Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Visa Reads/Writes Problem

Solved!
Go to solution

Hi all.

 

I have been using labview VISA to communicate with an I/O device called a µChameleon.

 

I need to monitor the state of mutiple pins by sending a VISA write to poll the pin and then use a VISA read to identify the pins state.

 

The problem I have is when I use multiple VISA Read/Writes. When I run this, a single VISA Read will return the corresponding pin state but all the rest show nothing. The funny thing is when I use highlight execution they will all return the pin state. 

 

The below picture shows the basic premise of what im doing by just copying the basic serial read and write code. For example I send the string "pin 1 state" followed by a carriage return and if it works correctly it should return a VISA Read string saying " pin 1 1" (high) or "pin 1 0" (low).

 

Can anyone help me witht this. Is it a timing issue with the VISA Reads??.

0 Kudos
Message 1 of 14
(5,420 Views)
You are opening the same resource twice. A serial line cannot be used in such parallel way. You should ask for the scond pin after receiving the answer from the first. But you know what the answer looks like so simply askfor the number of chars you expect,without a wait. Visa will wait for you.
greetings from the Netherlands
0 Kudos
Message 2 of 14
(5,416 Views)

Thanks for your reply.

 

When you say, ask for the number of characters, what do you mean??.

0 Kudos
Message 3 of 14
(5,413 Views)
I mean the number of bytes/characters you ask from visa to return. That is known on your system and always the same for the same question
greetings from the Netherlands
0 Kudos
Message 4 of 14
(5,406 Views)
I have looked into what you have said but it seems VISA returns the same number of bytes on both reads. "pin 1 1" and pin "1 0" return the same number.
0 Kudos
Message 5 of 14
(5,405 Views)
That is what Albert meant. No need for the Bytes At Serial Port since you know the number. If you want to monitor the pin state, just put the write/read in a loop.
0 Kudos
Message 6 of 14
(5,401 Views)

Thanks for the feedback guys but I'm still doing something wrong.

 

The 2 pins in question are connected to 2 reed switch outputs which detect whether a pneumatic gripper is closed or is open.

 

I have changed the code as seen in the attachement below but it hangs on the first read and then gives the error as per  the second attachment. The bit number "8" on both reads is the expected number of bits for both "pin state" questions. Is there any more input you can give in relation to this problem?. Thanks again.

Download All
0 Kudos
Message 7 of 14
(5,398 Views)

Hi Banjo B

 

Having looked at your code it looks as if on LabVIEW you are asking for writes from pins 1 and 2.   In LabVIEW ports are numbered starting at zero.  It may be worth changing your code to request writes from ports 0 and 1 rather than 1 and 2, since the timeout error could have been generated when the second VISA Write function tries to access pin 2 and receives no data.

 

You may find the following Knowledge Base (KB) article useful; in particular section 3, "Common Problems":

 

Serial Communications

 

Depending on how old the hardware is that you are using , it may also be that you require a Wait function between the VISA Write and VISA Read functions, as older instrumentation may not be quick enough to respond to commands written to the port.

 

The following KB article may be of use to you:

 

Timeout Error -1073807339 on VISA Read or Write

 

From your code, it looks as if you are using a large enough timeout.

 

I hope this helps but please let me know if you have any further questions.

 

Kind Regards


Marshall B
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 8 of 14
(5,382 Views)

Attaching an image does not do any good. You are obviously looking for the wrong string if you have something like /n so you are probably sending the incorrect termination character as well. Did you turn on '\' Codes Display for the string controls?

0 Kudos
Message 9 of 14
(5,373 Views)
The reason i didnt post the VI and posted the images is because i thought it would be pointless considering you dont have the device to reproduce the error.if posting the VI would help I will do so.

The command I am sending to the device is "pin 1 state" for the first visa write and "pin 2 state" for the second visa write. This sets the device up to return the state of those pins.

Therefore if pin 1 goes high it will return the string "pin 1 1/n". The /n (line feed) is the correct termination character as I have tested all these commands with the basic serial read write example.
I'm thinking now that I should maybe Leave it as 1 visa write and continually poll each pins state. Eventually I want to monitor up to 8 pins using these commands.
0 Kudos
Message 10 of 14
(5,360 Views)