LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Arduino and VISA, Scan From String Error - LabView v17.0 (64-bit)

Solved!
Go to solution

Hi everybody, I'm working in a project to show the RPM from a motor. The actual value of the RPM is porcesed and send from Arduino to LabView. The problem is when I want to convert that value in a float to show it in a constant or any kind of indicator, just show the error:

"Error 1 occurred at Scan From String (arg 1) in nameofproject.vi"

"Possible reason(s):

LabVIEW: An input parameter is invalid. For example if the input is a path.....".

 

The error could come from the format string argument, from the format specifier, but I try all the possible specifiers and shows the same error. My actual specifier is : " %,; %f".

 

NOTES:

-I was trying before with the format specifier " %.; %f", but I change it to the actual format specifier " %,; %f", and the program run correctly once, later appears the same error, and still until now.

-I'm working on LabVIEW 2017 (v17.0 64-bit).

-I was having the same throuble with another project with smiliar characteristics, but in LabVIEW 2015, this problem is solved adding the VISA Discard Events block before the VISA Close block.

 

IMAGES ATTACHED:

 

 

Download All
0 Kudos
Message 1 of 10
(3,529 Views)

Show the data you have actually received from the VISA Read.  Are you getting any timeout errors? My guess is you are getting a timeout error and an empty string, or something is not formatted properly in your string.

0 Kudos
Message 2 of 10
(3,514 Views)

Hi, thanks for the answer. So, i'm sending the data from Arduino with the Serial.print function, and the value is a float value. You can check in the Block Digram that I posted, exists a "Decimal String To Number" block, and it works correctly, but when I add the "Scan From String" block, the error appears

0 Kudos
Message 3 of 10
(3,509 Views)

Hi jdarias,

 

PLEASE show the string you receive from Arduino in "String leido"! This is the information we need to help you with your issue!

 


@jdarias08 wrote:

So, i'm sending the data from Arduino with the Serial.print function, and the value is a float value.


Arduino usually uses "English" numeric formats, with a point as decimal separator. No idea why you think a format string like %,;%f will give good results in LabVIEW…

 


@jdarias08 wrote:

You can check in the Block Digram that I posted, exists a "Decimal String To Number" block, and it works correctly, but when I add the "Scan From String" block, the error appears


DecimalStringToNumber doesn't care about float values as it handle ONLY integer values! It's the wrong function for this special purpose!

 

So again:

What did you receive in "String leido"?

Why don't you use the error output of either VISARead and ScanFromString to decide about useful values in "Float"?

Why do you need those VISAEvent functions in your code? They are pretty senseless here as VISARead will just wait until 20 bytes (or the TermChar) are received!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(3,463 Views)

Hi, thanks for the answer and for the patience.

In the next images atached, you will see how the string is received from Arduino (removing the Decimal To Number block and the Scan From String block, and all the blocks associated with them), and how the strings are printed in the Monitor Serial (to send the data to LabView, I use the method .print() instead .println(), but in both cases doesn't work in LabView)

 

NOTES:

- I just use the "Decimal String to Number" block to probe if LabView was receiving datas from Arduino, and also if the data was correct.

 

-I know that Arduino, and in general, the point is used as decimal separator, but I think that this is irrelevant, because in the LabView reference, in the "Format Specifier Syntax", in the Syntax Elements, Localization , Codes, there specifies that a comma or a period could be used like decimal separator. In any case, I use period, comma, and the default Localization Codes, but nothing works

 

-I try to use error output in a help, but nothing says to me what is the specific error, so, the most specific information that I have is the error that says "... An input parameter is invalid...", the error that I show in the past images attached

 

-I use the VISA Enable Event block to start the execution when a event occurs in the serial port, in my case, when the string is send from Arduino to LabView through serial port

 

-I use the VISA Wait on Event block to wait until the event from the "Enable Event block" occurs, and send the data (string)

 

-I use the VISA Read block for read the data from the serial port, and is showed in a indicator from "read buffer" output

 

NOTES ABOUT IMAGES ATTACHED:

 

In the Arduino's Monitor Serial, we can count 7 characters, 4 integer numbers, 1 period, and 2 decimals.

 

-1st Image:  In this image I print from Arduino with the method .print(), and the byte count in the VISA Read block is setted to 20 bytes. You can see how is received the string in "String leido"

 

-2nd Image: In this image, I print from Arduino with the method .println(). The value showed in "String leido" seems correct.

 

-3rd and 4th Images: In the image number 3, I setted the byte count at  7 Bytes, and the value is not showed correctly (the real value is between 1700.00 and 1900.00), but sometimes is showed correctly, so this looks like a synchronization problem. In the 4th Image, I keep the byte count in 7, but I use in Arduino the method .println()

 

-5th Image: Some values printed in the Arduino's Serial Monitor, with the method println()

 

 

FINAL NOTE:

All the tests I performed here, are also executed with the "Scan From String" block, but the same error shown at the beginning of this thread persists

 

 

 

 

0 Kudos
Message 5 of 10
(3,440 Views)
Solution
Accepted by topic author jdarias08

Hi jdarias,

 

according to image5 you should read from COM port with default TermChar settings and WITHOUT any of those VISAEvent functions. The received should be converted to DBL using ScanFromString with a format of "%.;%f".

This should work for image2, image3, image4.

 

1st Image: In this image I print from Arduino with the method .print(), and the byte count in the VISA Read block is setted to 20 bytes. You can see how is received the string in "String leido"

Using just print() on Arduino is wrong: you need to insert some separator/termination chars. Use println() instead, which includes the TermChar!

 

3rd and 4th Images: In the image number 3, I setted the byte count at 7 Bytes, and the value is not showed correctly (the real value is between 1700.00 and 1900.00), but sometimes is showed correctly,

Reading just 7 bytes is wrong (because a message also contains the TermChar(s))!

You need to request more bytes than you expect in your message, so use "20" as you did before! VISARead will finish when

  1. there is an error at the COM port
  2. the TermChar has been received
  3. the requested number of bytes has been received
  4. the configured TimeOut is reached

To receive full messages you need to request more bytes then expected to get the received string for condition 2…

(Still you need to implement error handling to handle condition 1 & 4.)

 

I know that Arduino, and in general, the point is used as decimal separator, but I think that this is irrelevant, because in the LabView reference, in the "Format Specifier Syntax", in the Syntax Elements, Localization , Codes, there specifies that a comma or a period could be used like decimal separator. In any case, I use period, comma, and the default Localization Codes, but nothing works

The format of the received string is relevant - and you need to use the corresponding format string.

How you display the converted values later on (and which regional settings you are using) is irrelevant!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(3,427 Views)
Solution
Accepted by topic author jdarias08

@jdarias08 wrote:

Hi, thanks for the answer. So, i'm sending the data from Arduino with the Serial.print function, and the value is a float value. You can check in the Block Digram that I posted, exists a "Decimal String To Number" block, and it works correctly, but when I add the "Scan From String" block, the error appears


PLEASE, when we ask for you to include certain information, actually include in that info in your reply!

 

You say "Decimal String to Number block, and it works correctly".  No it doesn't.  You said you are sending a float value, but Decimal String only yields integer values.

 

To summarize the things you need to do to make your VI work correctly:

1.  Get rid of Decimal String to Number function.

2.  Set your VISA Read to a number of bytes larger than your longest message.

3.  Set the format string for your Scan from String to %.;%f

4.  Use Println() in your Arduino code.

5.  Go back and read the help files on items 1-4, and google help for the Arduino on item 5, so that you understand how all of those functions work and why you need to use them the way we said.

0 Kudos
Message 7 of 10
(3,396 Views)

@jdarias08 wrote:

 i'm sending the data from Arduino with the Serial.print function, 


Try using the Arduino Serial.PrintLn function as it appends a LF to the end to the data for you and you can use that LF as a Termination Character on your VISA Read

 

When you send data from the Arduino separate values by a coma (data1,data2,data3) then using the LabVIEW "Spreadsheet string to  Array" with the delimiter set to a comma you can convert the received string into a numeric array in one step

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 10
(3,379 Views)

Hi again, and thanks a lot for all the support that you are bringing to me.

 

Collecting all the sugestions that you and the others in the next answers, I do the next steps:

 

1). I delete the Decimal String To Number block and all the blocks associated with it. Next I use the method println() to print from Arduino. Also, I delete the Scan from String block and all the blocks associated with it, to only show from read buffer the value received from Arduino, ImageA shows the result, and seems correct.

 

2). I add the Scan From String block, with the next Format Specifier Syntax " %.; %f", as you and others recommended, keeping the println() method to print from Arduino, but the error appears, as you can see in the imageB

 

3). I delete the VISA Wait on Event block, and leave the rest like in the last step (step 2), as you can see in the imageC, and FINALLY, EVERYTHING WORKS FINE

 

CONCLUSIONS:

 

To print from Arduino and to get the string data from LabView, we need to use the println() method, that adds automatically the TermChar. Also, the VISA Wait on Event block is unnecesary, because the VISA Read block will wait until are read 20 bytes of characters from Arduino or until reads a TermChar.

 

Another issue is that the Format Specifier Syntax MUST be like is received from the serial port. In this case was my fault, I understood that the Format Specifier Syntax only was the specifier for the output string from the Scan From String block, but further, we need to consider how is the string received by the Scan From String block.

 

THANK YOU A LOT BY ALL THE SUPPORT AND THE PATIENCE THAN YOU AND YOUR PARTNERS BRINGED TO ME. BEST REGARDS, jdarias

Download All
0 Kudos
Message 9 of 10
(3,353 Views)

Hi jdarias,

 


@jdarias08 wrote:

2). I add the Scan From String block, with the next Format Specifier Syntax " %.; %f", as you and others recommended, keeping the println() method to print from Arduino, but the error appears, as you can see in the imageB

Another issue is that the Format Specifier Syntax MUST be like is received from the serial port.


Again you failed to show the "String leido" content when the error occurs! All we got is an error message, but still without the underlying data…

 

You also should be careful about that format string (as you wrote on your own): it has to request the same format as is used in the received string. Even additional spaces (like in the format string you created) might become the source of problems!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 10
(3,321 Views)