Need to parse values from node-red-contrib-s7 node

Need help to prase MD168 tag. I tried using buffer-parser but no success. The value is supposed to be "88.00".

Below is the payload.

msg.payload = 
{ 
    "M2.0": true, 
    "MR168": 6.32293893072644e-41, 
    "MR169": 1.6186723662659685e-38, 
    "MR170": -7.057678885757923e-10, 
    "MD168": 45122, 
    "MD169": 11551232, 
    "MD170": 2957115392 
}
return msg;

There shouldn't be any need to parse the values.

By selecting tag reading tag MR168 you should get real value.
Why do you even read bytes 169 170 and so on?

What result do you get when you read single tag of address MR168?

To see if value occupying consecutive tag space or not. :man_shrugging:

What happens if you select to read single tag MR168?

This the first time I see that tags read by s7 node gives different values from the ones in PLC.
Could you share PLC online VAT table with act values?

Are you reading from S7-1200/1500 or S7-300/400?

sinumerik 828d

Haven't worked with SInumerik series. Cannot help, can't you just move this value to DB and read it from there?

The data looks like floating(32bit) in Little endian format. You can use "buffer parser" which can convert to float little endian.

Can you create a flow and share ?

As you mentioned earlier you were expecting data at MD168 tag "88" but getting "6.32293893072644e-41" so I tested by simulating Modbus data over Little endian format and found that if I read in node-red as float big endian is getting "6.32293893072644e-41" but if I read in Float little endian format getting value of "88". So try in buffer-parser data type as "float (le)".

I am sharing my test flow.

[{"id":"bda4aeea932107fe","type":"tab","label":"Flow 5","disabled":false,"info":"","env":[]},{"id":"a0b8845a59395151","type":"modbus-read","z":"bda4aeea932107fe","name":"","topic":"ModbusData","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"2","quantity":"4","rate":"100","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"d3f6a446.e8ec78","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":150,"y":100,"wires":[["301d77ba97dd5d74"],[]]},{"id":"301d77ba97dd5d74","type":"buffer-parser","z":"bda4aeea932107fe","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatle","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":390,"y":100,"wires":[["ee2b5dd976ac4b0c"]]},{"id":"ee2b5dd976ac4b0c","type":"debug","z":"bda4aeea932107fe","name":"debug 26","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":100,"wires":[]},{"id":"d3f6a446.e8ec78","type":"modbus-client","name":"test","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

getting error

Error: data is not an array or a buffer

the reason why I asked you to share flow. :weary:

Why ? Make buffer to parse buffer? :face_with_spiral_eyes:
image

[{"id":"2f07c697e82592e3","type":"buffer-maker","z":"20f21f0f49f965c7","name":"","specification":"spec","specificationType":"ui","items":[{"name":"item1","type":"floatle","length":1,"dataType":"msg","data":"payload"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","x":655,"y":780,"wires":[["abaa6ae99d779c03"]],"l":false},{"id":"aad716df25acf09c","type":"inject","z":"20f21f0f49f965c7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"6.32293893072644e-41","payloadType":"str","x":595,"y":780,"wires":[["2f07c697e82592e3"]],"l":false},{"id":"abaa6ae99d779c03","type":"buffer-parser","z":"20f21f0f49f965c7","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":715,"y":780,"wires":[["0f68543715c9b093"]],"l":false},{"id":"0f68543715c9b093","type":"debug","z":"20f21f0f49f965c7","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":775,"y":780,"wires":[],"l":false}]

image

The make buffer is to generate a buffer that is then used to show how to parse it. How else can one generate a test flow when one does not have access to the hardware?

had no clue that I need to generate a buffer and then parse it. :man_shrugging:

I used below :point_down: code in function node to get result for anyone might need it and cited link1 & link2 to get result.

var value = 6.32293893072644e-41;
var buf1 = Buffer.alloc(4);
buf1.writeFloatLE(value);
var buf2 = Buffer.from(buf1);
msg.payload = buf2.readFloatBE(0);
node.status({ fill: "green", shape: "dot", text: msg.payload});
return msg;

I think the idea is that you get the buffer from the device, but I don't know the device you are using.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.