LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem reading data from arduino with visa read

Solved!
Go to solution

There really is no timeout to worry about for VISA Write.  Whatever you write to it will go out pretty much right away.

 

You don't want Write and Read to occur at the same time.  You want to Write a command, then Read the response.  You do it in series! 

 

I see other issues with your code with an abuse of local variables.  Use wires, not local variables.

 

0 Kudos
Message 11 of 28
(1,351 Views)

I need to write a command and read teh data from arduino at the same time, so what should I do ?

0 Kudos
Message 12 of 28
(1,347 Views)

How can your read a response "at the same time" as you write the command?  You have given your device enough time to react tot he command you sent to it.

0 Kudos
Message 13 of 28
(1,344 Views)

the command is use to move my robot via Arduino, and my robot always sent the data posisition all the time to Arduino even there is no command to it. So I have to always read the data posisition in my Arduino with or without my command to move the robot.  

0 Kudos
Message 14 of 28
(1,342 Views)

Hello everyone

I need some help about visa open duplicate session. Anyone can explain about this ? Can I use this to make my program can read and write at the same time ? Because I have a program with same port that have send data serial to Arduino and the Arduino send data too to LabVIEW all the time, so sometimes, my VI have to read and write using visa at the same time. I really expect someone can explain so clearly because I'm new in labview

 

thank you 

0 Kudos
Message 15 of 28
(1,402 Views)
  1. Open one VISA session at the beginning of your program
  2. Use that same VISA session for every VISA Read or Write in your program by using a shift register to pass that VISA session around your program's main loop
  3.  Close the VISA session at the end of your program

DO NOT open a VISA session for one read or write close it and open a new one every single time!

 

Here's a very simple example...

serial1.png

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 16 of 28
(1,392 Views)
So if i want to make visa write and visa read work at the same time, I have to use shift register in my loop ?
0 Kudos
Message 17 of 28
(1,381 Views)
Solution
Accepted by topic author Reiza

As I have stated, you can do this quite simply with a queued message handler.  Have a loop specifically for communicating with the instrument and talk to it using a queue.  Here is a quick framework for you to work with.


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
Download All
0 Kudos
Message 18 of 28
(1,329 Views)

@Reiza wrote:
So if i want to make visa write and visa read work at the same time, I have to use shift register in my loop ?

Yes, here's a little better example for you. Notice I have the Termination Character enabled and set to the default \n or Line Feed and I have set the VISA Read to read far more bytes than I ever expect to receive.

 

serial2.png

 

Now when you send a command the VISA read will read until it receives the Termination Character or times out.

 

This is how you do serial communications with VISA and any serial device.

 

In your Arduino sketch use the PrintLn command as it appends a Line Feed onto everything for you.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 19 of 28
(1,377 Views)

Can you explain how the shift register works to make visa write and read at the same time ?

0 Kudos
Message 20 of 28
(1,374 Views)