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: 

Read only specific byte

Solved!
Go to solution

I have a continuous stream of data coming in via my serial port. Basically, I want Labview to be able to wait for the byte '08' to arrive at the serial port and then read that and the following couple of bytes.

 

The problem is I have no idea how to isolate that specific section of bytes from a continuous data stream. It doesn't appear on a regular basis (only when an event happens on the device), and I need to be able to read it everytime it appears (not just the first time).

 

I've used the VISA read / write process before, but never for something like this, and I'm really at a loss. Any help would be hugely appreciated.

 

Brian 

0 Kudos
Message 1 of 6
(2,945 Views)
Solution
Accepted by topic author bpmccain

You could set up byte 08 as a termination character and enable termination characters.  Read a large number of bytes.  The read will either timeout, acquire the large number bytes, or return what it has received up to and including the 08.  Now if you want to read a specific number of bytes after that, then to a Read of that number of bytes.

 

Probably better is to just read the serial port continuously and search for the 08 byte that may appear in the string and just parse the data accordingly based on where that 08 occurs.

Message 2 of 6
(2,933 Views)
Depending on how quickly the data is coming in you might consider splitting your reading and processing into two tasks. Create a very simple read task that reads all the data and posts it to a queue for further processing. This task could look through the data and throw out the unwanted characters and process the data once the '08' is detected. If your data is streaming in slowly this is probably overkill. However if the data is coming in quickly you will want to make sure that you read all the data quickly to prevent any loss of data due to buffering or potentially slow down the sending device if you are using flow control.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 3 of 6
(2,917 Views)
Thanks. That got me heading in the right track. I scan it continuously, find 08, and then parse the string to obtain the next two bytes. 
0 Kudos
Message 4 of 6
(2,894 Views)

hallo

i also have problem regarding read only specified bytes. the problem is i am making a software which to read a data from telemetry and have to read 2 command frame n as soon i received perfect comman frame i have to reply with status frame.i have define all protocal and there is a communication but not in  a smooth manner i tried to shearch shot out by shearching 1st charcter  .  when i get a perfet command frame there is communication now the problem is the command frame after certain time it is incomplet i.e, normally it should be 84 bytes but after some time it shifted i dont know how to solve this prob .it would be nice if anyone help me out

0 Kudos
Message 5 of 6
(2,570 Views)

You should create a new thread with your question.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 6 of 6
(2,552 Views)