Convert int16 to float16 - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Convert int16 to float16 (/showthread.php?tid=2493) |
Convert int16 to float16 - fleeceable - 28.02.2020 Hi! I'm working on with special modbus script. I have Corrigo ventilation controller and communicating over ModbusRTU. When I read register with profile then it is converted automatically thanks to this line: { "name": "Outside temp", "bus_datatype": "float16", "datatype": "int16", "type": "inputregister", "address": 0, "value_multiplier": 0.1, "units": "C" }, So this works. Now I'm going to use scripting. How can I convert integer to float via script? For example, received value is 65523, it should be -1.x degree. RE: Convert int16 to float16 - Daniel - 29.02.2020 What is the point of using script when profile work? RE: Convert int16 to float16 - admin - 02.03.2020 float16 is supported by the modbus mapper. Just use "datatype": "float16" and it will work. RE: Convert int16 to float16 - fleeceable - 02.03.2020 (29.02.2020, 09:24)Daniel. Wrote: What is the point of using script when profile work?I have 5 ventilation controllers. There is about 130 modbus points what I need to read per controller. From that, 100 is alarm points. If there is A or B alarm, I will read alarm points also. (A and B alarm is sum of all these) And ventilation controller can handle 10 answers per 1 fast request. So it's quite messed up system on there but I can take control via scripting. (02.03.2020, 07:42)admin Wrote: float16 is supported by the modbus mapper. Just use "datatype": "float16" and it will work.Actually this way what I wrote it will work... Now i'm scripting. I will add screenshot but answer is 65523 with minus degrees. If outside temp is over 0 then it will be correct number. Also my variable is in 2 byte floating point format but grp.update gives 6552.3 or something like that. RE: Convert int16 to float16 - Daniel - 02.03.2020 If in profile value_multiplier": 0.1 works then you should do the same here outside_te*0.1 I don't think the 65523 is a correct value. Usually such is send when No value or no sensor is on PLC side. RE: Convert int16 to float16 - admin - 02.03.2020 Real datatype is float32 not float16. Correct profile entry should be: Code: { "name": "Outside temp", "bus_datatype": "float32", "datatype": "float32", "type": "inputregister", "address": 0, "units": "C" }, RE: Convert int16 to float16 - fleeceable - 02.03.2020 (02.03.2020, 15:33)Daniel. Wrote: If in profile value_multiplier": 0.1 works then you should do the same hereI figured out. uint16 max value is 65535. If minus degrees, value is changed reversely. 65535-65523=12 12/10=1.2 1.2*-1=-1.2°C RE: Convert int16 to float16 - Daniel - 02.03.2020 Try reading it like this Code: value = mb:readinputregistervalue(0, "float32", "w") RE: Convert int16 to float16 - admin - 02.03.2020 I've edited Daniel's example to use internal conversion function. You might have to use different swap parameter (w) depending on your ModBus device. Possible values: n (no swap), w (word swap), b (byte swap), bw (byte and word swap). |