From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Some questions on efficient serial read and speeding up data processing

I have this flow meter that spits out two strings when queried with command "x" : Date:time, and then Meter #1 xxxx.xxxx SCFM . All that the x does is query the meter to display its status. The serial readout from the meter is intended to only duplicate the value present on the little lcd that the meter has. It's not meant for controlling and my discussion with the company was that while not ideal, parsing the string is the only way to get useable info from it. I only need the flow value and there is no way that it will just output that string. So I have it set up to search for the meter name, and if this has a value find the number. Before I did not have the true false case but it meant that the flow would state zero every time that it received the date:time string. My questions are:

 

Is this the only way to do this? both in terms of finding the number I need and making sure that it is always updated properly.

 

Right now I have a delay in the while loop because if I sample too fast, I oversample the buffer and get no useable string data (get one letter or no value at a time). Is there any way to remove this and have continous sampling?  I thought about reducing the wait time to 25ms, searching for a series of characters like #, 1, and parsing the string character by character, but the vi moves too fast to capture all of the data. If I put in a buffer delay I am right back where I started with the longer delay.

 

Is there anything else I can do to make this code more efficient and better sample the flow meters output?

0 Kudos
Message 1 of 23
(4,062 Views)

Does the device send back a termination character such as a line feed or carriage return?  If so, you should be using that to terminate your read after reading a large number of bytes.

 

Right now, your Write/Read sequence is in an odd order.  First you check number of bytes, then you write the X, then you read that original number of bytes immediately after sending the x.  Since it was probably 0 at the port when the loop started, you initially read 0 bytes.  Then the next iteration, (assuming your loop rate was slow enough, you'll get bytes as the port based on the X written in the previous iteration.

 

You need to write the X, delay a period of time, then do bytes at port (assuming you can't use the termination character, and you have a different number of bytes every iteration that you can't rely on), then read that number of bytes.

0 Kudos
Message 2 of 23
(4,161 Views)

The device sends back I believe a carraige return after each line. the x needs to be written every single time i want to query this info, so the bytes at port should be the same with every query, I did notice that it is additive probably because it is in the while loop, is this a bad thing? Is there a way to add in a visa clear to wipe the buffer after each read without impeding the data flow too much?

0 Kudos
Message 3 of 23
(4,014 Views)

If it sends a carriage return, then just wire the number 13 (decimal) to the appropriate input of the Serial Configure VI so that it knows that.  The termination character is already enabled by default.

 

Now just do the VISA Write, then the VISA read with a large number wired to it (larger than the longest message you ever expect to receive).  The VISA read will return immediately after it receives the carriage return and will have a complete message.  No need to use the bytes at port.

 

I don't understand your question about clearing the buffer.  You don't need to clear the buffer because the VISA Read will read all the data in the buffer up to the carriage return.  As long as the device isn't sending anything extra after that, then the buffer will be clear until you send the next message request.

0 Kudos
Message 4 of 23
(4,004 Views)

You should enable termination character in the serial port setup.

 

Set the term char to equal the termination of your data string.

 

Then read until the term char is encountered or a time out.

 

Set the VISA read bytes to a higher amount than you expect to read

 

Set the timeout to somewhat longer than it should take to get a 'good' read

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 23
(3,979 Views)

I am not sure if it does send a carriage return or not. In the hyperterminal program I used to check the connection it does enter the next line about flow on a new line, does this mean that a carraige return was used? either way I have done all of this and am still getting a flow number, but my problem of a low sampling rate is even worse now. I get a data point once every 2seconds, or sometimes every 3 seconds. Is there any way to speed this up? I should be able to get one sample from the pump at least every 25ms, since that is what an older edition of this program would do, and it also did a search within the read strings.

0 Kudos
Message 6 of 23
(3,946 Views)

How much data is the unit sending and how often is it sending it?

 

LabView is not going to receve data any faster than Hyper-terminal does. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 23
(3,939 Views)

The flowmeter sends data by having its terminal echo turned on, so whatever is on the screen will be duplicated on my serial readout:

 

 

4/21/15 07:15 PM (22 bytes)

Flow rate 12121.121 SCFM (49 bytes)

 

I can do a hold on the screen so that it stops on the current screen output so I only have the one line of 49bytes coming to the serial port. I tried to do this and the data was still very slow.

 

0 Kudos
Message 8 of 23
(3,933 Views)

@labview12110 wrote:

The flowmeter sends data by having its terminal echo turned on, so whatever is on the screen will be duplicated on my serial readout:

 

 

4/21/15 07:15 PM (22 bytes)

Flow rate 12121.121 SCFM (49 bytes)

 

I can do a hold on the screen so that it stops on the current screen output so I only have the one line of 49bytes coming to the serial port. I tried to do this and the data was still very slow.

 


How often does it send data to the screen? 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 23
(3,921 Views)

I cannot seem to find that mentioned anywhere in the manual, I did find that it is best to turn off terminal echo when writing the x command which tells it to dump the data, maybe it samples at 1sec, but with terminal echo on AND a query command I am getting a double response which is why i get a value every 2 seconds. does that sound crazy or reasonable?

0 Kudos
Message 10 of 23
(3,915 Views)