12-16-2019 04:03 PM
Hi,
I am new to Labview and created a VI that reads data from a serial port. I am using VISA read function and my expected data stream has the following format: A,+000.00,+000.00,M,+022.21,00,3A.
After the Read VISA, I have a Scan from String function. But when I try to run my labview VI it gives me Error 85 Scan From String (arg1). I have the following format for this arg: %s,%f,%f,%s,%f,%f,%x. Could someone let me know where I have it wrong?
Thank you.
Solved! Go to Solution.
12-16-2019 04:12 PM
No.
But if you attached your VI and saved the string you received from your device as default data in either a string constant, control, or indicator, then we might be able to figure how where you went wrong.
12-16-2019 04:20 PM
"%s", a string, matches everything including commas, therefore it never stops, therefore there is nothing after it to scan.
If you change your two "%s" instances to "%1s", that tells them to scan exactly 1 character, and it should work.
12-16-2019 04:20 PM
Because the comma following the "A" is also a string, and everything else after the comma can be interpreted as a string, it scans the whole line into your first output and then scratches its head because it can't find the comma! You have to specify that it only reads one character (the "A") and then you'll be okay. Do the same for all your fixed-width strings.
Or, you can treat it as a comma-delimited string, index each element and work on them separately...
12-16-2019 04:21 PM
@Kyle97330 wrote:
"%s", a string, matches everything including commas, therefore it never stops, therefore there is nothing after it to scan.
If you change your two "%s" instances to "%1s", that tells them to scan exactly 1 character, and it should work.
You beat me to it.
12-16-2019 04:59 PM
Hi,
I tried your solution. It still does not work.
12-16-2019 05:00 PM
Thank you for the reply everyone. I will post my VI in a bit.
12-16-2019 05:04 PM
Alternate solution if you don't have a fixed-length input string: If you scan for this:
"%[^,],%f,%f,%[^,],%f,%f,%x"
The "%[^,]" part means "scan for any string until you get to a comma", which allows for any length of string.
12-16-2019 05:12 PM
Try replacing all of your commas by spaces. Scan from String with %s stops when it encounters a space (which can cause interesting things if your string, itself, has spaces!). You can use the "Search and Replace String" function to do this, but be sure to enable the "Replace all?" option, the left-most of the top Connector inputs. However, you need to "manually" replace the commas in the Format String with spaces, as well. This will give you the result you want.
Bob Schor
12-16-2019 05:55 PM
As an aside, something interesting happened to Scan from String in between LV 2015 and LV 2018. It doesn't parse exactly the same. I had a string that suddenly gave the ol' error 85 after updating the code from LV 2015 to LV 2018. I admit that I was taking advantage of a "generous" interpretation of the help file, but it seemed to work. Somewhere between LV 2015 and LV 2018, they must've tightened up the parsing.