Dear everyone,
I'm working on a node to achieve float32 values read and write based on IEEE754 (real type on PLC's)
So i have a flow to inject a float value in buffer parser and then parser maker to split that into 2 words of 16bit integers (so we can execute a modbus write).
Then i reverse the process with another parser to get back the same value. (but this needs a swap 16 operation). This is what i'm not sure now, if there is a mistake on my setup, and this amplifies my concern because we have also precision error after 4 decimal digits.
On modbus PLC's we just write the 32 bits straight in 2 words by pointing to the starting register, and then read back the same real value by pointing on the same starting register.
Is the result reasonable or there is a setup mistake ?
Below is the flow used:
[
{
"id": "9be00b9bab774a27",
"type": "inject",
"z": "f9ec28042044c16a",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "4893.37207645",
"payloadType": "num",
"x": 220,
"y": 100,
"wires": [
[
"9f85b0f26fee4365"
]
]
},
{
"id": "ea646b374b59410b",
"type": "debug",
"z": "f9ec28042044c16a",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 1110,
"y": 100,
"wires": []
},
{
"id": "fdb414cc9c0746f9",
"type": "modbus-write",
"z": "f9ec28042044c16a",
"name": "localhost",
"showStatusActivities": false,
"showErrors": true,
"showWarnings": true,
"unitid": "1",
"dataType": "MHoldingRegisters",
"adr": "1000",
"quantity": "2",
"server": "386f2a0ac05453c3",
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"delayOnStart": false,
"startDelayTime": "",
"x": 920,
"y": 100,
"wires": [
[
"ea646b374b59410b"
],
[]
]
},
{
"id": "9f85b0f26fee4365",
"type": "buffer-maker",
"z": "f9ec28042044c16a",
"name": "real to buffer",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"name": "Voltage",
"type": "floatle",
"length": 1,
"dataType": "msg",
"data": "payload"
}
],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"x": 450,
"y": 100,
"wires": [
[
"e89f3d1c41906520",
"e45569a956b055f6"
]
]
},
{
"id": "e89f3d1c41906520",
"type": "buffer-parser",
"z": "f9ec28042044c16a",
"name": "buffer 2 words",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "uint16le",
"name": "word1",
"offset": 0,
"length": 1,
"offsetbit": 0,
"scale": "1",
"mask": ""
},
{
"type": "uint16le",
"name": "word2",
"offset": 2,
"length": 1,
"offsetbit": 0,
"scale": "1",
"mask": ""
}
],
"swap1": "",
"swap2": "swap16",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"resultType": "value",
"resultTypeType": "output",
"multipleResult": false,
"fanOutMultipleResult": false,
"setTopic": false,
"outputs": 1,
"x": 700,
"y": 100,
"wires": [
[
"fdb414cc9c0746f9",
"63e040941a10433f"
]
]
},
{
"id": "63e040941a10433f",
"type": "debug",
"z": "f9ec28042044c16a",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 900,
"y": 200,
"wires": []
},
{
"id": "e45569a956b055f6",
"type": "debug",
"z": "f9ec28042044c16a",
"name": "debug 2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 640,
"y": 180,
"wires": []
},
{
"id": "99ccf7a240bbabe8",
"type": "inject",
"z": "f9ec28042044c16a",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "4893.37000000000000000",
"payloadType": "num",
"x": 250,
"y": 220,
"wires": [
[
"9f85b0f26fee4365"
]
]
},
{
"id": "a00b6808469ed203",
"type": "buffer-parser",
"z": "f9ec28042044c16a",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "floatle",
"name": "item1",
"offset": 0,
"length": 1,
"offsetbit": 0,
"scale": "1",
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"resultType": "value",
"resultTypeType": "return",
"multipleResult": false,
"fanOutMultipleResult": false,
"setTopic": false,
"outputs": 1,
"x": 550,
"y": 300,
"wires": [
[
"7bc3c0f57af030c4"
]
]
},
{
"id": "272d08a838e76627",
"type": "modbus-read",
"z": "f9ec28042044c16a",
"name": "read float",
"topic": "",
"showStatusActivities": false,
"logIOActivities": false,
"showErrors": false,
"showWarnings": true,
"unitid": "1",
"dataType": "HoldingRegister",
"adr": "1000",
"quantity": "2",
"rate": "1",
"rateUnit": "h",
"delayOnStart": false,
"startDelayTime": "",
"server": "386f2a0ac05453c3",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"x": 220,
"y": 300,
"wires": [
[
"a00b6808469ed203"
],
[]
]
},
{
"id": "7bc3c0f57af030c4",
"type": "debug",
"z": "f9ec28042044c16a",
"name": "debug 4",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 780,
"y": 300,
"wires": []
},
{
"id": "bfce9582d6b554bd",
"type": "inject",
"z": "f9ec28042044c16a",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "4893.372",
"payloadType": "num",
"x": 200,
"y": 160,
"wires": [
[
"9f85b0f26fee4365"
]
]
},
{
"id": "7bc4f8f6c5e05361",
"type": "modbus-server",
"z": "f9ec28042044c16a",
"name": "local_modbus_server",
"logEnabled": true,
"hostname": "0.0.0.0",
"serverPort": "2000",
"responseDelay": 100,
"delayUnit": "ms",
"coilsBufferSize": 10000,
"holdingBufferSize": 10000,
"inputBufferSize": 10000,
"discreteBufferSize": 10000,
"showErrors": true,
"showStatusActivities": true,
"x": 1200,
"y": 240,
"wires": [
[],
[],
[],
[],
[]
]
},
{
"id": "386f2a0ac05453c3",
"type": "modbus-client",
"name": "localhost",
"clienttype": "tcp",
"bufferCommands": true,
"stateLogEnabled": false,
"queueLogEnabled": false,
"failureLogEnabled": true,
"tcpHost": "127.0.0.1",
"tcpPort": "2000",
"tcpType": "DEFAULT",
"serialPort": "/dev/ttyUSB",
"serialType": "RTU-BUFFERD",
"serialBaudrate": 9600,
"serialDatabits": 8,
"serialStopbits": 1,
"serialParity": "none",
"serialConnectionDelay": 100,
"serialAsciiResponseStartDelimiter": "0x3A",
"unit_id": 1,
"commandDelay": 1,
"clientTimeout": 1000,
"reconnectOnTimeout": true,
"reconnectTimeout": 2000,
"parallelUnitIdsAllowed": true,
"showErrors": false,
"showWarnings": true,
"showLogs": true
}
]
Any comments appreciated.