I am receiving this string from a Pic micro using an RS484 to serial (USB) converter.
FE5A6144141A140C1413142324222000�
The last char, showing as a replacement char of something that cannot be displayed, it is a 8bit value.
It represent the checksum.
I am extracting that char from the string using:
let cs = m.substr(33,1);
This gives me this: �
I have tried to convert it using:
cs=String.fromCharCode(cs);
This gives me an empty string " "
and
cs=parseInt(cs, 8)
This gives me a NaN
Whatever I tried is not returning me the value. I have successfully decoded the rest of the string but not that last part!
Here is the decoding function with the string I receive copied into an injection node.
[{"id":"5780c7918e4f68a9","type":"function","z":"b114e20b20dbeb01","name":"","func":"let m = msg.payload\n\nlet mAddr = m.substr(1,2)\nlet sAdrr = m.substr(3,2);\nlet comm = m.substr(5,2);\nlet vc1 = m.substr(9,2) + m.substr(7,2);\nlet vc2 = m.substr(13,2)+ m.substr(11,2);\nlet vc3 = m.substr(17,2)+ m.substr(15,2);\nlet vc4 = m.substr(21,2);+ m.substr(19,2)\nlet t1 = m.substr(23,2);\nlet t2 = m.substr(25,2);\nlet t3 = m.substr(27,2);\nlet t4 = m.substr(29,2);\nlet flag = m.substr(31,2);\n//let cs = m.substr(33,1);\nlet cs = m.substr(33,1);\n\nvc1=parseInt(vc1, 16)/1000;\nvc2=parseInt(vc2, 16)/1000;\nvc3=parseInt(vc3, 16)/1000;\nvc4=parseInt(vc4, 16)/1000;\nt1=parseInt(t1, 16);\nt2=parseInt(t2, 16);\nt3=parseInt(t3, 16);\nt4=parseInt(t4, 16);\n//cs=String.fromCharCode(cs);\n//cs=parseInt(cs, 8)\n\n\n//formatting\nreturn {payload:{MasterAddress:mAddr,\nSlaveAddress:sAdrr,\nCommand:comm,\nVc1:vc1,\nVc2:vc2,\nVc3:vc3,\nVc4:vc3,\nT1:t1,\nT2:t2,\nT3:t3,\nT4:t4,\nFlag:flag,\nCS:cs\n}}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":440,"wires":[["23556ff73afb7655"]]},{"id":"23556ff73afb7655","type":"debug","z":"b114e20b20dbeb01","name":"Decode","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":440,"wires":[]},{"id":"b521d8c461b7e66d","type":"inject","z":"b114e20b20dbeb01","name":"Dummy Value","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\u0002FE5A6144141A140C1413142324222000�","payloadType":"str","x":300,"y":520,"wires":[["5780c7918e4f68a9"]]}]
How can I get and parse that 8bit value to an integer?
Thanks for helping.