08-17-2009 01:37 PM
A year later, and I'm having a few issues with this VI.
The data is transmitted once per second.
The data is 23 lines, with a line termination character of /n.
The problem is that sometimes, instead of starting at line 0,
it will start reading at some random line, and then continue from there.
Line 0 will always be : -->
I tried 2 solutions so far, neither of which have worked:
1) Check if line0 == '-->'
2) Check if bytes at port == 113
If those are not true, I clear the I/O buffer, then start the read over.
Now, if I look at what is being sent (in Hyperterminal), the data is being sent correctly,
but it is not being read by my program in LabVIEW.
I attached a simplified example of what I tried (shows solution 2).
Anyone see what I am doing wrong?
08-17-2009 01:43 PM
Cory:
Your attachment did not attach.
-AK2DM
08-17-2009 01:45 PM
Just one of those days.....
Here's the attachment
08-17-2009 02:07 PM
Since each line is terminated with a \n, I would not even bother with the VISA Bytes at Serial Port. To avoid partial lines, you can do a read and specify some high byte count. The VISA Read will automatically terminate with the termination character. If the returned byte count is less than a full line, discard it. You subsequent reads should be a full line. If a line does not have a defined size, you could just automatically discard the first read.
Now, if you need to read the 23 lines in some particular order, that will require a bit more work.
08-17-2009 02:27 PM
Thanks Dennis, I will try that.
Do you have any suggestions for the other part of the problem?
Say for example, the program starts the read at line 9.
It will read 9-23, then 0-8.
Then it will build the array as
9
10
11
12
.....
22
23
0
1
2
...
7
8
What kind of logic should I use to make it correctly read the data.
The only way I can think to do this is the fact that I know that line 0 is going to be '-->'.
But what I have done so far is :
if line0 == '-->'
[code for serial read, etc]
else:
[clear I/O buffer, do nothing else]
With this stragegy, the VI either works if it happens to be timed correctly, or does nothing if it misses.
If it isnt reading from line 0, it just cycles and never collects any data, because it is in the 'else' case.
08-17-2009 02:41 PM
Cory,
Read one line at a time. When you find line 0, then start building the array. When you find another line 0, process the previous array and start a new one.
Lynn
08-17-2009 02:43 PM
I think you would just need a separate synchronization loop. Read a line, if it ends with -->, then exit the loop and pass the string out to another loop and use it as the first line in your array. This would be your regular read loop The first time this loop executes, you would repeat 22 times. Subsequently, you would run 23 times since you would be synchronized. In the initial loop, if the line is not a -->, just keep reading until it does. I don't think you need to flush the buffer at all. You'll probably want to set a timeout for the first loop.
08-17-2009 02:53 PM
OK, I will give that a try and let you know how it turns out.
08-26-2009 12:28 PM
The synchroniztion loop worked perfectly.
Now it starts the read correctly every time.
Thanks for the tip Dennis.