AdvancedHMI Software

General Category => Support Questions => Topic started by: andrew_pj on June 04, 2015, 03:52:00 AM

Title: ModbusTCP WriteValue Bit 15 - OverflowException
Post by: andrew_pj 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

Title: Re: ModbusTCP WriteValue Bit 15 - OverflowException
Post by: andrew_pj 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'
Title: Re: ModbusTCP WriteValue Bit 15 - OverflowException
Post by: Archie 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.
Title: Re: ModbusTCP WriteValue Bit 15 - OverflowException
Post by: andrew_pj on June 04, 2015, 09:03:08 PM
Thanks, Archie.