LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic VISA Write

Hello all, i was trying to find a way to send commands through the serial automatically. In my project i read the data from sensors through serial read when writing serial commands 1,2,...,5. Now i'm required to get these readings every 30 seconds (i just need to send one number). So is there any method to automatically send a number serially using VISA Write? and how can i put a delay between every iteration?

Thanks.

0 Kudos
Message 1 of 11
(2,697 Views)

Just remove the Event Structure.


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 11
(2,665 Views)

@crossrulz wrote:

Just remove the Event Structure.


if i remove the event structure and change the write buffer to a constant it will work. However, the time of the read and write functions is determined by the timeout in the serial configuration. So the read function will have a huge delay because it will have the same timeout as the write function which is not efficient for my application. How to split the timeout of the read and write functions?

Also, is there a way to make the vi run automatically but also add the write buffer as another option to request the data between the iterations?

0 Kudos
Message 3 of 11
(2,644 Views)

Something is very strange with your VISA device.  It looks like you give it a "command" consisting of a digit from 1 to 4, and it then is supposed to give you back a response that you parse depending on whether you got 1, 2, 3, or 4.  What is puzzling is that usually VISA commands end with "end-of-line" sequences, e.g. <CR><LF>, which you have not used.  I'm wondering if your device is just not responding (because it hasn't yet parsed the command), which would explain why the VISA read is so slow -- it has to time out and then return probably nothing.

 

When a VISA instrument gets a Command that causes it to send a Response, the response is typically "instantaneous" (i.e. at 9600 Baud, 10 characters + <CR><LF> should take about 12 msec, much less than the 10 second timeout).

 

Bob Schor

0 Kudos
Message 4 of 11
(2,639 Views)

@Bob_Schor wrote:

Something is very strange with your VISA device.  It looks like you give it a "command" consisting of a digit from 1 to 4, and it then is supposed to give you back a response that you parse depending on whether you got 1, 2, 3, or 4.  What is puzzling is that usually VISA commands end with "end-of-line" sequences, e.g. <CR><LF>, which you have not used.  I'm wondering if your device is just not responding (because it hasn't yet parsed the command), which would explain why the VISA read is so slow -- it has to time out and then return probably nothing.

 

When a VISA instrument gets a Command that causes it to send a Response, the response is typically "instantaneous" (i.e. at 9600 Baud, 10 characters + <CR><LF> should take about 12 msec, much less than the 10 second timeout).

 

Bob Schor


Actually, i don't know what is causing this exactly. I'm using an arduino device to get readings from sensors and send them to labview. But i probably guess that the arduino code has some delays because it sometimes won't even get the readings and i solved this by increasing the timeout.

0 Kudos
Message 5 of 11
(2,631 Views)

Thank you!  You've told me your problem.  Your VISA Read is (properly) constructed to "read until Termination Character", which is (by default) a Line Feed.  But you have not programmed your Arduino to send data followed by a Line Feed, so the Read just waits for the non-existent Line Feed or 10 seconds, whichever comes first.

 

Program Arduino to send Data and then send <LF>.  You will be pleasantly surprised by the (much better) results.

 

Bob Schor

Message 6 of 11
(2,626 Views)

@Bob_Schor wrote:

Thank you!  You've told me your problem.  Your VISA Read is (properly) constructed to "read until Termination Character", which is (by default) a Line Feed.  But you have not programmed your Arduino to send data followed by a Line Feed, so the Read just waits for the non-existent Line Feed or 10 seconds, whichever comes first.

 

Program Arduino to send Data and then send <LF>.  You will be pleasantly surprised by the (much better) results.

 

Bob Schor


I did program it to be followed by a line feed. Every 3 readings are followed by a print on a new line function. There is a delay in my arduino code itself which i didn't figure the out yet so unless i use a high timeout value the readings are messed up. A method to wait for the readings to come and store them until next iteration may solve this problem.

I attached a sample of the code i'm using which includes the way i'm sending the data.

0 Kudos
Message 7 of 11
(2,607 Views)

In your VISA.txt code, you only have a single printn function in there that occurs if p=4.

 

All your other options, the last print statement of the sections are a regular print!

 

if(Serial.available()>0)
{p=Serial.read();
if(p=='1'){
Serial.print(x);
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.print(z);                                       Why no Printline Here?
}
else if(p=='2'){
Serial.print(a);
Serial.print("\t");
Serial.print(b);
Serial.print("\t");
Serial.print(c);                                  or here?
}
else if(p=='3'){
Serial.print(d);
Serial.print("\t");
Serial.print(e);
Serial.print("\t");
Serial.print(f);                                            Or here?
}
else if(p=='4'){
Serial.print(g);
Serial.print("\t");
Serial.print(h);
Serial.print("\t");
Serial.println(j);                                   Print Line here  GOOD
}
else if(p=='5'){

}
}
p=0;
}
Message 8 of 11
(2,601 Views)

@RavensFan wrote:

In your VISA.txt code, you only have a single printn function in there that occurs if p=4.

 

All your other options, the last print statement of the sections are a regular print!

 

if(Serial.available()>0)
{p=Serial.read();
if(p=='1'){
Serial.print(x);
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.print(z);                                       Why no Printline Here?
}
else if(p=='2'){
Serial.print(a);
Serial.print("\t");
Serial.print(b);
Serial.print("\t");
Serial.print(c);                                  or here?
}
else if(p=='3'){
Serial.print(d);
Serial.print("\t");
Serial.print(e);
Serial.print("\t");
Serial.print(f);                                            Or here?
}
else if(p=='4'){
Serial.print(g);
Serial.print("\t");
Serial.print(h);
Serial.print("\t");
Serial.println(j);                                   Print Line here  GOOD
}
else if(p=='5'){

}
}
p=0;
}

I'm now using the case of sending the number 5 only which brings the readings of all sensors (which you modified for me). If i understand correctly the read operation ends with the linefeed that i put in the end which is what i need. Anyway i tried adding the println afterf every 3 readings and it didn't make a difference.  

0 Kudos
Message 9 of 11
(2,587 Views)

Instead of 

Serial.print(g);
Serial.print("\t");
Serial.print(h);
Serial.print("\t");
Serial.println(j);

How about 

Serial.println(g,h,j);

Or

Serial.println(g","h","j);

It's been a long time since I did any Arduino programming so I can't remember if you need to quote the commas or not, you probably do. But what I am trying to say is send all of your data at once separated by commas and use LabVIEW to sort it out

 

Then read until you receive the termination character or time out.

 

Use the Scan From String function to convert the received data to numeric.

s2s.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 11
(2,572 Views)