LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Read problems

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?

Cory K
0 Kudos
Message 11 of 19
(1,031 Views)

Cory:

 

Your attachment did not attach.

 

-AK2DM

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 12 of 19
(1,028 Views)

Just one of those days..... Smiley Very Happy

 

Here's the attachment

Cory K
0 Kudos
Message 13 of 19
(1,024 Views)

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.

Message 14 of 19
(1,012 Views)

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.

 

Cory K
0 Kudos
Message 15 of 19
(994 Views)

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 

Message 16 of 19
(991 Views)

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.

 

 

Message 17 of 19
(990 Views)

OK, I will give that a try and let you know how it turns out.

Cory K
0 Kudos
Message 18 of 19
(985 Views)

The synchroniztion loop worked perfectly.

Now it starts the read correctly every time.

Thanks for the tip Dennis.

Cory K
0 Kudos
Message 19 of 19
(942 Views)