Author Topic: Modbus Float point byte and word swap  (Read 8170 times)

Stewart

  • Newbie
  • *
  • Posts: 5
    • View Profile
Modbus Float point byte and word swap
« on: April 12, 2015, 01:23:14 PM »
Hi,
I have a Modbus device that I have been able to get working but the value I’m getting is wrong. It’s a float value but it needs to be “byte and word swapped”. When i use ‘F’ eg: F40017 my output value using a ‘Basiclabel’ is wrong. Is there a command or some code I can use to swap the bytes and word around. I tested the device output value with “ShortBus Modbus Scanner” software and it gives the proper output value when float value is swapped. Can someone please help, my VB.net skills are very limited.

Thanks
Stewart

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
    • View Profile
    • AdvancedHMI
Re: Modbus Float point byte and word swap
« Reply #1 on: April 12, 2015, 02:48:04 PM »
The driver was tested on the Click PLC so it uses that byte order. It may not be very easy to swap bytes since it is not built into the driver.

Does it work correctly on 16 bit integers?

Stewart

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Modbus Float point byte and word swap
« Reply #2 on: April 12, 2015, 04:49:02 PM »
Archie,
Thanks for the quick response.

When i checked for 16 bit integer values i get the following:

Advanced HMI at 40xxx i get a value of 257, when i use “ShortBus Modbus Scanner” i get the same 257
Advanced HMI at 40yyy i get a value of -27136, when i use “ShortBus Modbus Scanner” i  get 9600

I guess the -27136 value is padded with FFFFFFFFFFFF

Is is possible to add a feature like 'FW' = Float word swap and 'FB' = Float byte swap, 'FBW' = Float byte word swap
or some thing like that?

Thanks
Stewart

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
    • View Profile
    • AdvancedHMI
Re: Modbus Float point byte and word swap
« Reply #3 on: April 12, 2015, 11:51:45 PM »
I added a SwapBytes property to the Modbus drivers. This will part of the next release which should be available in a couple days.

Stewart

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Modbus Float point byte and word swap
« Reply #4 on: April 13, 2015, 12:06:12 PM »
Archie,
Thanks a lot.

I will test it out whenever you release the new update and give you feedback.

Stewart

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
    • View Profile
    • AdvancedHMI
Re: Modbus Float point byte and word swap
« Reply #5 on: April 20, 2015, 07:39:27 PM »
A new version has been posted with the SwapBytes property.

Stewart

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Modbus Float point byte and word swap
« Reply #6 on: April 28, 2015, 07:19:06 AM »
Archie,
I did some testing over the weekend of the latest release (V398f) using Modbus RTU.  I’m still having problems with getting the right output values using ‘Basic label’.

The results are below.

Device used for testing is a Modbus RTU Energy Meter using RS485.
Value being read from the device is a Float of 4 bytes which should display 60.02
Using standard Modbus software the raw output when reading address 400XX is:

RX: 0x01 0x04 0x04 0x42 0x70 0x14 0x7B 0xAA 0xBB

When this value is read using Advanced HMI the following value is displayed:

SwapBytes = False
2.990863E+30

SwapBytes = True
7.819442E-25

Digging deeper to see why I was getting the values above, I setup a Modbus RTU simulator software to see if I could make Advanced HMI output the values above.
To get the values listed below to be displayed using a ‘Basic label’ in Advanced HMI required the following raw string to be sent to it:

Display = 60.02
TX: 0x01 0x03 0x04 0x14 0x7B 0x42 0x70 0xAA 0xBB

Display = 2.990863E+30
TX: 0x01 0x03 0x04 0x00 0x01 0x72 0x17 0xAA 0xBB

Display = 7.819442E-25
TX: 0x01 0x03 0x04 0x00 0x01 0x17 0x72 0xAA 0xBB

In analyzing the results it seems that advanced HMI is doing the following:
1.   It takes the raw bytes received from device and does a word swap: 42 70 14 7B => 14 7B 42 70
2.   It then converts it to 6002
3.   Next it converts the 6002 => 17 72
4.   Depending on if SwapBytes is True or False it swaps the bytes and outputs that as the value to display.

After all that my question is, can I get Advanced HMI to not do the 2nd conversion to 17 72 and just output the 6002 value?
Also to read some of the other addresses for this device is it possible to have a SwapWord property?

Thanks in advance, your software and support is awesome.
Stewart


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
    • View Profile
    • AdvancedHMI
Re: Modbus Float point byte and word swap
« Reply #7 on: April 28, 2015, 12:35:22 PM »
Here is what I am seeing:

In .NET, which uses little endian, 60.02 in a byte stream is this:

0x7B 0x14 0x70 0x42

The byte stream you show from your device is:

0x42 0x70 0x14 0x7B


The SwapBytes will do this:

0x70 0x42 0x7B 0x14

Which means the swap bytes needs to be following by a swap words. I will implement this feature for the next release. Thanks for the detailed feedback, it helps a lot in figuring out the issue.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
    • View Profile
    • AdvancedHMI
Re: Modbus Float point byte and word swap
« Reply #8 on: April 29, 2015, 09:38:51 PM »
Version 3.98g with WordSwap property is now available.

Stewart

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Modbus Float point byte and word swap
« Reply #9 on: May 01, 2015, 02:10:59 PM »
Archie,
Thanks again for the quick response & update.

As before i will test it out and give you my feedback.

Stewart