04-13-2017 01:32 PM - edited 04-13-2017 01:32 PM
Apparently, we all need to read the help document...
The Match Pattern uses a subset of the Regular Expression syntax. Not seeing the ? in the list of those supported. And I am getting some conflicting results. For instance, Use "Serial?\nblah" with \ codes for the string display and ? for the regular expression, I actually get "\nblah" as the after substring. But search for Serial?\n and it can't find it. Anyways, go reading the help and it clearly states to put special characters in brackets. So the proper search should be "Serial[?]\n".
04-13-2017 01:50 PM
The brackets are use for character classes and special characters acts differently when inside a character class. In this case [?] matches "?". Using the \ escape character gives the same result.
In the Match Pattern Function help file the is a green link to special characters, you will find ? listed there.
Ben64
04-14-2017 04:51 AM
Thank you for all the replies, guys.
ben64's suggestion solved the question mark issue! On the other hand, I still want to optimize the code!
1. I have replaced the while loop with a for loop (see image below).
2. Removing the whitespace is tricky! It seems that the output from the small while loop is an array of strings. There is an auto-indexed tunnel on the right side of the while loop.
3. Regarding the serial port, the problem is that sometimes the serial device will not be connected. So the program will crash by trying to open a COM port that does not exist.
I would appreciate your input.
04-14-2017 05:27 AM - edited 04-14-2017 05:41 AM
I would suggest a class. You have a loop with a bunch of shift registers and this screams out to replace them with private data entries, and a single (or two, for errors) shift register.
This will probably also fit more easily around using a bunch of subVIs to clear up the bazillion wires you have everywhere and the large amount of space used by Bundle by Name nodes or similar.
Regarding the whitespace loop, you can use the same function Crossrulez already mentioned in (I think) a different context to do the same, using '\s' as a delimiter. I do wonder if you can't simplify further though - it seems the handling of the array of strings is similar in many cases and might profit from some further changes. Below is a like for like replacement (I think):
(the '\s' constant is in '\' representation - it is a space character)
04-14-2017 05:33 AM - edited 04-14-2017 05:38 AM
Actually, on a further note, of the 7(!!) shift registers at the bottom of the loop, only 'Time Array' is changed (in the 'transfer' case). You don't need them to be in shift registers if you're only going to read constant values - just make them a normal tunnel and you can remove the 7 wires going across for no reason in half of the cases...
This is completely not true. Sorry - I missed the write cases under the mountains of wire!
04-14-2017 10:43 AM - edited 04-14-2017 10:43 AM
cbutcher, I need two string outputs (command running, first element of command) and one string array output (rest of command).
I attempted a first optimization, using the spreadsheet to array function, and managed to get rid of the small WHILE loop. What do you guys think?
I do not know how to tackle the issue with the serial port opening and closing all the time. Concerning the .txt file removal, the strip path function is not exactly what I want, as it not only removes the extension but the name of the file as well, leaving only the folder path.
04-14-2017 11:31 AM
Three very quick comments:
04-16-2017 10:04 AM
Thanks, cbutcher. I implemented the changes. However, I disagree with your first point. Both the type and the size matter. I tested it and it is also mentioned in the context help.
04-16-2017 10:56 AM
I see only 'dimension and representation of array type' - no mention of size. Although it's certainly possible that I'm completely wrong, I can't imagine you'd need to initialize an array of ... many elements in order to read the values from a spreadsheet - that would seem pretty brittle and frustrating to me.