Hello Guest it is November 18, 2019, 04:16:11 AM

Author Topic: Brain for dealing with negative DRO values from modbus device  (Read 3716 times)

0 Members and 1 Guest are viewing this topic.

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

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Brain for dealing with negative DRO values from modbus device
« Reply #1 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
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/
Re: Brain for dealing with negative DRO values from modbus device
« Reply #2 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

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Brain for dealing with negative DRO values from modbus device
« Reply #3 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