LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Scan from string" function issue

Hi all,

 

I have a beginner's question. I am collecting some data from a micromanometer through labview. The input is through a serial RS232 port in ASCII format. Using one of the example VI viz, "Basic serial read and wirte" I see the data coming in the following way:

 

DP -0.123mmH2O

 

What I would like to do is now sort out the above string into just its numeric part and save it as a text file or table for post processing. I tried using the scan from string function but the final output i get is mmH2O if i scan it twice. Can please anyone help me find a solution.

 

Thanks for reading the post!

0 Kudos
Message 1 of 8
(5,691 Views)

Have you tried the functions match pattern or match regular expression?

 

Check in context help and LV help about these functions.

 

These will help you to solve your problem. 

Message 2 of 8
(5,690 Views)

Regular expressions are difficult (but not too difficult to make their value worth the effort); here's a reference I always use.

 

\- searches for the negative sign

{0,1} says to take it if you find it, but don't worry if it's not there (find zero or one of them)

[0-9] is a character class that will return a number

* says to take all that you find

\. looks for the decimal point

regexp.jpg

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 3 of 8
(5,661 Views)

Hi ukbaisdumb

 

 

If the format of the string will be same  DP -0.123mmH2O then you can use the following method

 

regards,

 

shrek

Message 4 of 8
(5,658 Views)
Thanks guys! I should have mentioned I am using labview 7.1 and I do not have the regular expression function, so what do I do? I have the "match pattern" function and "scan from string" function.
0 Kudos
Message 5 of 8
(5,612 Views)

Hi ukbaisdumb,

 

use ScanFromString this way:

sfs.png

It's as simple as it looks like... Search the context help for the different format codes!

 

In case the "DP" in front of the number can change: split the string at the " " (space) and scan for "%f"...

Message Edited by GerdW on 11-12-2009 09:56 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 8
(5,608 Views)

Incase if you need the units too...

untitled.PNG

Message 7 of 8
(5,602 Views)

Further to the problem, now I am reading the string from a VISA read block gathering input from a serial port, which is connected to a pressure measuring instrument. I have used the idea given in the example file of "basic serial read and write.vi" to read the input. Any suggestions as to how I should be doing this?

 

Thanks.

0 Kudos
Message 8 of 8
(5,503 Views)