05-09-2017 01:38 PM
Hi All
I have a device that spits out data at a serial port every 100ms. I am able to write to the device then need to read the serial port to ensure the changes took affect. The serial port output i need to capture looks something like this:
12345678
23456789
12345678
23456789
12345678
23456789
12345678
End of data
Due to poll speed of device, sometimes when I open a visa session and read bytes from the serial port I wont get the full set of data, or sometimes I get more than 1 full set of data. So, what I am doing is reading, matching string "End of data", then checking to make sure I have a minimum string length before "end of data" so I know I have captured all 7 lines of numbers I need. This is in a loop I repeat until successful. From there I am kind of stuck. Because I don't know where offset "0" is (it changes from capture to capture), I don't know how to trim out what I don't need and get my starting to point to be exactly at the first line of data. Its like I need to work backwards from "End of data". Any suggestions? Hopefully that makes sense and sorry but I cannot upload my current code. Thanks!
05-09-2017 01:49 PM
What device is sending the data?
Does it send a termination character like a linefeed?
If it does, you should be taking advantage of that. Enable the termination character in your serial configure. Then just read a number of bytes larger than the longest message you expect. The VISA Read will stop once it gets the termination character.
You didn't attach your VI so I can only guess at what the problem is. But my guess is that you used the Basic Serial Read Write example, (not a very good example by the way) which used a wait and bytes at port property node. Bytes at Port is the wrong thing to use the vast majority of the time.