12-08-2021 06:28 AM - edited 12-08-2021 06:55 AM
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...
12-08-2021 05:53 AM
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
12-08-2021 06:43 AM
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.
12-08-2021 06:53 AM
Each line is terminated with "\n" or do you mean a termination character is needed in the scan from string formatting?
12-08-2021 06:58 AM
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.
12-08-2021 07:01 AM
@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).
12-08-2021 07:36 AM
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.
12-08-2021 08:59 AM - edited 12-08-2021 08:59 AM
@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...
12-08-2021 12:10 PM
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.
12-08-2021 01:13 PM
@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.