LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan From String cannot find values from a stream of strings

I am trying to use Scan From String to pick out a data set from a stream of string values. The string values can be seen below. Each line is terminated with "\n". The one I want to pick out is X:1420 Y:1891. The vi works fine when the device only sends out the interested string but when other strings are present, the X:, Y: values only show for a fraction of a second then reset to the default value. Could the experts here find out what is missing? Many thanks!

 

Motor Initializing...

Total x distance in steps: 1420

Current x position: 709

Total y distance in steps: 1891

Current y position: 945

X:1420Y:1891

Traverse Ready...

0 Kudos
Message 1 of 29
(3,861 Views)

I have a stream of strings coming in through serial. The stream looks like below. Each line is terminated with "\n". The line I want to pick out is X:1420 Y:1891. I am using the Scan From String function to pick out the line I am interested in. This works if the device is only sending out the string I am interested in. If it sends out more than one string labview won't recongnise the string. Is there something missing? 

 

Motor Initializing...

Total x distance in steps: 1420

Current x position: 709

Total y distance in steps: 1891

Current y position: 945

X:1420Y:1891

 

0 Kudos
Message 2 of 29
(3,693 Views)

You're reading random sized string parts, 32 bytes each time, and then search those parts for a specific string.

 

That won't work, or it will work coincidently at best.

 

If you insist on not using a termination character (that does seem to be there), you'd have to concatenate the string to build up the complete string, and search that string instead. This will be very impractical, but it's the consequence of not using a termination character or some other means of synchronizing the string messages.

 

Why is there a sequence structure, that doesn't do anything except making your diagram harder to read. Pretty much like all the wire bends.

0 Kudos
Message 3 of 29
(3,854 Views)

Each line is terminated with "\n" or do you mean a termination character is needed in the scan from string formatting?

0 Kudos
Message 4 of 29
(3,851 Views)

Yes, you should be using the Termination Character and set the number of bytes to read to be more (I like to use 100 or even 4096 for terminals).  Then you will be reading complete lines each iteration.  From there, you could use Scan From String to try to parse it.  Just do not update all of the indicators if you get an error.


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
0 Kudos
Message 5 of 29
(3,845 Views)

@samAAF wrote:

Each line is terminated with "\n" or do you mean a termination character is needed in the scan from string formatting?


No.  The "Enable Termination Character" Boolean input to the VISA Configure Serial Port should be set to TRUE.  The Term Char should also be set to 0xA if your strings are ending with a Line Feed (\n).  0xD is a Carriage Return (\r).


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
0 Kudos
Message 6 of 29
(3,844 Views)

Oh right thanks! corrected it but that doesn't change anything. I can see the function picked out the values and they appear momentarily in the bottom right text boxes in the video.

0 Kudos
Message 7 of 29
(3,821 Views)

@samAAF wrote:

Oh right thanks! corrected it but that doesn't change anything. I can see the function picked out the values and they appear momentarily in the bottom right text boxes in the video.


Of course you should also

+ not use Bytes at Port

+ use 0xA or 10 as end termination character (not 0xD)

+ increase the nr of bytes to read so it's always large enough

+ store the values on a successful read, the parsed values will disappear the next cycle because that string isn't the string you want. use a shift register

+ Upload the new code...

0 Kudos
Message 8 of 29
(3,800 Views)

Thank you for the suggestion. Could you elaborate further on how to store a value from a successful read? It appears that the scan from string function will return 0 if nothing of interest is in the string rather than ignore the string completely. This seems to be where the problem is.

0 Kudos
Message 9 of 29
(3,779 Views)

@samAAF wrote:

Thank you for the suggestion. Could you elaborate further on how to store a value from a successful read? It appears that the scan from string function will return 0 if nothing of interest is in the string rather than ignore the string completely. This seems to be where the problem is.


You can store values in shift registers.  Just only update the values if you do not have an error from the Scan From String.


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
0 Kudos
Message 10 of 29
(3,770 Views)