Author Topic: decoding ModbusRTU serial read result  (Read 1495 times)

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
decoding ModbusRTU serial read result
« on: December 23, 2014, 06:05:54 PM »
So I am reading a group of bits as a word:

strValue1 = ModbusRTUCom1.Read("41281")
lblReadResult.Text = strValue1

The result displayed lblReadResult.Text is "-256"

So what is the binary value of the register "41281"?  It thought it was a signed integer, but I am not sure.
   


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: decoding ModbusRTU serial read result
« Reply #1 on: December 23, 2014, 07:52:09 PM »
All integers that come back are interpreted as signed. The easiest way I find to see what bits represent what numbers is to use the Windows Calculator in Programmer View. I select the Dec setting, put in the number, then select Bin,

Doing that shows that -256 = 1111111100000000  , so bits 8-15 is on
« Last Edit: December 24, 2014, 09:00:37 AM by Archie »

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: decoding ModbusRTU serial read result
« Reply #2 on: December 24, 2014, 08:39:48 AM »
So to clarify, the modbusRTU read returns one word(16 bits) for each register.  So -256 would represent 1111 1111 0000 0000

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: decoding ModbusRTU serial read result
« Reply #3 on: December 24, 2014, 09:01:17 AM »
So to clarify, the modbusRTU read returns one word(16 bits) for each register.  So -256 would represent 1111 1111 0000 0000
Yes, you are correct. I modified my response above because I just noticed I did the conversion incorrectly.