LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

best way to read serial data

If I am streaming serial data in through my com port, and I need to search for specific strings in it. What is the best way to do this? I know that I will have to buffer the input and then search the buffer for a string that I need, but what happens if my buffer is of size [80] and the string that I am looking for is at position 78...80 plus bytes 0...2 of the next buffer. Then my string won't be found. Does anyone know what I can do?
0 Kudos
Message 1 of 2
(2,939 Views)
This can be done in several ways depending on the characteristics of the serial communication (amount of data transmitted, presence of start and termination character, speed of the serial communication...).

If your signal has a defined termination character (I suppose it is so since you can determine where it starts and ends) you can install a com callback that's fired when the termination character is received; or you can fire the callback on the start character and wait in the callback for a fixed amount of bytes to be received.

Or you could receive at regular intervals and append the bytes reveiced to a string in which to look for your data: in this case you may want to save a index in the string where the last search was made so as to limit the new
search, next you will need to discard all data prior to the substring found and restart again. But this could generate a significan overhead on your machine with respect to a comcallback fired by special characters in your transmission.

Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,939 Views)