LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read 2 analog inputs with VISA

I think the string is showing one value from the two inputs, how do I separate the two inputs so that it is showing two values like 10 and 11 instead of showing a changing value from 10-11?

If I use the scan from string function, it gives me this error: 

Scan failed. The input string does not contain data in the expected format.

 

or

 

 

Error 1 occurred at Scan From String (arg 1):

LabVIEW: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.

 

my code to serial print two inputs: Serial.println(Voltage, Current);

Even if I print separately: Serial.println(Voltage);

                                             Serial.println(Current);

It still only shows one value.. maybe that is the reason why the the Scan From String function shows one value only?

I've tried serial printing two of the input one at a time and it is correct.

0 Kudos
Message 11 of 20
(1,818 Views)

Hi lamela,

 

again I have to ask: HOW does the string look like? Is it so hard to provide an exact example of your received string???

 

I think the string is showing one value from the two inputs

Are you sure or are you guessing? How can we tell what you might "think" when you aren't able to provide examples?

 

You wrote you send values from the Arduino using the command "println(value1, value2)", but now you "think" you only receive ""value1" in LabVIEW?

Get your data communications clear! (And learn to provide meaningful examples!)

 

Edit after your edit:

my code to serial print two inputs: Serial.println(Voltage, Current);

Even if I print separately: Serial.println(Voltage);

                                             Serial.println(Current);

The first command is completely different then the second part! In the first you should receive two values in one line, in the 2nd one you receive one value per line: You need to adapt your string parsing to these strings!

Again: send both values in one line. Use the LF as termchar. Separate the values by some separator char like comma. Check the received string for validity. Use some error checking in your VI.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 12 of 20
(1,800 Views)

Ok, I'm using the one line code now and I added the termchar but it still shows one value now? What should I do?

Download All
0 Kudos
Message 13 of 20
(1,791 Views)

Hi lamela,

 

you still don't use Ctrl-U on your block diagram? Is it so hard to use the keyboard from time to time?

 

I'm using the one line code now and I added the termchar but it still shows one value now?

Which string do you send from the Arduino? Did you debug this and did you compare the string generated in the Arduino with the one received by LabVIEW?

 

What should I do?

As I wrote in my last message: add a separator char between your two values!

And I would also limit the number of digits per value. How accurate does the Arduino measure voltages? With a 12bit ADC you only need 4 digits per value…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 14 of 20
(1,767 Views)

How to add a separator char between the two values? I've checked already and the string is showing both the values at once.. so basically it keeps changing from current value to voltage value. The string in the arduino serial monitor will show two of the correct values but labview shows both that is ever changing?

Do you have a solution to this? My project deadline is getting closer and closer!

0 Kudos
Message 15 of 20
(1,708 Views)

Hi lamela,

 

I already suggested to put a comma between those two values. You need to adapt that "println" command to also put a comma between value1 and value2…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 16 of 20
(1,703 Views)

So I have to add something on the code to make labview display the two values separately?

print code: Serial.println(Voltage, Current);

 

 

0 Kudos
Message 17 of 20
(1,681 Views)

Hi lamela,

 

yes, you need to add a spearator to allow LabVIEW correctly parse the string!

 

As said before I would use a comma between the values, something like "println(value1, ",", value2)".

And as also said before I don't know the correct syntax for your Arduino sketch, you need to figure that one out on your own!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 18 of 20
(1,675 Views)

I've added the separator char and it is showing two values from the string. But the Scan From String function is only showing the value of the voltage(Voltage0) but not the current(Voltage1)?
Here is the error if I don't input the error in and out: 

 

LabVIEW:  Scan failed. The input string does not contain data in the expected format.

 

How can I get both the readings and signals out from the Scan From String function? What can I do?

 

my code: 

Serial.print(Voltage0);
Serial.print(", ");
Serial.println(Voltage1);

Download All
0 Kudos
Message 19 of 20
(1,603 Views)

I got it working already! I just added a comma between the two %f for Scan From String function so it becomes %f, %f.

0 Kudos
Message 20 of 20
(1,571 Views)