# How can I split buffer where received the specific byte

**URL:** <https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084>\
**Category:** General\
**Created:** [21 November 2018 00:48 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084 "2018-11-21T00:48:27Z")\
**Posts on this page:** 13\
**Page:** 2

<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:** [23 November 2018 08:49 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/21 "2018-11-23T08:49:26Z")

</div>

Have you told us which version of the serial node you are using? You can see this from the Manage Palette menu in the editor.

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [23 November 2018 14:40 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/22 "2018-11-23T14:40:47Z")

</div>

Hi Colin, sorry I forgot to share it.  
Would you see below my node-red version is 0.19.4, as you can see below:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/733164fcff3310975a4689e25c462ca3e87ee0fb.png)

Best Regards,  
Alex

---

<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:** [23 November 2018 16:16 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/23 "2018-11-23T16:16:37Z")

</div>

That does not tell us the version of serial port, at least not directly. Scroll down and you should see node-red-node-serialport

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [23 November 2018 17:27 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/24 "2018-11-23T17:27:00Z")

</div>

Hi Colin, would you see below my serial version:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8fed6e3df88c965a9db201a4dd4c312975b8ef4d.png)

Thanks a lot for your support!

Best Regards,  
Alex

---

<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:** [23 November 2018 17:43 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/25 "2018-11-23T17:43:55Z")

</div>

Well that is the latest version.  
@dceejay is it possible that there is an error in the serialport node that causes repeated buffers when splitting on a character? I know 'possible' isn't the best word there because it is certainly possible. 'Likely' doesn't sound like a good word either, but you know what I mean.  
I haven't got any serial hardware so I can't try and replicate it myself.  
I had a quick look at the code but didn't see anything obvious, which isn't surprising.

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [25 November 2018 17:12 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/26 "2018-11-25T17:12:48Z")

</div>

Hi Guys!  
I changed the serial USB dongle, change from PL203 to CP2102, to check if i´ll see any changes about duplication message, but still the same behavior!

Best Regards,  
Alex

---

<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:** [25 November 2018 17:45 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/27 "2018-11-25T17:45:16Z")

</div>

Hi - most odd... can you do us a favour and try something to help us debug this ?

Find the file 25-serial.js (probably under ~/.node-red/node\_modules/node-red-node-serialport directory but depend of OS etc

in there find line 82 and insert a console.out line below like this

```
this.port.on('data', function(msgout) {
    console.log(typeof msgout, msgout.length, JSON.stringify(msgout));
    node.send(msgout);
});

```

Then restart Node-RED and watch the console to see what gets printed...  
does the length match what you expect... Does it get printed twice per one input sent ?

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [26 November 2018 00:41 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/28 "2018-11-26T00:41:27Z")

</div>

Hi dceejay,  
I found file 25-serial.js under /usr/lib/node\_modules/node-red-node -serialport/

I have a doubt if I can change this file, under directory above, as you advise me. Please let me know if i can do it?

pi@raspberrypi:/usr/lib/node\_modules/node-red-node-serialport $ ls -lt  
total 60

> Blockquote  
> drwxr-xr-x 153 root root 4096 Nov 2 21:20 node\_modules  
> drwxr-xr-x 4 root root 4096 Nov 2 21:20 locales  
> -rw-r--r-- 1 root root 1462 Sep 17 19:18 package.json  
> -rw-r--r-- 1 root root 17422 Oct 26 1985 25-serial.html  
> -rw-r--r-- 1 root root 19957 Oct 26 1985 25-serial.js  
> -rw-r--r-- 1 root root 632 Oct 26 1985 LICENSE  
> -rw-r--r-- 1 root root 1751 Oct 26 1985 README.md  
> pi@raspberrypi:/usr/lib/node\_modules/node-red-node-serialport $

> Blockquote

Best Regards,  
Alex

---

<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:** [26 November 2018 07:11 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/29 "2018-11-26T07:11:43Z")

</div>

Yes sure. You will need to use sudo or root to access the file but yes, that is the one.

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [26 November 2018 10:23 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/30 "2018-11-26T10:23:03Z")

</div>

Hi dceejay,  
I already yet include the new line that you advise me on 25-serial.js and I still received twice messages, as you can see below in the palette debug log 2x 19 (149) length and 2 x 18 (164) length messages.

To explain you better: my node send 1 message and wait to receive 2 messages.  
Get Version (example that i should be receive)  
07:50:56.612 -\> 01 02 10 10 02 10 02 10 10 03  
07:50:56.694 \<- 01 80 00 00 05 95 00 00 00 10 00 03  
07:50:56.874 \<- 01 80 10 00 05 A4 00 01 00 30 00 03  
You can see bellow, the pi log and palette debug information w/ rbe node:

> Blockquote  
> 26 Nov 10:12:50 - [info] serial port /dev/ttyUSB0 opened at 115200 baud 8N1  
> object undefined {"payload":{"type":"Buffer","data":[1,128,2,16,2,16,2,21,241,2,16,61,2,16,73,2,16,3]},"port":"/dev/ttyUSB0"}  
> object undefined {"payload":{"type":"Buffer","data":[1,128,2,16,2,16,2,21,242,2,16,62,2,16,73,2,16,3]},"port":"/dev/ttyUSB0"}  
> 26 Nov 10:12:50 - [info] [debug:43313881.a42ee8]  
> \<Buffer 01 80 02 10 02 10 02 15 f2 02 10 3e 02 10 49 02 10 03\>  
> object undefined {"payload":{"type":"Buffer","data":[1,128,73,2,16,2,19,100,61,2,16,147,3]},"port":"/dev/ttyUSB0"}  
> 26 Nov 10:12:50 - [info] [debug:43313881.a42ee8]  
> \<Buffer 01 80 49 02 10 02 13 64 3d 02 10 93 03\>  
> object undefined {"payload":{"type":"Buffer","data":[1,128,73,2,16,2,19,100,62,2,16,144,3]},"port":"/dev/ttyUSB0"}  
> 26 Nov 10:12:50 - [info] [debug:43313881.a42ee8]  
> \<Buffer 01 80 49 02 10 02 13 64 3e 02 10 90 03\>  
> 26 Nov 10:13:52 - [info] Stopping modified nodes  
> 26 Nov 10:13:52 - [info] Stopped modified nodes  
> 26 Nov 10:13:52 - [info] Starting modified nodes  
> 26 Nov 10:13:52 - [info] Started modified nodes  
> object undefined {"payload":{"type":"Buffer","data":[1,128,2,16,2,16,2,21,149,2,16,2,16,2,16,16,2,16,3]},"port":"/dev/ttyUSB0"}  
> 26 Nov 10:14:20 - [info] [debug:43313881.a42ee8]  
> \<Buffer 01 80 02 10 02 10 02 15 95 02 10 02 10 02 10 10 02 10 03\>  
> object undefined {"payload":{"type":"Buffer","data":[1,128,16,2,16,2,21,164,2,16,2,17,2,16,48,2,16,3]},"port":"/dev/ttyUSB0"}  
> 26 Nov 10:14:20 - [info] [debug:43313881.a42ee8]  
> \<Buffer 01 80 10 02 10 02 15 a4 02 10 02 11 02 10 30 02 10 03\>  
> object undefined {"payload":{"type":"Buffer","data":[1,128,2,16,2,16,2,21,149,2,16,2,16,2,16,16,2,16,3]},"port":"/dev/ttyUSB0"}  
> 26 Nov 10:14:20 - [info] [debug:43313881.a42ee8]  
> \<Buffer 01 80 02 10 02 10 02 15 95 02 10 02 10 02 10 10 02 10 03\>  
> object undefined {"payload":{"type":"Buffer","data":[1,128,16,2,16,2,21,164,2,16,2,17,2,16,48,2,16,3]},"port":"/dev/ttyUSB0"}  
> 26 Nov 10:14:20 - [info] [debug:43313881.a42ee8]  
> \<Buffer 01 80 10 02 10 02 15 a4 02 10 02 11 02 10 30 02 10 03\>

> Blockquote

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/5433f2f9c10adb82a3754fa6ac32de6f93d2666a.png)

---

<div class="post-metadata">

**Author:** ![aco7342](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aco7342/32/649_2.png) [@aco7342](https://discourse.nodered.org/u/aco7342)\
**Post date:** [27 November 2018 18:57 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/31 "2018-11-27T18:57:49Z")

</div>

try this...  
Sorry for my poor english but

```
        0x16, 22d same your Start (0x01)

         0x17, 23d same your Stop (0x03)

        Example Tx:164f504e3030303017add7
        
	16 - Start
        
	4f - data
        
	....
        
	30 - data
        
	17 - Stop
        
	ad - crc16
        
	d7 - crc16

```

function RxCompleto( vetor,msg ) {

```
var pos = (vetor.length - 2) -1 // subtrai 1 por que vetor inicia em 0
            
msg.expr1 = (vetor[pos] == 23)
            
msg.expr2 = ((vetor.length==1) && (vetor[0] == 21))
        
return ( (msg.expr1) || (msg.expr2) );

```

}

........

port.on('data', (data) =\> {

```
for ( var x = 0 ; x < data.length ; x++) {
				
	out.push( data[x])
			
}	
			
if (RxCompleto(out,msg)) {

      // Continue Your Code              
}

```

//Example  
//Multiple Message  
27 Nov 14:01:10 - [info] Log TxRxPinPad - Tx:164453503033322020415455414c495a414e444f20202020202020544142454c4153207c20202017d5b0/DSP032 ATUALIZANDO TABELAS | հ out:(42) md5:e193281c4cc9eb3349e5125d116112d7 003/027

27 Nov 14:01:10 - [info] Log TxRxPinPad - Tx:16544c523331363031333134313038303330374130303030303030303332303130303030303030303030303030303030303030303244454249544f202020202020202020203033303038433030384330303843303736393836323030303030303030303030303030303030303053595354454d202045304630453837303030463046303031323244383430303446383030303031303030303030304438343030304138303030303030303030303030303030303030303030303030303030303030303030303030303030303030304639463032303635463241303239413033394330313935303539463337303430303030303030303033394633373034303030303030303030303030303030303030303030303030303030303030303059315a3159335a334438343030344638303030303130303030303030443834303030413830301758b0/TLR316013141080307A000000003201000000000000000000002DEBITO 03008C008C008C07698620000000000000000000SYSTEM E0F0E87000F0F00122D84004F8000010000000D84000A80000000000000000000000000000000000000000000F9F02065F2A029A039C0195059F370400000000039F370400000000000000000000000000000000Y1Z1Y3Z3D84004F8000010000000D84000A800X� out:(326) md5:f0e145a35cd87d4c1ade6339af8da53a

27 Nov 14:01:11 - [info] Log TxRxPinPad. Rx:(22) cmd:[DSP] DSP000 ,TLR000 /DSP000 ,TLR000

27 Nov 14:01:11 - [info] Log TxRxPinPad. Rx:(22) cmd:[TLR] DSP000 ,TLR000 /DSP000 ,TLR000

---

<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:** [27 November 2018 19:26 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/32 "2018-11-27T19:26:52Z")

</div>

@aargollo - the debug log out seems to look OK after you restart there are 4 messages

```
<Buffer 01 80 02 10 02 10 02 15 95 02 10 02 10 02 10 10 02 10 03>
<Buffer 01 80 10 02 10 02 15 a4 02 10 02 11 02 10 30 02 10 03>
<Buffer 01 80 02 10 02 10 02 15 95 02 10 02 10 02 10 10 02 10 03>
<Buffer 01 80 10 02 10 02 15 a4 02 10 02 11 02 10 30 02 10 03>

```

Yes they are repeated - but that looks like that is what is being received from the other end so I don't think there is a problem there.

One final thing to try - I see you are using deploy only modified nodes `Stopping modified nodes` - maybe try a complete redeploy as that stops and restarts everything.

---

<div class="post-metadata">

**Author:** ![aargollo](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aargollo](https://discourse.nodered.org/u/aargollo)\
**Post date:** [28 November 2018 09:04 UTC](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084/33 "2018-11-28T09:04:15Z")

</div>

> [@dceejay](#):
>
> One final thing to try - I see you are using deploy only modified nodes `Stopping modified nodes` - maybe try a complete redeploy as that stops and restarts everything.

@dceejay, I agree you its look like very stranger and i thing that also from the other side. But the unique thing that cause distrust is that when i used serialport without 0x03 as split byte is working very well. Don´t worrying I´ll try to implement a code sent by aco7432.

@aco7342, thanks a lot "Muito obrigado meu conterrâneo,pela ajuda".

I´ll let us know soon about the changes!  
Best Regards,  
Alex

[Previous page](https://discourse.nodered.org/t/how-can-i-split-buffer-where-received-the-specific-byte/5084.md?page=1)
