LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question mark in pattern matching

Solved!
Go to solution

Hello,

 

I've been having some issues with my LabVIEW program and would like to ask for assistance.

 

The program accepts a script as an input, which is run line by line. Each line is inserted into various pattern matching functions to determine what needs to be done, with the outputs fed into a case selector.

 

One of these cases (the one named "serial") is designed to interface with devices connected to the serial port. I've been using it to try and communicate with a microfluidic pump. However, certain commands that are used to query the pump's status contain a question mark.

 

The issue is the following: when the vi encounters a line containing a question mark the program immediately ends, as if the line with the question mark was the last line of the script. The command with the question mark is executed correctly. However, whatever comes after it never gets executed. It is worth noting that I tried substituting ? with \? and the pump returns an error message, meaning that the command was incorrect.

 

Also, I must say that I am not the creator of the original vi; I just modified it to suit my needs. The comments inside it are mine.

 

I would appreciate your input on the matter. I attach the vi itself and a photograph.

Download All
0 Kudos
Message 1 of 19
(6,106 Views)

Could you save this as a project and post it, or at least include the sub-vi: "Serial write and read v0.2.vi"?

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 2 of 19
(6,072 Views)

Please find attached the Serial write and read v0.2.vi.

0 Kudos
Message 3 of 19
(6,055 Views)

First, what is the line that works some, but doesn't address the full command?

 

Does this Serial case return a timeout error?  When a command is sent that does NOT expect a response from the Instrument, the VISA Read should flag an error as there will be nothing to read. Is this an older instrument?  Some of the older instruments would repeat the command back even though it did not contain a "?".

 

Newer equipment following the SCPI standard does not reflect the command.  Also, the value of bytes to read variable is set to 5.  These SCPI pieces of equipment require the "?" in order to respond and in many cases it will respond with more than 5 characters at that time.  Those additional characters will remain in the instrument's transmit buffer until the next read.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 4 of 19
(6,035 Views)

There are many such commands, for example "?76".

 

The instrument is new. There is no chance of timeout errors. The command is executed correctly but then the script ends, as if there this was the last command. I'm pretty sure the error is in the part of the vi where the matching of the patters is being done, and, specifically, where the "Lines left to run" is updated. Somehow the "Lines left to run" ends up with an empty string.

 

The question mark is a special character in LabVIEW. This is what confuses the program.

0 Kudos
Message 5 of 19
(6,029 Views)

The "?" is not a special LabVIEW character.  It may be special to your coding.  What is the instrument to which you are trying to communicate?

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 6 of 19
(6,017 Views)

The Match Pattern does not care about the ?.  And there are plenty of places that we can optimize here.

 

For starters, I would use the Spreadsheet String To Array function to change your program string into an array of strings.  Then you can just use a FOR loop instead of the WHILE loop.  Also, there are built in functions for trimming white space and getting the extension off of a file path.  And you should not be constantly opening and closing your serial port.  Open it before the main loop and close it afterwards.  Then you can do all of the write and read you want inside.

 

But changing to the FOR loop would greatly help your situation.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 19
(6,014 Views)

Asking a stupid question, but where are these '?' marks? I can't see one anywhere on the BD or the 'Lines to Run' control input given.

 

As a quick side note, you have a while loop with (condition -> not -> continue if true). You can get rid of the 'not' and just wire it to 'stop if true'.


GCentral
0 Kudos
Message 8 of 19
(6,012 Views)
Solution
Accepted by topic author edu11

\? should be used only in the regular expression input of the Match Pattern vi. Modify your code as in the following picture (using Search and Replace String.vi) and it should work.

 

replace.pngedit: I totally agree with Crossrulz that there is a lot of place for optimization in the code.

 

Ben64

Message 9 of 19
(6,007 Views)

@Minions wrote:

The "?" is not a special LabVIEW character.  It may be special to your coding.  What is the instrument to which you are trying to communicate?


"?" is a special character for regular expression used by the Match Pattern vi, it matches a single preceding character or character class as one that can appear zero or one time at the input. So in the present case if you have "Serial?\n" at the string input and at the regular expression input the function will try to match "Serial\n" which doesn't exist in the string control. If you look at the value of offset past match it will return -1 meaning that the Match Pattern function reached the end without finding a match. Since we're at the end of the string the after substring is empty and the loop will be stopped. By adding a backslash in front of the ? (in the regex input only, Serial\?\n) the function will now try to match the literal Serial?\n string.

 

Ben64

0 Kudos
Message 10 of 19
(5,992 Views)