Serial data : how to split?

hello

i have 2 situations on my serial port
a ) i inject a request to the serial port , and the response is processed. => this works not so good
b) on at random moments , my serial port recieves data => this works wel in the debug-log (rs485 node )

my problem is : when i inject a request , then i recieve 2 times the serial response ,,,, how can i create a selector that gives priority to my injected flow ? ( send cmd node )

Are you saying you inject in send command and you get the same response in rx485buss and interrupt? If so could you just not process the send command response.

Can we see the responses, as hard to create a selector when we do not have an info.

when i remove this part , it works fine ... BUT then i lose the knowledgde when my module randomly send an serial update.... cos the flow below accepts the random message from my serial port

[{"id":"e069fca6f965b4f1","type":"serial in","z":"6841c37d8366ee9d","name":"rs485","serial":"13a81711edbad506","x":670,"y":540,"wires":[["a67aa8f17c0231de"]]},{"id":"da06f2746ca55034","type":"debug","z":"6841c37d8366ee9d","name":"tx485","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":410,"y":520,"wires":[]},{"id":"bcfce054121007c7","type":"inject","z":"6841c37d8366ee9d","name":"rs485 req","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"get status","payload":"40 81 01","payloadType":"str","x":180,"y":560,"wires":[["6ca29fdf3331da77"]]},{"id":"6f2e9090fdd990c4","type":"function","z":"6841c37d8366ee9d","name":"convert 40 01 01 to buffer ","func":"//in string :   40 01 01 BF A8 C1\n//out bufferarray : [ 64,1,1,191,168,193]\n\nlet datacrc = msg.payload + \" \" + msg.crc;\nmsg.payload = Buffer.from(datacrc.replace(/\\s/g, \"\"), \"hex\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":480,"wires":[["e5dfc33d22b92199"]]},{"id":"e5dfc33d22b92199","type":"serial request","z":"6841c37d8366ee9d","name":"send cmd","serial":"13a81711edbad506","x":680,"y":480,"wires":[["2f6c080937f1ce14"]]},{"id":"ea23af7f906a8aca","type":"debug","z":"6841c37d8366ee9d","name":"rx485bus","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":480,"wires":[]},{"id":"2f6c080937f1ce14","type":"function","z":"6841c37d8366ee9d","name":"rx-dec2hexstring","func":"//in bufferarray = [192,254,0,6,0,64,1,1,191,168,193]\n//out string = \"c0 00 fe 06 01 40 82 01 00 86 37 c1\"\n//msg.payload = msg.payload.toString('hex')\nmsg.payload = msg.payload.toString('hex').match(/.{1,2}/g).join(' ');\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":480,"wires":[["ea23af7f906a8aca"]]},{"id":"a67aa8f17c0231de","type":"function","z":"6841c37d8366ee9d","name":"rx-dec2hexstring","func":"//in bufferarray = [192,254,0,6,0,64,1,1,191,168,193]\n//out string = \"c0 00 fe 06 01 40 82 01 00 86 37 c1\"\n//msg.payload = msg.payload.toString('hex')\nmsg.payload = msg.payload.toString('hex').match(/.{1,2}/g).join(' ');\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":540,"wires":[["1772e0cfd1eae23e"]]},{"id":"1772e0cfd1eae23e","type":"debug","z":"6841c37d8366ee9d","name":"interupt","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":540,"wires":[]},{"id":"6ca29fdf3331da77","type":"function","z":"6841c37d8366ee9d","name":"add crc berekenen","func":"//console.log(\"in 00 FE 06 01 40 02 01 03  crc F1 09\");\n\n\nconst hexString = msg.payload//\"00 FE 06 01 40 02 01 03\";\nconst hexArray = hexString.split(\" \");\nlet tabelcrcberekenen = hexArray.map(hex => parseInt(hex, 16));\n//let tabelcrcberekenen = [0,254,6,1,64,2,1,3];\n//let tabelcrcberekenen = \"00 FE 06 01 40 02 01 03\";\n\n\n\n\nconsole.log(tabelcrcberekenen);\nconsole.log(tabelcrcberekenen.length);\nconsole.log(\"****\");\n\nlet tempcrc = 65535;\nfor (let i = 0; i < tabelcrcberekenen.length; i++) {\n    let yy = tabelcrcberekenen[i];\n    console.log(\"yy=\" + yy);\n    tempcrc = tempcrc ^ yy;\n    //console.log(\"tempcrc:\"+ tempcrc); \n    for (let r = 0; r < 8; r++) {\n        let som = tempcrc & 1;\n        //console.log(\"som=\"+ som);\n        if (som == 1) {\n            tempcrc = tempcrc >> 1;\n            tempcrc = tempcrc ^ 33800;\n            \n        } else {\n            tempcrc = (tempcrc / 2);\n        }\n    }\n}\ntempcrc = tempcrc ^ 65535;\ntempcrc = tempcrc + 65536;\n\n//let CRCstring = tempcrc.toString();\nlet crcstring = tempcrc.toString(16).toUpperCase();\nlet crcdeel2 = crcstring[1] + crcstring[2];\nlet crcdeel1 = crcstring[3] + crcstring[4];\n\nmsg.crc = crcdeel1 + \" \" + crcdeel2 ; //F1 09\n \n\nmsg.payload = msg.payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":480,"wires":[["da06f2746ca55034","6f2e9090fdd990c4"]]},{"id":"13a81711edbad506","type":"serial-port","serialport":"/dev/ttyUSB0","serialbaud":"19200","databits":"8","parity":"none","stopbits":"2","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"100","bin":"bin","out":"time","addchar":"","responsetimeout":"1000"}]

in other words :
i want to recieve and process all broadcast from serialport
+
i want to proces my individual request from serialport

Could you change the Serial Request node to a Serial Out and keep the single Serial In node? Then the Serial In would receive both the requested and the random updates.

yes and no..
cos ,
the new problem is then ,when there is a timeout or the respons is to slow , then i get no msg.status = "OK"..

Does that matter?

If they really are the same message then a filter (rbe) node will remove duplicates

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