Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA read of serial data issue

Solved!
Go to solution

Hello everyone, I am new to LabView VISA.

My application is to read data from LDR and turn on and off bulb accordingly, the switching of bulbs is to be displayed in LabView. The program runs perfectly in Arduino and I want to indicate the bulb on/off in labview. I am using VISA for displaying the switching of bulbs.

Arduino program:

volatile int glight,Lstate;
void setup()
{
pinMode(5,OUTPUT);
Serial.begin(9600);
}

void loop()
{
glight=analogRead(A0); //ldr sensor
if(glight<140)
{
digitalWrite(5,HIGH);
Lstate=0;
}
else if(150< glight < 300)
{
digitalWrite(5,LOW);
Lstate=1;
}
Serial.print("L");
Serial.print(Lstate);
}

In LabView I sometimes get correct output indicating that the bulb is ON but that occurs only once and after that it does not run(after it executives once it shows error 85 or sometimes 1 but I assure you the connections are tight and correct). Also a point I should mention is that when I run the LabView program(Highlight Execution: ON) on the "Read buffer" from VISA Read the value that gets passed is "L0L0L0" or "L1L1L1" why does it do this? it should only show  L0 or L1. Please Help! 

0 Kudos
Message 1 of 7
(4,215 Views)

In your Arduino code, use "Serial.println(Lstate);".  The println adds a termination character to the end of the message.  Since you already have VISA configured to use the termination character, you might as well send it.  This will limit the read to just your single message instead of all of the messages up to 2000 characters.

 

From what I am seeing, you should also remove the VISA Write from the LabVIEW code.  I do not see where your Arduino is reading it, so that part is worthless.

 

And finally, you might want to add a wait of some sort to your Arduino loop so you can have more deterministic message rates.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(4,198 Views)

Hi

In VISA you are writing to and reading from the Arduino.

The Arduino is not listening, so why writing to it?

 

You are also reading 2000 characters from the Arduino in LabVIEW why not 2?

 

So just read two characters or 4 if CR LF is added but I believe it is not.

Check in LabVIEW if a 1 or a 0 occurs in that string and read again.

 

I send the modified version back. Only thing you need to do is eventually change the wait to longer or shorter and more important fill in the port to listen to.

 

greetings from the Netherlands
Message 3 of 7
(4,195 Views)
Solution
Accepted by Kraken123

And just to confuse you some more, here is another simplified version.  It does make the assumption you changed that line in the Arduino like I told you above (println).  Also note that your VISA Read will limit the loop rate.  So no need for an additional wait which will likely force you to be behind in the message retrieval.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 7
(4,192 Views)

I can't thank you and '@Albert. Geven'!

I did as you two asked me to, removed the Serial Write because it was not necessary as I was only reading the data from Arduino and secondly the 'Serial.println()' to terminate the continuous read of the data which was causing the error. though I should mention that I used 'Scan from string' function as I had multiple outputs to read  at once.

0 Kudos
Message 5 of 7
(4,154 Views)

Hi all,

I've some problem with reading serial data from arduino too. i already test the serial data are works at serial monitor in arduino software, but it not show at my lab view project.

This is my arduino program.


void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println(analogRead(0));
}

 

 

Please help me

Download All
0 Kudos
Message 6 of 7
(3,600 Views)

caturpermadi,

 You are using a different methodology than the original poster as you are using the LIFA toolkit vi's. If you are going to continue to use LIFA you must load their firmware onto your arduino. Note that LIFA is old and the person who developed it has replaced it with LINX. If you have questions about LINX after going through their tutorials you should probably post them to their website forums. 

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 7 of 7
(3,561 Views)