LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan string for tokens generating errors

Solved!
Go to solution

Hello!

 

I have program which receive strings from serial port, divide it into 2 separate strings and write into separate arrays. Everything is fine, but sometimes Scan string for tokens is generating some strange values. 

For example: If I'm sending strings like this:

23.14 67.00

23.18 68.00

23.18 66.00

and after splitting, I'm getting values like:

23.14, 8, 23.18

67.00, 0, 66.00

It seems like sometimes only last digit is passed.

 

 

Here is my VI

(data in "serial port" is correct)

Zrzut ekranu 2013-12-10 o 00.39.55.png

 

And output values:

 

Zrzut ekranu 2013-12-10 o 00.41.37.png

 

I guess it might be something with delays because if I'm decreasing wait time inside loop, errors appear more often. If so, is there any other (faster) way to split one string into two? I've already checked Search/Split string with set offset but it didn't help.

 

(I'm using LV2010)

0 Kudos
Message 1 of 12
(3,937 Views)

What delimeters are you using?  Can you post your VI instead of a picture?

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 2 of 12
(3,906 Views)

@Piramidowy wrote:

Here is my VI

(data in "serial port" is correct)


No, that's not a VI, just a picture. Shouldn't you wait until at least 11 bytes are at the serial port?

Yes, what are the array elements in your delimiter array? (seems like "spreadsheet string to array" would do the job easier).

 

Attach your VI. Maybe autoindex the "serial port" value at the FOR loop boundary, run it for a while, then inspect the resulting array. Can you disconnect that array and turn it into a diagram constant (right click...change to constant), save the VI under a new name, then attach it here.

0 Kudos
Message 3 of 12
(3,875 Views)

@altenbach wrote:

@Piramidowy wrote:

Here is my VI

(data in "serial port" is correct)


No, that's not a VI, just a picture. Shouldn't you wait until at least 11 bytes are at the serial port?

Yes, what are the array elements in your delimiter array? (seems like "spreadsheet string to array" would do the job easier).

 

Attach your VI. Maybe autoindex the "serial port" value at the FOR loop boundary, run it for a while, then inspect the resulting array. Can you disconnect that array and turn it into a diagram constant (right click...change to constant), save the VI under a new name, then attach it here.


Sorry, here is my VI and serial port array (I'm not sure if I did it correctly though).


I found some spikes in serial port array as well. Don't understand why they doesn't appear in Serial port indicator.

Data is gathered by arduino board with some sensors attached and sent by serial port as a string of values separated with space (eg.: xx.xx xx.xx xx.xx\n)

0 Kudos
Message 4 of 12
(3,858 Views)

It looks like you're not getting spikes.  What's happening is the read from serial port sometimes reads data in the middle of the packet so you end up with either part of a packet or a full packet plus part of the next one.  Since the only delimiter you are looking for is a space you end up losing the extra part of the packet.  You have no method for checking for extra charachters so everything just gets lost.  You can see this if you right-click on your serial port array and select "Codes displaty".  You'll then be able to see the codes in the string.

\s = space

\r = return (carriage return)

\n = new line (line feed)

Serial array.png

 

I've attached a VI that should do what you want.  Probably not the best way to do it but it should work.  I saved it for 2010.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 5 of 12
(3,814 Views)

When you have configured the transmitted string to have a termination character and you are, you should never use the VISA Bytes at Serial Port. You can simply set the number of bytes to some arbitrary high number. No need for the case statement and no need for some fixed wait. The VISA Read automatically stops when the termination character is detected. 

Message 6 of 12
(3,803 Views)
Solution
Accepted by topic author Piramidowy

Yep, use the termination character.  I was in a hurry so didn't get it quite right.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
Message 7 of 12
(3,794 Views)

Thank you very much for your help. Everything is working as it is supposed to.

 

One last question, if I may.

In arduino I have simple loop with small delay (like 200-300 ms) to get all the readings before sending data to serial output. Now if I add Wait Until Next:  Zrzut ekranu 2013-12-10 o 20.17.37.pngin LabView main loop to get samples every 1 sec, at the beginning everything is fine, but after some time I'm getting small delays with sensor readings. I guess it has something with timings of arduino and labview loops. Should I focus on arduino code and make data send exactly at 1 sec intervals or is there another way to deal with that in LabView?

0 Kudos
Message 8 of 12
(3,778 Views)

Why would you want to add any sort of wait in the LabVIEW code. That would not make much sense. With the last example, the LabVIEW code will read the serial port whenever data is available.

0 Kudos
Message 9 of 12
(3,772 Views)

Well, to specify (lower) sampling rate inside LabVIEW program. On the other hand, probably it would be better to deal with that in data-saving part of a program.

0 Kudos
Message 10 of 12
(3,761 Views)