Author Topic: ModbusTCP WriteValue Bit 15 - OverflowException  (Read 1924 times)

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
ModbusTCP WriteValue Bit 15 - OverflowException
« on: June 04, 2015, 03:52:00 AM »
Dear Archie,

I am using V398g, ModbusTCP, and got an OverflowException when trying to WriteValue with Button.
Basically I have 16 Buttons, the first 15 works fine. Writing value to address 40001:
Button0 = 1
Button1 = 2
Button2 = 4
Button3 = 8
Button4 = 16
....
Button14 = 16384
Button15 = 32768

Got an error when pressing Button15 (32768), refer to attachment.
Please advise the solution.
Thank you.

Best regards,
Andrew


andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: ModbusTCP WriteValue Bit 15 - OverflowException
« Reply #1 on: June 04, 2015, 04:36:00 AM »
Just downloaded V398m, and try with 'U40001' instead of '40001'
Result : OK

But I'm wondering, why only bit 15 needs to have 'U', others (bit 0~14) not required ?
And this is only for WriteValue, for ReadValue I can use 40001.15 without 'U'
« Last Edit: June 04, 2015, 04:40:37 AM by andrew_pj »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP WriteValue Bit 15 - OverflowException
« Reply #2 on: June 04, 2015, 07:59:30 AM »
By default the values are 16 bit signed integers with a range of -32768 to 32767, therefore 32768 overflows. The data comes back in unsigned byte values and these bytes are combined to make the signed 16 bit integer.  When specifying a bit number, the bit values are extracted before the bytes are combined, therefore signed/unsigned has no effect.

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: ModbusTCP WriteValue Bit 15 - OverflowException
« Reply #3 on: June 04, 2015, 09:03:08 PM »
Thanks, Archie.