Hello,
I read values from a Siemens PLC thanks to the s7 node. However, I have now to convert the data into floating values. I've tried to use buffer-parser or maker, or doing it with a change mode or a function, but the result is always 0. I've seen several topics about this subject on the forum but I didn't find the answer to my problem.
This is my flow :
[
{
"id": "176701d716ba4394",
"type": "tab",
"label": "Flux 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "8cc018e22ffb36c8",
"type": "s7 in",
"z": "176701d716ba4394",
"endpoint": "fed32a73d5582e79",
"mode": "all",
"variable": "",
"diff": true,
"name": "",
"x": 460,
"y": 360,
"wires": [
[
"113b04d62d587a51",
"78ac1c9bf42bdfc4",
"84b765e8f9789969"
]
]
},
{
"id": "113b04d62d587a51",
"type": "debug",
"z": "176701d716ba4394",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 650,
"y": 200,
"wires": []
},
{
"id": "93b2ff2180088830",
"type": "function",
"z": "176701d716ba4394",
"name": "Dry Bulb + Wet Bulb To Float",
"func": "// Extraction des données brutes\nvar bufDryBulb = Buffer.alloc(4);\nvar bufWetBulb = Buffer.alloc(4);\n\nbufDryBulb[0] = flow.Dry_Bulb_0_float;\nbufDryBulb[1] = flow.Dry_Bulb_1_float;\nbufDryBulb[2] = flow.Dry_Bulb_2_float;\nbufDryBulb[3] = flow.Dry_Bulb_3_float;\n\nbufWetBulb[0] = flow.Wet_Bulb_0_float;\nbufWetBulb[1] = flow.Wet_Bulb_1_float;\nbufWetBulb[2] = flow.Wet_Bulb_2_float;\nbufWetBulb[3] = flow.Wet_Bulb_3_float;\n\n// Conversion des données brutes en nombre flottant\nvar floatValueDryBulb = bufDryBulb.readFloatBE(0); // Lit le nombre flottant en Big Endian à partir du tampon\nvar floatValueWetBulb = bufWetBulb.readFloatBE(0);\n// Retourne la valeur flottante\nreturn [{ payload: floatValueDryBulb }, { payload: floatValueWetBulb }] ;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 980,
"y": 360,
"wires": [
[
"be5b7cab248c34c9"
]
]
},
{
"id": "78ac1c9bf42bdfc4",
"type": "change",
"z": "176701d716ba4394",
"name": "Dry bulb conv + flow context",
"rules": [
{
"t": "set",
"p": "payload.Dry_Bulb_0_float",
"pt": "msg",
"to": "(payload.Dry_Bulb_0)+3",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload.Dry_Bulb_1_float",
"pt": "msg",
"to": "(payload.Dry_Bulb_1)+2",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload.Dry_Bulb_2_float",
"pt": "msg",
"to": "(payload.Dry_Bulb_2)+1",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload.Dry_Bulb_3_float",
"pt": "msg",
"to": "(payload.Dry_Bulb_3)+0",
"tot": "jsonata"
},
{
"t": "set",
"p": "Dry_Bulb_0_float",
"pt": "flow",
"to": "payload.Dry_Bulb_0_float",
"tot": "msg"
},
{
"t": "set",
"p": "Dry_Bulb_1_float",
"pt": "flow",
"to": "payload.Dry_Bulb_1_float",
"tot": "msg"
},
{
"t": "set",
"p": "Dry_Bulb_2_float",
"pt": "flow",
"to": "payload.Dry_Bulb_2_float",
"tot": "msg"
},
{
"t": "set",
"p": "Dry_Bulb_3_float",
"pt": "flow",
"to": "payload.Dry_Bulb_3_float",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 700,
"y": 340,
"wires": [
[
"81b83400d8dff551",
"93b2ff2180088830"
]
]
},
{
"id": "be5b7cab248c34c9",
"type": "debug",
"z": "176701d716ba4394",
"name": "debug 17",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1200,
"y": 360,
"wires": []
},
{
"id": "81b83400d8dff551",
"type": "debug",
"z": "176701d716ba4394",
"name": "debug 18",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 920,
"y": 300,
"wires": []
},
{
"id": "84b765e8f9789969",
"type": "change",
"z": "176701d716ba4394",
"name": "Wet bulb conv + flow context",
"rules": [
{
"t": "set",
"p": "payload.Wet_Bulb_0_float",
"pt": "msg",
"to": "(payload.Wet_Bulb_0)+3",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload.Wet_Bulb_1_float",
"pt": "msg",
"to": "(payload.Wet_Bulb_1)+2",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload.Wet_Bulb_2_float",
"pt": "msg",
"to": "(payload.Wet_Bulb_2)+1",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload.Wet_Bulb_3_float",
"pt": "msg",
"to": "(payload.Wet_Bulb_3)+0",
"tot": "jsonata"
},
{
"t": "set",
"p": "Wet_Bulb_0_float",
"pt": "flow",
"to": "payload.Wet_Bulb_0_float",
"tot": "msg"
},
{
"t": "set",
"p": "Wet_Bulb_1_float",
"pt": "flow",
"to": "payload.Wet_Bulb_1_float",
"tot": "msg"
},
{
"t": "set",
"p": "Wet_Bulb_2_float",
"pt": "flow",
"to": "payload.Wet_Bulb_2_float",
"tot": "msg"
},
{
"t": "set",
"p": "Wet_Bulb_3_float",
"pt": "flow",
"to": "payload.Wet_Bulb_3_float",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 700,
"y": 400,
"wires": [
[
"93b2ff2180088830",
"ff4ca3f2bc562b0b"
]
]
},
{
"id": "ff4ca3f2bc562b0b",
"type": "debug",
"z": "176701d716ba4394",
"name": "debug 19",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 920,
"y": 440,
"wires": []
},
{
"id": "fed32a73d5582e79",
"type": "s7 endpoint",
"transport": "iso-on-tcp",
"address": "192.168.0.1",
"port": "102",
"rack": "0",
"slot": "1",
"localtsaphi": "01",
"localtsaplo": "00",
"remotetsaphi": "01",
"remotetsaplo": "00",
"connmode": "rack-slot",
"adapter": "",
"busaddr": "2",
"cycletime": "10000",
"timeout": "2000",
"name": "Discovery",
"vartable": [
{
"addr": "DB62,BYTE0",
"name": "Dry_Bulb_0"
},
{
"addr": "DB62,BYTE1",
"name": "Dry_Bulb_1"
},
{
"addr": "DB62,BYTE2",
"name": "Dry_Bulb_2"
},
{
"addr": "DB62,BYTE3",
"name": "Dry_Bulb_3"
},
{
"addr": "DB62,BYTE4",
"name": "Wet_Bulb_0"
},
{
"addr": "DB62,BYTE5",
"name": "Wet_Bulb_1"
},
{
"addr": "DB62,BYTE6",
"name": "Wet_Bulb_2"
},
{
"addr": "DB62,BYTE7",
"name": "Wet_Bulb_3"
}
]
}
]
Here, the decode function in C for floating values (datasheet) :
static float conv_float_s7_pc(char * plc_real)
{
char tmp[4];
tmp[0] = * (plc_real + 3);
tmp[1] = * (plc_real + 2);
tmp[2] = * (plc_real + 1);
tmp[3] = * (plc_real + 0);
return(* (float *) tmp);
}
Thank you for your help.