LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to use regular expressions in a case statement?

I am currently trying to use a case statement that takes an action based off of content coming in on a serial port.
For example "B(0001)>\n".
I would like to make it to where i can take in any 4 hex values in the parenthesis rather than hard coding. Is it possible to do this using regular expressions or other methods in a case statement?

0 Kudos
Message 1 of 5
(145 Views)

As far as I am aware - NO

Case structure cannot take in regular expressions.

 

Since you already know the content coming in, why not change the string to numeric and use the numeric in case structure values?

You can combine numerics for example 47.. handles all values 47 and up

 

 

Something like this?

santo_13_0-1632948626014.png

 

-Santhosh
Semiconductor Validation & Production Test
Soliton Technologies
NI CLD, CTD
LabVIEW + TestStand + TestStand Semiconductor Module (2013 - 2020)
NI STS for Mixed signal and RF
Message 2 of 5
(130 Views)

I am taking in several different string formats, that take different value sizes.. I do not believe your method would work for my case.

I attached the specific portion of my VI.

0 Kudos
Message 3 of 5
(111 Views)

Can you evaluate the regex outside the case statement and just base the case structure on the results?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 5
(100 Views)

First, you really need to get rid of all of the local variables. Way too many. Use the wires and shift registers. You could also set the termination character to ">" and your read would read the contents of that entire line back. Though you would have to handle the other couple of cases differently. I'm referring to the "Amberjack" and "Waiting for" cases. I am guessing those are only output at startup which should be relatively easy to handle then. With respect to your other parsing, that is pretty straight forward. Use the regular expression below to separate your opcode from your data and use the opcode as your case selector.

 

Regular Expression Parsing.png

 

Without knowing the specifics of your protocol I can't really provide any other suggestions, especially regarding your two odd responses.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 5
(99 Views)