asci conversion
-
Hi All,
I'm reading the display register of a controller. The value is 32bit so I get an asci value of "2956538157". What's the best to convert that value to a real number. Real number here is -19
Modbus setting are, register_32, readable, swap words flag on
Modbus flag read, 2956538157. This should be -19
If I turn off the swap word flag I get 825077817, that is roughly -19
Cheers,
Mike
-
Hi Mike,
in REXYGEN 3 we have introduced "Register String" in Modbus driver.
Register string: text variable (Count is the number of bytes occupied by text in this case)
Did you try out this option? Instead of the "Swap word" flag try to set the "Swap byte" flag since every character is represented by a byte.
Let me know if it helped.
Cheers,
Tomas -
-
@cechurat Hi Tomas,
That works perfectly, thank you.
The next thing to solve! The display on the device I am reading does not use a decimal point below -9.9. So I get the same values from the register. -9.9 and above I can add again to get the decimal, -99 plus gain is -9.9. But -10 and below I can't use gain as -10 becomes -1.0. Is there a clean way in REXYGEN to handle this?
Cheers,
Mike -
@MikeyH Hi Mike,
I'm glad it works for you
For the "variable decimal point" I would use blocks MUL and CNDR. CNDR configure so it reflects the changing of the gain according to the value.
You will probably find many other solutions which will lead you to the desired behaviour (e.g. SSW for switching gain according to the value)
Hope it helps.
Cheers,
Tomas