Hello, I would like ask for help.
I am trying to read array from board, and I have a problem with output message.
the node works fine, msg.payload contain correct data, but I am not able to process them.
The correct message goes only to the first flow which I connect by "wire" into other nodes came just payload:[0:undefined].
the same behavior is continue next. I am not able even copy the correct array by msg.payload.slice() or var newArray=[...mag.payload]
also when I store the payload to context variable, I am not able to read it, even I see it into context data. I think pictures will tell more:
Pics description:
Please see the big letters A and B.
I changed the order of connection to the previous node. -> the numbers on the node.
A: message goes into function flow.set("Isol_results",msg.payload); return msg; so you are able on the context. see the data. Even they looks like String not like array. Next function is connected first so is able to read the flow context, and we are able to see it into first connected debug node -> msg.flow. The second one is empty.
B: Is changed order of connection all of the nodes, so valid payload goes into debug node, and others are invalid. So context is empty and function msg.flow=flow.get("Isol_results"); return msg; read array[0:undefined]
Thank you very much for help!
Pavol
Solved! Go to Solution.
Hi Pavol,
I was able to reproduce your issue. It happens because of the Internal FreeMASTER Lite Server option (in PCM node). Node-RED shares a reference to the same "internal" array as FreeMASTER Lite. This behavior will be fixed, but at this point I can suggest 2 options:
return JSON.parse(JSON.stringify(msg));
Hi Pavol,
I tried to create a similar flow as per your description, but could not reproduce the issue. Could you share your flow as JSON file.
Hello Iulian!
thank you!
Yes, here it is:
[{"id":"fd5d4b3b3aa475e9","type":"pcm","z":"e8a5b08199f66899","name":"PCM","url":"127.0.0.1:8090","urlType":"str","internal":true,"x":390,"y":400,"wires":[["2536f456555aaed7","f27f2245e046f223"],["7b96425f6eae323f"],["7b96425f6eae323f"]]},{"id":"10629f6ae38e08a5","type":"inject","z":"e8a5b08199f66899","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":400,"wires":[["fd5d4b3b3aa475e9"]]},{"id":"377ce03a10c01430","type":"read-uint-var","z":"e8a5b08199f66899","name":"Isol_PartitionsCnt","addr":"Isol_PartitionsCnt","addrType":"str","size":1,"sizeType":"num","x":190,"y":580,"wires":[["c9bedb33af384961","70c8a92af80530a8"]]},{"id":"1f64d6dcf167131a","type":"read-uint-var","z":"e8a5b08199f66899","name":"Isol_RegionsCnt","addr":"Isol_RegionsCnt","addrType":"str","size":"2","sizeType":"num","x":580,"y":560,"wires":[["768a1af843038174","2e479aaad0c64130"]]},{"id":"abdce692060f5f2a","type":"read-uint-arr","z":"e8a5b08199f66899","name":"Isol_Results","addr":"Isol_Results","addrType":"str","size":"size","sizeType":"msg","elSize":1,"elSizeType":"num","x":970,"y":580,"wires":[["30cb3045e14b13e1","b3eac4121bf1d0a2"]]},{"id":"768a1af843038174","type":"debug","z":"e8a5b08199f66899","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":540,"wires":[]},{"id":"2536f456555aaed7","type":"comm-start","z":"e8a5b08199f66899","name":"Start Comm","conn":"UART Connection","connType":"str","x":570,"y":380,"wires":[["9b9e202514f9e6a5","808b9b796fa1cc6e"]]},{"id":"c9bedb33af384961","type":"debug","z":"e8a5b08199f66899","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":540,"wires":[]},{"id":"d4071b90c74478f2","type":"tsa-read","z":"e8a5b08199f66899","name":"Read TSA","x":1070,"y":380,"wires":[["377ce03a10c01430","c6f42a8d8be60bea"]]},{"id":"c6f42a8d8be60bea","type":"debug","z":"e8a5b08199f66899","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1090,"y":340,"wires":[]},{"id":"7b96425f6eae323f","type":"function","z":"e8a5b08199f66899","name":"FM PCM ERROR","func":"var RunningDemo=global.get(\"RunningDemo\");\nRunningDemo.Running=false;\nRunningDemo.Description=node.name+\" stopped with error: \"+((typeof msg.payload.message!=\"undefined\")?msg.payload.message:\"\");\nglobal.set(\"ProcessStatus\",\"Is not possible to connect to the Board by FreeMaster, COMport is propably used by another program\");\n\nvar error={message:\"\",source:{name:\"ClearErrorMessage\"}}; \nerror.message=msg.payload.message;\nerror.source.name=node.name;\nmsg.error=error;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":420,"wires":[["2dc54e91e90a4ab0"]]},{"id":"f27f2245e046f223","type":"debug","z":"e8a5b08199f66899","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":340,"wires":[]},{"id":"9b9e202514f9e6a5","type":"debug","z":"e8a5b08199f66899","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":340,"wires":[]},{"id":"70c8a92af80530a8","type":"function","z":"e8a5b08199f66899","name":"HeaderCheck","func":"flow.set(msg.topic,msg.payload);\nreturn msg;\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":580,"wires":[["1f64d6dcf167131a"],["98f412b15ae63726"]]},{"id":"2e479aaad0c64130","type":"function","z":"e8a5b08199f66899","name":"flow.set","func":"flow.set(msg.topic,msg.payload);\nmsg.size=msg.payload*flow.get(\"Isol_PartitionsCnt\");\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":580,"wires":[["abdce692060f5f2a"]]},{"id":"808b9b796fa1cc6e","type":"function","z":"e8a5b08199f66899","name":"FM_ComPort_Open","func":"if(msg.payload==true)\n{return [msg,null];}\nelse\n{\nvar RunningDemo=global.get(\"RunningDemo\");\nRunningDemo.Running=false;\nRunningDemo.Description=node.name+\" stopped with error: \"+msg.payload.message;\nglobal.set(\"ProcessStatus\",\"Is not possible to connect to the Board by FreeMaster, COM port is propably used by another program\");\n\nvar error={message:\"\",source:{name:\"ClearErrorMessage\"}}; \nerror.message=msg.payload.message;\nerror.source.name=node.name;\nmsg.error=error;\nreturn [null,msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":380,"wires":[["d4071b90c74478f2"],["2dc54e91e90a4ab0"]]},{"id":"2dc54e91e90a4ab0","type":"link out","z":"e8a5b08199f66899","name":"Stop Isolation Demo - PH1","mode":"link","links":["08316067ce14e67e","c678937e845bf0e1"],"x":935,"y":420,"wires":[]},{"id":"98f412b15ae63726","type":"link out","z":"e8a5b08199f66899","name":"Stop Isolation Demo - PH1","mode":"link","links":["08316067ce14e67e","c678937e845bf0e1"],"x":495,"y":600,"wires":[]},{"id":"b3eac4121bf1d0a2","type":"debug","z":"e8a5b08199f66899","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1170,"y":560,"wires":[]},{"id":"30cb3045e14b13e1","type":"debug","z":"e8a5b08199f66899","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1170,"y":600,"wires":[]}]
Hi Pavol,
I was able to reproduce your issue. It happens because of the Internal FreeMASTER Lite Server option (in PCM node). Node-RED shares a reference to the same "internal" array as FreeMASTER Lite. This behavior will be fixed, but at this point I can suggest 2 options:
return JSON.parse(JSON.stringify(msg));