Machsupport Forum

Mach Discussion => Brains Development => Topic started by: Ivan_The_Red on April 05, 2012, 07:00:00 PM

Title: Brain for dealing with negative DRO values from modbus device
Post by: Ivan_The_Red on April 05, 2012, 07:00:00 PM
All,

I am trying to write a negative value generated from a modbus device into a DRO.  I have no problems doing this with positive values but what I try to pass
a negative value it ends up with a value around 65535. I know this has to do with the register size but I need help figuring out
how to deal with it......any help sure would be appreciated.

Thanks and Happy Easter
Title: Re: Brain for dealing with negative DRO values from modbus device
Post by: poppabear on April 07, 2012, 09:13:22 AM
Ivan,

  You will probably have to play tricks, I don't think that the modbus registers will take a "negative" number in a 16 bit register.

so, in your PLC or what ever....

You will need to push your unsigned number into the register that represents the value.
then you will need to turn on a another "bit" (that can be the register value following the one above).
in your PLC, if your number is NEGATIVE, turn on your "Negative Control Bit" (or just push a "1" into your second register).

Then in Brains:

Bring in your number value from the modbus and also look at the second register if it is NOT on, send the value to your dro.
second rung, do the same, but if it IS ON send the value through a formula  = (value * -1) then to your dro, to give you a negative value in the dro.

scott
Title: Re: Brain for dealing with negative DRO values from modbus device
Post by: Ivan_The_Red on April 10, 2012, 07:16:02 PM
Scott,

Thanks for your guidance, I gave it alot of thought over the Easter weekend and that's all I could come up with also.

I'll have to go that route

Thanks Alot
Title: Re: Brain for dealing with negative DRO values from modbus device
Post by: stirling on April 11, 2012, 07:08:02 AM
Looks like your modbus device is handling 16 bit numbers as signed twos complement and Mach is handling them as unsigned plain vanilla so if the range -32768 to +32767 is enough for your app. then
in your brain if the number sent from your modbus device to Mach is interpreted by Mach as being > 32767 then subtract 65536 from it else use the number unchanged.

Ian