Welcome, Guest
Username: Password: Remember me

TOPIC: how to swap word order on ChanAi?

how to swap word order on ChanAi? 3 years 7 months ago #9935

  • barnes
  • barnes's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 92
  • Karma: 0
I used the Description text as before to set the LittleEndianWordSwap = 1.

In function io_bus_card_read in file rt_io_bus.c

if(LittleEndianWordSwap == 0) {
if (byte_order == pwr_eByteOrderingEnum_BigEndian || float_rep == pwr_eFloatRepEnum_FloatIEEE) udata32 = swap32(udata32);
} else {

tmpint1=(udata32<<16)&0xffff0000; //LSW
tmpint2=(udata32>>16)&0x0000ffff; //MSW
tmpint3=tmpint1|tmpint2;

udata32=swap32(tmpint3);

}


This is working fine now, thanks for the ideas.
The administrator has disabled public write access.

how to swap word order on ChanAi? 3 years 7 months ago #9936

  • barnes
  • barnes's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 92
  • Karma: 0
Some major PLC manufactures have adopted the little endian standard. Reading Float32s directly from the remote PLC saves time and code in the Proview PLC graphical environment. I wish I had more time to learn the OOP behind the Proview. For now its working but it is a bit of a hack and probably deserves more time to integrating this solution properly into Proview.

Although not part of the original Modbus standard, people have forced a revision.

The big endian has died.


I bet writing the Float32 back to the remote PLC has the same problem.
Last Edit: 3 years 7 months ago by barnes.
The administrator has disabled public write access.

how to swap word order on ChanAi? 3 years 7 months ago #9937

  • claes
  • claes's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 2961
  • Karma: 0
I think the only thing you have to do is to change pwr_eByteOrderingEnum_BigEndian to pwr_eByteOrderingEnum_LittleEndian in the call to io_bus_card_init() in rt_io_m_mb_tcp_slave.c.

/Claes
The administrator has disabled public write access.

how to swap word order on ChanAi? 3 years 7 months ago #9939

  • barnes
  • barnes's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 92
  • Karma: 0
I will look into that.
I tried pwr_eByteOrderingEnum_LittleEndian in the read call and it did not seem to work.
In fact I created a third option pwr_eByteOrderingEnum_LittleEndianWordSwap but abandoned this.


I have run into another possible unrelated issue with the Modbus driver. When I have a discontinuous offset inside a Modbus_TCP_Slave, the driver loses count.

Modbus_TCP_Slave ---> Modbus_Module1 Address 0, 10 ChanAi's
_________________---> Modbus_Module2 Address 200, 10 ChanAi's

I've found a work around by adding another Modbus_TCP_Slave to the same remote PLC.

Is this a known bug?
Last Edit: 3 years 7 months ago by barnes.
The administrator has disabled public write access.

how to swap word order on ChanAi? 3 years 7 months ago #9965

  • barnes
  • barnes's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 92
  • Karma: 0
ChanAo had the same issue. The same byte swap code was used in function io_bus_card_write
file rt_io_bus.c



case pwr_eDataRepEnum_Float32:
memcpy(&udata32, &rawvalue, 4);
sig_ao->RawValue = udata32;
// if (byte_order == pwr_eByteOrderingEnum_BigEndian ||
// float_rep == pwr_eFloatRepEnum_FloatIEEE) udata32 = swap32(udata32);


if(LittleEndianWordSwap == 0) {
if (byte_order == pwr_eByteOrderingEnum_BigEndian || float_rep == pwr_eFloatRepEnum_FloatIEEE) udata32 = swap32(udata32);
} else {

tmpint1=(udata32<<16)&0xffff0000; //LSW
tmpint2=(udata32>>16)&0x0000ffff; //MSW
tmpint3=tmpint1|tmpint2;

udata32=swap32(tmpint3);

}
The administrator has disabled public write access.

how to swap word order on ChanAi? 2 years 1 month ago #10626

  • florent
  • florent's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
  • Karma: 0
barnes wrote:
I used the Description text as before to set the LittleEndianWordSwap = 1.

In function io_bus_card_read in file rt_io_bus.c

if(LittleEndianWordSwap == 0) {
if (byte_order == pwr_eByteOrderingEnum_BigEndian || float_rep == pwr_eFloatRepEnum_FloatIEEE) udata32 = swap32(udata32);
} else {

tmpint1=(udata32<<16)&0xffff0000; //LSW
tmpint2=(udata32>>16)&0x0000ffff; //MSW
tmpint3=tmpint1|tmpint2;

udata32=swap32(tmpint3);

}


This is working fine now, thanks for the ideas.

Hi,
I'm interested to this function, can you explain how you do that?
thanks
Florent
The administrator has disabled public write access.
Time to create page: 5.981 seconds