How can I split buffer where received the specific byte

Hi Guys,
i working on my interfacing program and I need to split the buffer received, from a serial communication, for each one message received. Each serial message have a start/stop byte structure:

0x01 - start
0x03 - stop

msg received example:
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

My actually program can´t split it as you can see below:
As you can see the 1st message have part of bytes in the 2st buffer (2st buffer component).
buffer%20strcuture

has one in it that can help me to seperate the buffers or has a specif function?

Best Regards,
Alex

Didn’t Colin answer this when you asked a similar question 8days ago?

(see his first post)

Hi Mr Unkmoose. Thanks for your response.

Answering your questions, I would like to create a new sequence of bytes, in array, that have begin and end according the start and stop (0x01 and 0x03). For example:
See below the buffer, without any treatment, received from node-red is:
1st buffer - [1,128,2,16,2,16,2,21,149,2,16,2,16,2,16]
2 st buffer - [16,2,16,3,1,128,16,2,16,2,21,164,2,16,2,17,2,16,48,2,16,3]

A new buffer or array shall be:
1st buffer/array - [1,128,2,16,2,16,2,21,149,2,16,2,16,2,16,16,2,16,3]
2 st buffer/array - [1,128,16,2,16,2,21,164,2,16,2,17,2,16,48,2,16,3]
see that each one has its size or length.
I need to work with a function or we have a node that can be do that?

BR,
Alex

You'll have to do it in a function.
Take a look at https://www.w3schools.com/nodejs/met_buffer_indexof.asp
or
https://www.tutorialspoint.com/nodejs/nodejs_buffers.htm
which should get you started

Can 1's and 3's appear at other positions in the buffer or is it guaranteed that every 1 is the start and every 3 is the end?

Hi colin,
every msg star with 1 and stop with 3. But we have a ddifferent lengths accoridng each msg answered.

BR
Alex

That didn't answer the question. Can there be a 1 or a 3 inside the message, or will a 1 always mean start and a 3 always means end?

Sorry Colin, We dont have 1 or 3 inside the message!

OK, are you getting this from a serial node? In which case you can configure the serial node to pass on its data each time it sees a particular character. It seems that will accept a hex code so if you set the character to 0x03 then it should give you the messages already split.

Hi Colin, thanks a lot!
The split code (with 0x03 stop byte), in the serial input, almost worked. As you can see in the PIC attached, for each message received the debug node show twice.
for example:
You can see in PIC in the first 4 messages (18 and 19 bytes), we have 2 to 2 duplicates, and in the last only 1 message with 37 bytes (original without 0x03).

buffer_w%200x03%20complete

Do you have idea how to fix it?

Is the debug node direct on the output of the Com node?
Show us what is in some of the short buffers.
Post a screenshot showing the setup of the com port config node (the one where you put in the Split On character).

Hi Colin, good morning!
Yes, of course, the debug node is direct on the serial input node. As you can see, in the PIC below, the setup configuration, nodes in the flow and debug screen:

Sorry, still not sure what the problem is. You haven't shown the end of the short buffer so we can't see whether it ends in 03. Is the problem that the buffer you show is correct but you are receiving it twice? If that is the problem and the debug is on the output of the Com port node then either there is a massive bug in the Com node (which is unlikely) or that data is being received twice. I think it is much more likely that the device on the other end of the wire is sending it twice.

If it really is ending the exact thing twice then an RBE node will remove the duplicate :slight_smile:

Hi Colin
The problem is the debug show it twice. The split buffer w/ stop bytes running well. The end of buffer is correctly!
I made some experience, I changed the split input to "after a silent of" (without split code 0x03) and the debug show only one message, considering the same scenario. As you can see below:

Do you can see that the message buffer is single!
Do you have any idea what is happening?

Dceejay, plase tel me more about node RBE. I didnt know it!

Best Regards,
Alex

It is one of the built in nodes. It can check for a message the same as the previous one and ignore it if so.

On the serial node, if you regularly get repeated records when you use split on character but never when you use the timeout then perhaps there is a problem with the serial node. If necessary do some more testing to see if you can convince yourself. If you think there is a problem with the node then I am not the one to help, but I imagine someone will want to know which version it is. You can see that from the Manage Palette window.

What is the mechanism that the sender uses to know when to send?

Colin, using a serial interface, transmitting one bit every clock pulse. Just in 2 wires connected trough converter device. Could you see below more about it:
pi@raspberrypi:~ $ lsusb
Bus 001 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

My Serial configuration at node-red side is:

It´s very stranger, the duplication behavior happening just when I split the buffer raw data (using a stop byte 0x03). I did another experience to split (0x92) using the same message, but 0x92/146 is on 9th position, the original buffer have 19 elements, and I didn´t see duplication behavior, but the elements 10- 19 disappeared! As you can see below:


image
This behavior above is normal?

I´ll make experience palliative with node RBE to try to cut duplication message!

Sorry, I meant how does the sender know when to transmit another buffer to the node red machine. I am just looking for some mechanism that might cause it to re-transmit the same buffer. Is there any feedback back to the sender?

When you told it to split on the 9th byte I wonder whether the bytes after it got lost because the com node was processing the buffer. I would have thought the reception would be interrupt driven, but I don't know how it works so don't know.

Colin, don´t worrying!
The exchange device does not have any mechanism to guarantee the procedures send and response message. Does not have feedback!

What makes me wary is that with timeout defined in split input works with or duplication.

Thanks a lot.
Best Regards,
Alex