LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

visa read works only when stopped and ran again

On two computers I have a two different vis both with a visa read and write oneis sending out messages and getting responses on the other computer I have a vi that receives the messages and sends out the response to the message. The problem is the vi that gets the responses only reads the responses if I stop the vi then run it again. How can I fix this?
0 Kudos
Message 1 of 4
(2,705 Views)
Hello Molly,

There are a few things that could be going on here. What method are you using to communicate between your VI's? I will assume you are using serial.

If a port is not open, the port will discard the message, which could be what is happening here. If you are trying to write from computer A to B and then have B respond back to A, your code should look like this:

Computer A:
Open VISA serial port.
Wait until computer B has the program running and has opened its VISA port (there is no programmatic way to do this, you will need to synchronize this by hand).
Send request.
Read response.
Close port.

Computer B:
Open VISA serial port.
Read request.
Send response.
Close port.

Hope this helps. If you need more assistance, feel free to p
ost here.

Scott B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(2,705 Views)
Scott,
It is a serial connection.
Right now my Vi is doing this:

Computer A:
Open VISA serial port.
loops to
Read response ( if no response to read) then it
Sends request.
Then loops back to read a response
Close port.


Computer B:
Open VISA serial port.
loops to
Read request ( if no request to read) then it
Sends a dummy response.
Then loops back to read a request
Close port.

Do I need to change one to write first because I had no problems before and it was set up this way??

Also how do I go about doing this??:
"Wait until computer B has the program running and has opened its VISA port (there is no programmatic way to do this, you will need to synchronize this by hand)."
0 Kudos
Message 3 of 4
(2,705 Views)
Hello again,

What I meant by the synchronization "by hand" was that if one computer has not yet started running and the other computer is writing a request and expecting a response, the whole serial application could just wait forever and not do anything. Anything that a computer receives on its port before it does a VISA Open is going to be ignored by that computer.

It seems that you get around this by sending a "dummy response" if the computer detects no data at its port.

From your description of your program, this should work okay. Assuming you start both programs at the exact same time and assuming that each step takes the same amount of time to run, your first read request will timeout and will return you no data. The 2 computers
will then write dummy data to each other, and then the second time through the loop the serial read should pick up the data from the previous dummy response.

Is this what you see happening, or is something else going wrong? Depending on what you want to do, you could change one of them to write first. Are you starting both VI's at the same time, or are you running one followed by the other? Which one do you start first? What exactly happens at each step on each computer?

Hope this helps. Let me know if you are still having problems, and answer my questions above.

Scott B.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(2,705 Views)