cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Read problems

Cory_K
Active Participant

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
18 REPLIES 18
Knight of NI

Re: Serial Read problems

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.
Cory_K
Active Participant

Re: Serial Read problems

Message contains an attachment
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
Cory_K
Active Participant

Re: Serial Read problems

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
Ray.R
Knight of NI

Re: Serial Read problems

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 Smiley Wink
 
Otherwise, I don't understand the problem..
 
R
Knight of NI

Re: Serial Read problems

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.
Cory_K
Active Participant

Re: Serial Read problems

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
Cory_K
Active Participant

Re: Serial Read problems

Thanks smercurio,
Problem solved.

Cory K
Knight of NI

Re: Serial Read problems

Message contains an image Message contains an attachment
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
Highlighted
Cory_K
Active Participant

Re: Serial Read problems

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

Thanks for the help.

- Cory

Cory K