cancel
Showing results for 
Search instead for 
Did you mean: 

"Scan from string" function issue

ukbaisdumb
Member

"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!

7 REPLIES 7
Vsh
Active Participant
Active Participant

Re: "Scan from string" function issue

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. 

jcarmody
Trusted Enthusiast

Re: "Scan from string" function issue

Message contains a hyperlink Message contains an image

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

shrekt
Active Participant

Re: "Scan from string" function issue

Message contains a hyperlink Message contains an attachment

Hi ukbaisdumb

 

 

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

 

regards,

 

shrek

ukbaisdumb
Member

Re: "Scan from string" function issue

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

Re: "Scan from string" function issue

Message contains an image

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

Re: "Scan from string" function issue

Message contains an image Message contains an attachment

Incase if you need the units too...

untitled.PNG

ukbaisdumb
Member

Re: "Scan from string" function issue

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.