LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How many bytes to read

If I am doing a serial read for a specific instrument, how do I know how many bytes are coming in.
The instrument is transfering data once every second.
The data is 20 lines total, each line ending with "\r\n".
Is there a way I can read in each line by successively reading a certain number of bytes?
Cory K
0 Kudos
Message 1 of 9
(5,726 Views)
If you know each line ends in /r/n, then enable your serial termination character and set it to be /n.  Read in a large number of bytes.  The serial read will terminate with either the number of bytes read in, or the termination character, or the timeout, whichever occurs first.  With a sufficiently large number of bytes in the VISA read function, then the termination character should occur first.
Message 2 of 9
(5,723 Views)
Idea.
could you call the bytes at serial port function every 750ms or so and feed that into the Visa read function? Then parse it out line by line using the \r\n.
Now Using LabVIEW 2019SP1 and TestStand 2019
Message 3 of 9
(5,718 Views)
I'm here with Ravens fan. Use a byte termination character.

After reading the port you will have exactly 1 (one) message. Then look how much more bytes are available at the port. If the number is big enough, do another read.

Make sure you keep fire reading events otherwise your buffer will burst (by default at 4k).

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 4 of 9
(5,711 Views)
This seems like the same question you asked before.
Message 5 of 9
(5,703 Views)

That was more to format the data.
I am having trouble reading in the data (if I do not use continuous run, which causes other problems)

If I set a termination character, won't it only read in the first line of data then stop?
How do I get the rest of the data, so I can parse out each one individually?

Cory K
0 Kudos
Message 6 of 9
(5,657 Views)
How did you implement your serial read?
 
Did you query how many bytes to read and read those bytes (within a loop)?
 
ex:
 
initilaize shift register with empty string
Loop until 0 bytes available
  - query how many bytes available
  - read those bytes
  - append new string to string from shift register
  - place newly appended string to shift register
  - wait small duration (ms)
EndLoop
read output of shift register
 
(sorry... didn't have LV to prepare an example)
 
R
 
Message 7 of 9
(5,646 Views)
Thanks Joe, that worked perfect.
That way I don't have to guess how many bytes are coming in.
Cory K
0 Kudos
Message 8 of 9
(5,615 Views)
Glad it works! 
 
I usually prepare examples, but without having LV installed, it was the best description I could come up with 😉  😄
 
R
0 Kudos
Message 9 of 9
(5,609 Views)