LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to differentiate string containing characters vs. numbers?

Solved!
Go to solution

Hello, I am creating an application to read data from a serial port device. The problem is that the device, on startup, outputs a block of text containing characters describing the device. Shortly after, it outputs a command prompt "Command:" It is at this point that I want my VI to input the command to begin taking measurements.

 

I was looking at the VISA Wait on Event and it looks like that could be used to wait for the device to output a "Serial Character" but there is no differentiation between letters and numbers that I can tell.

 

If the device is outputting numbers in the read string, of course, I do not need to input the command to begin taking measurements again, that will only probably confuse the device. In that case, I would like my VI to continue taking measurements with VISA Read.

 

The reason for this is that when I run the application, the device may have already been turned on. Sending that command to the device using VISA Write is unnecessary at that point.

 

Any advice would be appreciated. Thanks.

0 Kudos
Message 1 of 14
(3,345 Views)

Not sure if this is what you are looking for, but this VI will only set "Match" to TRUE if the input string *ONLY* contains alphabetic characters (case does not matter.)  It uses the "Match Regular Expression" VI in the string pallet.

 


Message Edited by SiegeX on 11-24-2008 03:39 PM

Message 2 of 14
(3,342 Views)

Actually, the block of text containing characters also contains numbers (company address, device model/serial number, etc.). If there was a way to check if it only contains numbers, that would probably work.

 

 

I should probably state, the device outputs numbers in the format "XX.XXXX" (ex. 29.3134).  I don't know if the decimal point will ruin that plan or be taken as part of the number, I'd assume the latter.

0 Kudos
Message 3 of 14
(3,334 Views)
It would ruin the plan.  When your device is sending data, are the values seperated by white space or newlines or are they just concatenated together?  Or perhaps each time you do a VESA Read you only get a single value of the form XX.XXXX?

Message 4 of 14
(3,329 Views)

The values are separated by a new line. CR+LF is the read termination character.

 

So it sends one value at a time.

 

Sorry, this is also YeungJohn2, my other account.

Message Edited by YeungJohn on 11-24-2008 03:53 PM
Message Edited by YeungJohn on 11-24-2008 03:54 PM
0 Kudos
Message 5 of 14
(3,323 Views)
Solution
Accepted by YeungJohn2

That makes it alot easier.  In that case this will do the trick.  You'll notice that the bottom case does not match even though it has valid vaules inside of it.  The only thing that will match is if the entire string is of the form XX.XXXX.  By the way, since we are only matching numbers now, you can remove the "ignore case" boolean as it no longer matters.

 

 

Message Edited by SiegeX on 11-24-2008 03:58 PM

Message 6 of 14
(3,318 Views)
Wow thanks I think this will work. I was eyeing the Match Pattern vi in the strings pallet, but hadn't considered using Match Regular Expression. I will see if this works and come back to give you a good rating.
0 Kudos
Message 7 of 14
(3,309 Views)
If it works make sure to mark it as an accepted solution for others who may have this same problem.  Thanks

Message 8 of 14
(3,305 Views)

Oh one last thing, on the top case, can I replace "1234.56" with my read string "XX.XXXX"?

 

Also, if the "Offset Past Match" is Not Equal To "-1", that means that the string is of the form "XX.XXXX" or it is not?

0 Kudos
Message 9 of 14
(3,300 Views)
I figured it out. Haha.
0 Kudos
Message 10 of 14
(3,283 Views)