From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read line by line from serial input?

Solved!
Go to solution

I have a flow meter that when you write "x" to it over serial it spits out two lines:

 

Time HH:MM:SS MM/DD/YYYY


#1 METER #1 1234.22121 SCFM 121321 SCF


 


Initially I simply turned off the termination characters and read everything, and just set my bytes to read at how long this message was. But turns out this is different for every flow meter even if they are the same model. The manufactuer told me:

 

The output of the “x”  command is a text string which is the summary of the configured meters. The number of bytes is dependent with the number of configured meters and the value of the measured variables. So the output is not a constant number of bytes and we don’t have a way to control this. The thing that I did before is, instead of counting the number of bytes on the response, I will look for the “LINE FEED” character to terminate a line. The model 155 is consistently append the CR LF character combinations every end of the line. And for the “x” command it will respond to “LOGGING DATA TO TERMINAL” heading as the 1st line then TIME and DATE for the 2nd line then METER 1 summary for the 3rd line, METER 2 summary for the 4th and so on.

 

I only have the 1 meter so how do i wire up a read after line feed? and how do I make sure that it reads both before changing the valuein the flow supply numeric indicator? Usually when it does not find the #1METER#1 string it puts out a 0 which makes my later calculations with this flow value worthless.

 

0 Kudos
Message 1 of 13
(5,439 Views)

Just do two reads for each "x" command.  The first will return the time, the second will return your data.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 13
(5,434 Views)

You mean wire a second read after the first or a new write as well? The meter takes a good 250ms to spit out both lines after each x and querying too soon starts it over. Or do you mean split the wire coming from the write into two reads?

0 Kudos
Message 3 of 13
(5,432 Views)
Solution
Accepted by topic author labview12110

Like this


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 13
(5,409 Views)
I dont think that is working. It starts out with both read buffers displaying opposite values. Time meter time meter and half are cut off. Then settles to buffer two being meter and one being time. But it hangs at times and then gets going again. Like the time is taking more than a minute to update and the flow value won't change for 5-10second intervals.
0 Kudos
Message 5 of 13
(5,405 Views)
I dont think that is working. It starts out with both read buffers displaying opposite values. Time meter time meter and half are cut off. Then settles to buffer two being meter and one being time. But it hangs at times and then gets going again. Like the time is taking more than a minute to update and the flow value won't change for 5-10second intervals.
0 Kudos
Message 6 of 13
(5,404 Views)

Rereading everything here.

 

Are you getting the first header data that the manufacturer said you should?  The data lines should be:

LOGGING DATA TO TERMINAL

Time HH:MM:SS MM/DD/YYYY

#1 METER #1 1234.22121 SCFM 121321 SCF


And there should be a line feed at the end of each line.  So we should actually be doing 3 reads for each "x" command, letting the termination character do its job.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 13
(5,389 Views)

I am not getting the header logging data. in either of my read buffers. What does the line feed look like? I am not seeing anything after SCF or the date.

0 Kudos
Message 8 of 13
(5,385 Views)
I added a third read and it also just gives time once everything has stabilized.
0 Kudos
Message 9 of 13
(5,383 Views)

This is where you start playing with a program like hyperterminal so you can see what is coming through everytime you type an "x".   Once you have a clear picture, then you can figure out how many reads you need to do for everytime you type an "x".

 

Turn on \codes display on your indicators so you can see what a line feed "looks like".

0 Kudos
Message 10 of 13
(5,371 Views)