LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

scan the string from serial port to extract data

Solved!
Go to solution

Dear all,

 

Here is a newbie problem. I have two sensors sending data to a same serial port wirelessly. In order to distinguish which one is which. I coded each sensor to send data with a unique address UoL 000X, then followed by two values I want to read. Those two values are in float with fixed print format (fixed decimal after third bit). The string format from the first sensor should looks like UoL 0001 123.45678 876.54321. I am using the Scan From String Function, unfortunately, it won't work this way. Could you please check the VI for me? Or some better solution for this application. Thanks a lot.

 

S.G

 

 

 

 

0 Kudos
Message 1 of 7
(6,480 Views)

First things first.

 

You are checking the bytes at  the serial port however many bytes are at the port until you have either a timeout, an error, or you have 1 or more bytes.  If you only have 1 byte at the time, the checking loop ends and you read that 1 byte, even though that is not a complete message.  So all checks from there will fail.

 

You have the termination character enabled.  Does your device send a termination character at the end of the message?  If so, that is the best.  Then you should just do a VISA read with a sufficiently large number of bytes.  More than you ever expect to actually receive.  Then the VISA read will stop once you get the termination character which you will then know is a complete message.

 

Second,  your scan from string format is messed up.  You are in normal mode, but you have a /s in the middle of it, along with actual spaces around it.  Do you actually mean \s which would represent a space?  If so, you need to put \s in when the string constant is in \codes mode.

 

Third,  you are decoding for both devices at once, even though you said the message could be from either device.  What you need to do is inspect the string for the device name, decode the values, and use the value from the inspection to decide what formula and indicator to send the data to.  Write now it tries to send it to both even though the data is only for one device.

 

Fourth,  why use a formula express VI for something that is a simple addition?  Use the addition function on the numeric palette.

 

0 Kudos
Message 2 of 7
(6,474 Views)

Hi Ravens Fan,

 

Thank you for your reply.

Two sensors will send a package of data (UoL 0001 123.45678 876.54321) very 30 minutes, 24 hours. Therefore the labview will monitor the serial port constinuously untill soneone hit the stop button. All I want is to extract the right values Fr and Fs from the string, then put them into the right formula and display the output. (The formula is not just a simple addition, I just used it as a simplification). I can code the sensor to send a '/n' as a termination character, but it might be OK just hit the stop button to stop checking.

 

Secondly, I knew that I must messed up with the string format. The code to send the data is " sprintf(strTemp,"UoL 0001 %8.5f %8.5f\r\n",(float)(Fr),(float)(Fs); print_dbg(strTemp);"   When I use the hyperterminal to receive the data, it is exactly what I want "UoL 0001 123.45678 876.54321".  But it still won't work after I changed the string format to "UoL 0001 %f %f" Any idea why?

 

Thirdly, you are absolutely about what I'm trying to achieving. Both sensors are sending the data to same serial port, because I am sending just a small data (only mili seconds) and long interval (30 mins). So there is infinitesimal chance those two signal will mixed up. The results I read from hyperterminal is something like this "UoL 0001 123.45678 876.54321   (........ten mins.......)  UoL 0001 123.45678 876.54321" . I want to put the correct values ( Fr and Fs )to the correct formula for correct sensor.

 

Could you please help me? Thanks a lot.

 

S.G

 

 

0 Kudos
Message 3 of 7
(6,459 Views)
Solution
Accepted by topic author SamGao

It's not working because what you've attached isn't any different from what you attached earlier.  Did you try anything?

 

See that attached modification to your VI.  The format strings work with the examples you gave and sends the data to the appropriate indicator.

 

Also, I cleaned up the mess of that the inner loop where you were waiting for 1 or more bytes.  Which means most of the time you'd probably get an incomplete message.

Message 4 of 7
(6,443 Views)

Hi  

 


The program is working now except the will give another problem with VISA read, error code and screenshot as below. Do you get any idea what is wrong? 

VISA:  (Hex 0xBFFF0015) Timeout expired before operation completed.

 

S.G


0 Kudos
Message 5 of 7
(6,421 Views)

What string are you sending in the VISA write?  Are you sure it is a command the device is recognizing?

0 Kudos
Message 6 of 7
(6,408 Views)

Problems solved. Many thanks.

 

There is another problem with the chart I am using.

 I am not being able to display the time in seconds (Starting with 0 and ending whenever the user stops the acquisition) on the X Axis.

If I choose absolute time, the chart start with 00:00:00 01/01/1904, I don't get it, why the year is 1904?

If I choose relitave time, it actually start from 00:00:00, but the time passed by is not actualy by seconds. For example, the actual time should be 00:00:10, the chart shows 00:00:04.

Any idea why?

 

SamG

0 Kudos
Message 7 of 7
(6,390 Views)