Decimal to float conversion block

Hello,

Is there any ready function for Decimal to Real Float value conversion? In below flow case, please check the output value i.e decimal , I want it to be displayed on dashboard as Float ( that is actually sent value from my device i.e PLC)

image

Please see my device i.e PLC output below....float value should be displayed on dashboard.


[{"id":"c05317e9.473668","type":"fieldbus out","z":"1ff7cae7.e98135","name":"PROFINET IO","FieldbusNodeVersion":"1.2.7","WrapperVersion":"1.2.7","WrapperCompileDate":"Mar  8 2018/16:37:23","MinExpectedNodeJSVersion":"8.9.4","ActNodeJSVersion":"8.9.4","ActNodeREDVersion":"0.17.5","selectedSignalPath":"output~send_001~Sig_1","fieldbusObj":"9a308d19.98106","x":511,"y":138,"wires":[]},{"id":"1526a19f.2d104e","type":"fieldbus in","z":"1ff7cae7.e98135","name":"PROFINET IO","FieldbusNodeVersion":"1.2.7","WrapperVersion":"1.2.7","WrapperCompileDate":"Mar  8 2018/16:37:23","MinExpectedNodeJSVersion":"8.9.4","ActNodeJSVersion":"8.9.4","ActNodeREDVersion":"0.17.5","selectedSignalPath":"input~receive_001~Sig_1","fieldbusObj":"9a308d19.98106","x":173,"y":244,"wires":[["91ae2ec0.34956"]]},{"id":"91ae2ec0.34956","type":"debug","z":"1ff7cae7.e98135","name":"","active":true,"console":"false","complete":"false","x":493,"y":242,"wires":[]},{"id":"f65ab3a9.136a","type":"inject","z":"1ff7cae7.e98135","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":224,"y":137,"wires":[["c05317e9.473668"]]},{"id":"70f048eb.73d2a8","type":"fieldbus in","z":"1ff7cae7.e98135","name":"PROFINET IO","FieldbusNodeVersion":"1.2.7","WrapperVersion":"1.2.7","WrapperCompileDate":"Mar  8 2018/16:37:23","MinExpectedNodeJSVersion":"8.9.4","ActNodeJSVersion":"8.9.4","ActNodeREDVersion":"0.17.5","selectedSignalPath":"input~receive_001~Sig_2","fieldbusObj":"9a308d19.98106","x":181,"y":316,"wires":[["99fa9766.963cd8"]]},{"id":"99fa9766.963cd8","type":"debug","z":"1ff7cae7.e98135","name":"","active":true,"console":"false","complete":"false","x":470,"y":321,"wires":[]},{"id":"9a308d19.98106","type":"fieldbus interface","z":"","availableStackName":"PROFINET IO Device (version 3.12, build 0 revision 8): cifX0","interfaceComponents":"{\"fwName\":\"PROFINET IO Device\",\"boardName\":\"cifX0\",\"fwVersionMajor\":3,\"fwVersionMinor\":12,\"fwVersionBuild\":0,\"fwVersionRev\":8,\"prtName\":\"PROFINET IO\",\"className\":\"Device\",\"prtClassNumber\":21,\"commClassNumber\":10,\"channelNumber\":2,\"deviceNumber\":1291105,\"serialNumber\":21005}","clearOutputsOnDeploy":false,"traceFilePath":"/var/log/node-red/node-fieldbus.log","traceLevelWrapper":"wrapper","traceLevelNode":"node"}]

Which node type are you using to fetch the data? Probably one of the node-red-contrib nodes. We need first to understand the format that the data is being provided in. Are you sure the node does not provide the ability to give you a value in floating point format rather than the raw data?

The node as ' Profinet IO ' is giving data out ( that has to displayed on Dashboard0

BR
Madhumati

That doesn't tell us which node-red-contrib node you have installed (assuming you have). If you select Manage Palette from the hamburger menu in the top right then you should see nodes you have installed on the Installed tab.

These are nodes developed by our company i.e Hilscher , please check below -

In that case you should ask whoever developed the node what format the data is in and tell you how to convert it to floating point. Even better if the node provided the result in floating point format.

Below find output message payload of this node..please check if you can support-

That says that the value is a 32 bit unsigned integer with the value shown. So it is saying it is not a floating point value but an integer.

Reading PLC data is always an adventure in trial & error -- at least for me.

The value you want is encoded as a byte array, which when read as a 32bit Float (Big-Endian) does indeed equal 230:

> var hex = Number(1130758144).toString(16);
'43660000'
> var arr = hex.match(/(\d\d)/g).map(d => +("0x"+d));
[ 67, 102, 0, 0 ]
> var buf = Buffer.from(arr);
<Buffer 43 66 00 00>
> buf.readFloatBE()
230

So if you just want to replace the payload with the float value, something this should work in function node:

var hex = Number(msg.payload.value).toString(16);
var arr = hex.match(/(\d\d)/g).map(d => +("0x"+d));
msg.payload = Buffer.from(arr).readFloatBE();
return msg;

Although there are probably simpler ways in JS to convert that number into hex, and then into a buffer...