From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading packet starting with specific byte

Hi,

I have one small problem. I read some bytes coming through port and then I have to work with packet wich start with specific byte. The problem is, that i don´t know how to continue in this block diagram. After that loop for reading that byte, i have to delete one specific byte, create an array and then work with it. Can anyone help how to connect these two loops or has another solution? Because i don´t know wether that will work in this way

0 Kudos
Message 1 of 4
(2,996 Views)

@000alex000 wrote:

Hi,

I have one small problem. I read some bytes coming through port and then I have to work with packet wich start with specific byte. The problem is, that i don´t know how to continue in this block diagram. After that loop for reading that byte, i have to delete one specific byte, create an array and then work with it. Can anyone help how to connect these two loops or has another solution? Because i don´t know wether that will work in this way


Once you have the packet, start a loop that processes the bytes in order.  If the byte is not the Start Byte, delete it from the (head of) the array and continue.  Otherwise, stop the loop and pass out the remaining array (which starts with the Start Byte).  Then do what ever you need to do with the Byte array, including adding more bytes by doing another read.

 

Bob Schor

0 Kudos
Message 2 of 4
(2,957 Views)

Could you please show me it in that diagram? Because i am not sure, if i exactly understood that solution.

0 Kudos
Message 3 of 4
(2,937 Views)

OK, you have a VISA Read that gets a string that you hope contains the Start Byte + Other Bytes (I show that off to the left).  Change the String to an Array of Bytes.  You now want to process this array, looking for the Start Byte.  If you find it, you want to output that Byte and all the rest of the Bytes.  One way to do this is to have a Boolean (which I called "Found Start" on a Shift Register, initialized to False, and set to True when you find Start.  Use this to decide whether or not you save the Byte in the output Array Tunnel of the For loop.

 

What happens if the Start Byte is not in the VISA read?  Well, I had to leave something for you to do ...  If this happens, the output Array will be an Empty Array (you can test for this), so you can put this inside a While loop and do another VISA Read and look for Start until Start + Other Bytes is not empty.  Now you have the beginning of your data from your VISA input.  Do more VISA reads (sequentially -- following this piece of code -- use the Error Line to serialize your code) as you need to accomplish your goal.

 

VISA Start Byte.png

 

Bob Schor

0 Kudos
Message 4 of 4
(2,916 Views)