Discussion:
How many bytes to read
(too old to reply)
Cory K
2008-08-01 19:40:15 UTC
Permalink
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?
Ravens Fan
2008-08-01 19:40:16 UTC
Permalink
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.
GovBob
2008-08-01 19:40:17 UTC
Permalink
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.
TonP
2008-08-01 20:40:05 UTC
Permalink
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
smercurio_fc
2008-08-01 21:10:05 UTC
Permalink
This seems like the same question you asked <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=342723#M342723" target="_blank">before</a>.
Cory K
2008-08-05 19:40:06 UTC
Permalink
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?
JoeLabView
2008-08-05 19:40:10 UTC
Permalink
How did you implement your serial read?
&nbsp;
Did you query how many bytes to read and read those bytes (within a loop)?
&nbsp;
ex:
&nbsp;
initilaize shift register with empty string
Loop until 0 bytes available
&nbsp; - query how many bytes available
&nbsp; - read those bytes
&nbsp; - append new string to string from shift register
&nbsp; - place newly appended string to shift register
&nbsp; - wait small duration (ms)
EndLoop
read output of shift register
&nbsp;
(sorry... didn't have LV to prepare an example)
&nbsp;
R
&nbsp;
Cory K
2008-08-06 19:40:05 UTC
Permalink
Thanks Joe, that worked perfect.
That way I don't have to guess how many bytes are coming in.
JoeLabView
2008-08-06 19:40:09 UTC
Permalink
Glad it works!&nbsp;
&nbsp;
I usually prepare examples, but without having LV installed, it was the best description I could come up with ;)&nbsp; :D
&nbsp;
R

Continue reading on narkive:
Loading...