Convert Array to a number

Hi!
I'm having a problem to convert a value my PLC is sending with modbus, is says its in array, but I need to use this value to write on a chart, I don't know if I need to convert to number to be able to write in the chart, but thats what I think is the way to work.
I tried to convert the value the modbus is sending with this following function but is not working:

msg.payload = Number(msg.payload)

return msg;

Anyone can help? Do I need to convert the value from array to number to write on the chart or don't? If not why is not working?
If I need to convert the value to number, can anyone tell me how to do it?

Can you show debug1 as complete msg object?
image

  • you can try for function:
msg.payload = msg.payload[0]
return msg;

Yes.
Changed the debug to complete.

And then changed it back to normal and changed the function code to what you suggested.

I think response from both ports is different:

this will work on first node

msg.payload = msg.payload[0]
return msg;

this will work on second node

msg.payload = msg.payload.data[0]
return msg;

It worked, thank you!
My chart is reading the values as it should, just one thing, is there a way to filter the value anything above 0?
I see there is the polling rate of my modbus reading but i need that reading the entire time waiting for the value to come.
Is there a function I can write like If value > 0 then pass the information?

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