04-13-2017 08:30 AM
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.
Solved! Go to Solution.
04-13-2017 08:59 AM
Could you save this as a project and post it, or at least include the sub-vi: "Serial write and read v0.2.vi"?
04-13-2017 09:23 AM
Please find attached the Serial write and read v0.2.vi.
04-13-2017 09:50 AM - edited 04-13-2017 09:53 AM
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.
04-13-2017 10:02 AM
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.
04-13-2017 10:28 AM
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?
04-13-2017 10:30 AM
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.
04-13-2017 10:31 AM
04-13-2017 10:52 AM - edited 04-13-2017 10:54 AM
04-13-2017 12:07 PM
@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