04-12-2019 08:28 AM - last edited on 11-05-2019 09:13 PM by Kristi_Martinez
Hello
I am trying to communicate with arduino from LabVIEW using Visa Write/Read.
Problem: From all other softwares like Ni Max I can communicate really well with arduino but not from LabVIEW.
*not the line feed character problem. I corrected that.
*In ni trace I can see that the data is send and I can see the Rx led at arduino blinking so arduino is recieving the data send.
*if I use a while loop and write like 2-3 times with visa write then the communication works again.
Can someone help me to solve the issue ?
I am also posting a code that is working but I am writing 3 times but I get only 2 times an output at visa read and also a timeout error message.
Thank you
Bitto
Solved! Go to Solution.
04-12-2019 08:32 AM
Are you sure you correct any line feed character problem?
My guess is the problem is in your Arduino code, but you didn't attach that.
04-12-2019 08:57 AM
Thank you for the reply. The problem is not with the line feed because it works if I write like 3 times as you can see in my code and also the code in arduino is just does this : if serial.available then write back what I read.
04-12-2019 09:15 AM
To put it a little more bluntly than RavensFan did...
In the PICTURE of your code, you clearly show the Term Char being set to false. Since it is just a PICTURE, we are unable to tell what characters you are sending.
The error you are getting is most likely from the fact that you set your timeout to be 2 seconds, then wait for 3000 characters to arrive in your VISA read. Are you expecting 3000 chars? Remember, your Term Char has been disabled, so it is patently waiting for ALL the characters to arrive.
04-12-2019 09:57 AM
I added the termination concatenating string and I changed the code in arduino in such a way that I don't really need a term char to get a reply. 2 Seconds 300 characters is stupid, I agree I was trying to check what is happening and messed here and there I guess. I will upload the simple version of the code which still is not working normally but working with visa write inside a for loop. Could you please check the program.
Thank you
04-12-2019 10:23 AM - edited 04-12-2019 10:24 AM
I do not see any problems with the labview code. The only thing I could suggest would be to clear the buffers before writing anything. (Generally only a problem when connecting or disconnected the RS232 cables, or connecting to a spewing source)
The only thing else I can suggest is to put a loop-back cable on the RS232 port on the PC side. This will prove the labview code is solid. Typical trouble shooting steps. IE Divide and conquer 🙂
Good luck
04-13-2019 09:23 AM - edited 04-13-2019 09:35 AM
Which Arduino are you using? According to the FAQs if you are using one with a native USB you need to wait after serial begin.
Void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
}
void loop() {
//proceed normally
}
04-15-2019 03:39 AM
I tried adding a timeout before the write function and also changed the arduino code as you mentioned. It didn't make any difference.
04-15-2019 03:39 AM
Tried, no difference.
04-15-2019 03:55 AM
The program works well after adding a waiting time before Visa write but I had to give a wait of 2 Seconds.
Anyway it works well now thank You 🙂