LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using NI VISA to control serial relay card

That error -1073807346 says given VISA session is invalid.  There is a way that could happen.

 

You have a For Loop wrapped around the VISA write that runs X number of times based on how many elements are in the array coming from the Relay Inputs VI.  I don't know exactly what is going on in there.  If there are no elements in that array, then the For Loop runs zero times.  A For loop running zero times returns the default data for each output tunnel that it has.  For a purple VISA wire, that is going to be an empty reference.  With the VISA read later on, it will try to read the empty reference and you get that error number.

 

One way to solve that is to turn the purple tunnels on the For Loop into a shift register.  Then it passes through the Valid VISA reference even if the For Loop runs zero times.

 

I would not recommend a timeout value as low as 100 msec, that is generally not enough time for a serial device to send all the requested data reliably.

 

I don't think having different loops for the write and read is a good idea.  Are you writing a request for data, then trying to read it?  That is a typical means of communication on a serial port.  If so, you want to have a Read follow a Write so they stay synchronized.  No way to do that with two separate loops.  And using a global variable to send data from the read buffer in the 2nd loop back to the first is at best unnecessary (nothing else in the 1st loop uses it that couldn't be moved to the second loop), next best just odd and convoluted, worst case leads to race conditions in that variable which will catch up to you later and cause problems.

Message 21 of 23
(998 Views)

Thanks for the replies guys. I hadn't thought about the for loop returning an empty ref. I'll sort that.

 

I'll also try to determine if the card send a termination character.

 

Thanks.

 

John

0 Kudos
Message 22 of 23
(992 Views)

Progress update

 

I gave up with using NI VSA to control the relay card. I found that the card manufacturer provide a specific driver and a set of labview vi's.

 

I uninstalled the old virtual com port (VCP) driver and got the D2XX driver from here. I then downloaded the library of vi's from here. After installing the new driver, I set the latency of the device to 2ms.

 

I then wrote this code with the new vi's.

 

22587iF0D59F87C9A9EEDB

 

I have attached config card.vi and read/write vi incase anyone else is interested. Any feedback on the code is most welcome. It works but i feel it could be a little more efficient.

 

Once again, many thanks for all yout help

 

cheers

 

John

Download All
0 Kudos
Message 23 of 23
(984 Views)