LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to display each value inside a string on an indicator?

Solved!
Go to solution

Hi,

I am a beginner in labview. I want to split the values stored inside a string and display each value on an indicator. The values are acquired from an arduino through serial communication created into a string.

Note: i have tried using the scan string function but it didn't work so i don't know if i am using it in a wrong way or if there's another function i should use.

Thanks.

0 Kudos
Message 1 of 14
(7,013 Views)

First I would pull the VISA Configure serial port vi outside the loop. No need to keep configuring the port over and over. Secondly we have no idea what your string looks like so I couldn't help with that. Third you said you tried but you are not showing that attempt. Finally you are concatenating your array with a feedback node but you say you want it separated?

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 2 of 14
(7,004 Views)

Sorry i am new to labview i don't know if the feedback node is causing a problem. i used the feedback node with the concatenation function because i saw this method done in the examples and i have tried displaying the string directly without them but the indicator shows nothing. i am trying to send the numbers 26 and 19 (just as an example) through serial communication with arduino. The second picture attached is simulation without using the scan string function.

Download All
0 Kudos
Message 3 of 14
(6,985 Views)

Several comments:

  • For us to help you, you need to provide us with the best (and most accurate) information about your situation.
  • The VI you are using, provided as an attachment, is the "best" way to let us see exactly what you are trying to do.  We can edit your code, potentially run it, see "hidden" cases, etc, and can also see what version of LabVIEW you are using.  The only drawback is we need to have at least that version of LabVIEW ourselves to open your VI.
  • You can also embed an Image (PNGs are best) in your Message.  This saves us the step of downloading and opening attachments, but we can't edit/test a picture.
  • Ah, but you can make a Snippet (see the Edit Menu) and save a special PNG that can "turn into" LabVIEW code.
  • Your specific Error involves trying to Scan from String something (what?) that you received from Arduino.
  • Please run this program:VISA from ArduinoVISA from Arduino

    This is a Snippet, which I'll attach as a PNG and as the underlying LabVIEW (saved with LabVIEW 2016, so you should be able to open it with LabVIEW 2016, 2017, or 2018).  You'll need to set the VISA Resource Name control to match your VI (so it will read from your Arduino) then run the VI.  The VISA Configure Serial Port using the same default Baud Rate (9600) as yours and also uses the default Enable Termination Character (T).  Note the VISA Read command that says "Read 1024 characters".  Because we enabled <LF> as a Termination Character, we will read a string from the Arduino until it sends a New Line (probably 10-20 characters).  When you run this, let us know the string that Arduino returns, and how you want to parse it (is it a single number, several numbers, or what, and what variables do you want to assign to them?).

Bob Schor

Download All
0 Kudos
Message 4 of 14
(6,974 Views)

My purpose is to display values received from multiple sensors (most likely 3) ,stored in arduino, and display the value of each sensor on an indicator (indicator for temperature, indicator for humidity,.....). The arduino sends the data as an array (as i understand labview reads data as a string) through serial communication by a usb cable. I want to separate the values of each sensor from the array (each value will not exceed 1 byte in length) and to display each value (some have several numbers) separately, also it doesn't matter to me if the values are stored in new variables or displayed on indicators directly .

This is the result i got by trying to run your VI:

hiii.PNG

I have made some modifications to my VI. I removed the feedback node and concatenation functions and the VI ran without them successfully (most likely i had a problem with the usb cable) but there was a bit of a delay in displaying the data. I tried using the scan string function to separate the values but it gave me an error. 

 

This is a snippet of my diagram:

snip.png

 

And this is the error i got:

hiii2.PNG

I also attached my VI.

 

Thanks for the help.

0 Kudos
Message 5 of 14
(6,970 Views)

Your read buffer starts with some unprintable byte (which displays as a space before 2619).  You need to better understand the format your device is sending.

 

Note: if you right-click on your string indicator, you can change its display format to show unprintable bytes as hex codes, so you can better see what you are reading.

0 Kudos
Message 6 of 14
(6,958 Views)

@drjdpowell wrote:

Your read buffer starts with some unprintable byte (which displays as a space before 2619).  You need to better understand the format your device is sending.

 

Note: if you right-click on your string indicator, you can change its display format to show unprintable bytes as hex codes, so you can better see what you are reading.


I displayed the output as hexadecimal numbers and this is the result i got:


read.png

Sometimes the reading appears with the extra byte and sometimes not. I have no clue why it appears like that. Also, the reading appears for a short time and disappears.

Note: my main problem is separating the values (26 and 19 in this case).

0 Kudos
Message 7 of 14
(6,942 Views)

If random, odd unprintable characters are showing up, then something is wrong with your Arduino code.  The problem starts there.

 

If you want the 26 and 19 to be separated, why is your Arduino sending them jammed together?  They should be separated with some other character.  A common choice is a comma.

0 Kudos
Message 8 of 14
(6,930 Views)

@RavensFan wrote:

If random, odd unprintable characters are showing up, then something is wrong with your Arduino code.  The problem starts there.

 

If you want the 26 and 19 to be separated, why is your Arduino sending them jammed together?  They should be separated with some other character.  A common choice is a comma.


I modified the arduino code and put the variables inside the loop and this seems to have solved the problem of the odd byte at the beginning. Putting a coma is a good solution for separation in the code but how do i separate them inside labview if i use a special character like a comma? 

Note: i attached the arduino code i'm using. 

0 Kudos
Message 9 of 14
(6,925 Views)

Spreadsheet String to Array.

Or

Scan from String with a format string of %d,%d

0 Kudos
Message 10 of 14
(6,916 Views)