08-10-2015 12:40 PM
Hello,
I am reading data from a laser scanner. After asking the device to start sending data, it sends two acknowledgements, and then the data starts rolling in over TCP.
I can tell each batch from the others alone by bytecount, as there are no discernable delimiters in the data. So what I do, is simply to read that exact amount of data and send the linescan down the pipe for processing.
My question is, is that a sound way of acquiring data?
Maybe I should spend time working on a regex, so I don't rely on the bytecount staying constant? (which I'm not 100% sure it will).
Any other tips and tricks in regards of continuous TCP reads and the LV architecture involved, would be very welcome.
Thanks in advance 🙂
08-10-2015 01:53 PM
What device exactly are you trying to communicate with? There is often a programming manual that tells you how the messages are set up. Common for instruments is to use a Line Feed to end a message. This could help clear things up.
08-10-2015 01:57 PM
Like crossrulz said, hopefully there's a manual that can tell you how the messages are set up. It's very uncommon for there to be no delimiters at all, even if it's just a "\r" at the end of the dataset.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-10-2015 03:33 PM - edited 08-10-2015 03:44 PM
Thanks for the replies 🙂
The device is a LMS400 from SICK, but that doesn't really matter. Sorry if I wasn't clear!
I have found a way to separate the messages from the device. Not perfect, but it works for now. While I did mention delimiters, it's not the focus of my enquiry.
What I'm looking for, is "best practises" in regards of the architecture of continually reading TCP data, or any general tips you may have.
It's a fairly complex system, at least to me. It involves 5 of these scanners, which will need close coordination both starting and stopping, as well as computationally heavy algorithms (turning scans into 3D image). In short, I want an efficient architecture to allow room for all these going ons.
Edit: I guess 'pattern' would be a key word here. Sorry for not introducing it before. I'm building a state machine at the base of the system, but looking specifically to the continuous acquisition of batches of data, what patterns or key features would you name there?
08-10-2015 03:38 PM
Best practice is to try your best not to rely on byte count, or at least to check that the right delimiters are there after you've read your specified number of bytes. Delimiters are the easiest way to not accidentally cut data sections down the middle when a byte is off.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-11-2015
03:47 AM
- last edited on
05-12-2025
09:38 AM
by
Content Cleaner
Hi Tobias,
For continuous data acquisition I would recommend looking at using a producer/consumer architecture instead of a state machine as with a state machine you may go into a state that is not continually acquiring data. A producer/consumer will allow you to obtain the batches of data in the producer loop and read it in the consumer loop continually.
Have a look at this white paper on producer/consumer design pattern and see if it fits your application: https://www.ni.com/en/support/documentation/supplemental/21/producer-consumer-architecture-in-labvie...
Regards
Luke