# Serial data : how to split?

**URL:** https://discourse.nodered.org/t/serial-data-how-to-split/80229
**Category:** General
**Created:** [1 August 2023 17:00 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229 "2023-08-01T17:00:26Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)
#### Post date: [1 August 2023 17:00 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/1 "2023-08-01T17:00:26Z")

</div>

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 )

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2d846fede9ff14b21e98bc7eb5939a98af93940f.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 August 2023 18:19 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/2 "2023-08-01T18:19:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)
#### Post date: [1 August 2023 18:33 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/3 "2023-08-01T18:33:50Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2d5920b4873742ef342d338ad7bcd6332f4f885.png)

```auto
[{"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"}]

```

---

<div class="post-metadata">

### Author: ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)
#### Post date: [1 August 2023 19:29 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/4 "2023-08-01T19:29:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [1 August 2023 20:52 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/5 "2023-08-01T20:52:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)
#### Post date: [1 August 2023 21:06 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/6 "2023-08-01T21:06:33Z")

</div>

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"..

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [1 August 2023 21:10 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/7 "2023-08-01T21:10:48Z")

</div>

Does that matter?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [1 August 2023 21:36 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/8 "2023-08-01T21:36:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [30 September 2023 21:36 UTC](https://discourse.nodered.org/t/serial-data-how-to-split/80229/9 "2023-09-30T21:36:49Z")

</div>

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