06-24-2019 09:20 AM
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.
06-24-2019 12:17 PM
Just remove the Event Structure.
06-24-2019 04:42 PM
@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?
06-24-2019 05:39 PM
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
06-24-2019 06:08 PM
@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.
06-24-2019 06:56 PM
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
06-25-2019 08:37 AM
@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.
06-25-2019 08:46 AM
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; }
06-25-2019 01:57 PM - edited 06-25-2019 02:02 PM
@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.
06-25-2019 03:19 PM - edited 06-25-2019 03:34 PM
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.