LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Error 85 Scan from String (arg1)

Solved!
Go to solution

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.

0 Kudos
Message 1 of 15
(2,983 Views)

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.

0 Kudos
Message 2 of 15
(2,967 Views)

"%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.

0 Kudos
Message 3 of 15
(2,952 Views)

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...

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 15
(2,951 Views)

@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.

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 5 of 15
(2,950 Views)

Hi,

I tried your solution. It still does not work. 

0 Kudos
Message 6 of 15
(2,928 Views)

Thank you for the reply everyone. I will post my VI in a bit.

0 Kudos
Message 7 of 15
(2,926 Views)
Solution
Accepted by topic author sarat212

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.

0 Kudos
Message 8 of 15
(2,922 Views)

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.

Scan from String without commas.png

Bob Schor

Message 9 of 15
(2,920 Views)

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.

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 10 of 15
(2,902 Views)