LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Read problems

Hi,
I am having some difficulty with reading in data via a serial port.

My VI is the following:
1) Configure Port - wired to all correct settings
2) Serial Read - with output wired to indicator
3) Serial Close
 
The data is real-time, and sends to the computer every 2 seconds.
 
Now, when I run the program, I get data, but here's the problem:
 
I cannot keep all the data visible. Once a new set of data is sent, it clears the old set.
 
The data is formatted so that it comes in a block that is about 20 lines long,
with the end of each line marked with ' \r\n '.
 
It will give me 1 line, then clear, give me the next line, clear, etc.
 
How can I make the indicator not clear anything?
 
Thanks
- Cory
Cory K
0 Kudos
Message 1 of 19
(3,888 Views)
I'm not sure what this statement
It will give me 1 line, then clear, give me the next line, clear, etc.
means. However, in general, if you want to display a running tally of what you've received on a serial port you need to use a shift register. Presumably you have a loop. So, create a shift register for the loop and simply append the string you receive to the previous string. See the LabVIEW Help on shift registers.
0 Kudos
Message 2 of 19
(3,883 Views)
Heres the VI I have so far.

What I was trying to describe before was this.
Instead of getting the following:
"32 \r\n
14 \r\n
15 \r\n
16 \r\n
34 \r\n
25 \r\n
...."
 
I am getting:
"32 \r\n"
then
"14 \r\n"
then
"15 \r\n"
then
"16 \r\n"
then
"34 \r\n"
then
"25 \r\n"
etc
 
It isn't one complete string, it is just one line at a time.
Cory K
0 Kudos
Message 3 of 19
(3,845 Views)

Is there any way I cant write a line to an array or something?
Then when it hits "\r\n", start a new line?

Because ultimately I am trying to split up the information that is coming in,
and send it to the appropriate places in my VI.

Thanks,
Cory

Cory K
0 Kudos
Message 4 of 19
(3,840 Views)
When you say you're getting:
32 \r\n"
then
"14 \r\n"
then
"15 \r\n"
then
"16 \r\n"
then
"34 \r\n"
then
"25 \r\n"
etc
Do you mean that you have to run your vi multiple times?  Or do you get that in one shot?
If you get it in one shot, it should look like:
 
"32 \r\n
14 \r\n
15 \r\n
16 \r\n
34 \r\n
25 \r\n
etc"
 
Unless by somew strange reason that the string actually contains quote signs... that I doubt 😉
 
Otherwise, I don't understand the problem..
 
R
0 Kudos
Message 5 of 19
(3,833 Views)
Your serial port configuration is set up so that the termination character is enabled. The default termination character is linefeed. This means that the VISA Read will terminate once it sees the linefeed character. That is why when you run the VI you get just one line. Then, when you run it again you get the next line. If you want to get all the data you need to disable the termination character (this is an input to the VISA Configure Serial Port), and use the "Bytes at Port" to get the number of available bytes so that you read that many. Open the example called "Basic Serial Write and Read". That example is set up in this way.

To convert your string into an array just use the Spreadsheet String to Array function.
0 Kudos
Message 6 of 19
(3,828 Views)

OK, the instrument sends data on an interval, which i have set to 2 seconds.

The data comes formatted like so:

a
b
c
d
etc

The problem is, my indicator will only show "a", then "b", then "c", instead of "a b c d" in a column

 

Cory K
0 Kudos
Message 7 of 19
(3,826 Views)

Thanks smercurio,
Problem solved.

Cory K
0 Kudos
Message 8 of 19
(3,819 Views)
Are you trying to run the VI that you posted using the "continuous run" button? If so, stop. That's not how you want to run it. You need a loop. You also need a shift register to collect the data as it comes in. In other words:




Message Edited by smercurio_fc on 07-23-2008 05:01 PM
Message 9 of 19
(3,817 Views)

Oh....... I knew that......I was just .....uh..... testing you

Thanks for the help.

- Cory

Cory K
0 Kudos
Message 10 of 19
(3,814 Views)