Instrument Control (GPIB, Serial, VISA, IVI)

Showing results for 
Search instead for 
Did you mean: 

Using LabView to Control a Relay Through USB

Go to solution

Hello, I am hoping to use LabView to control a small relay with a USB port. Some other forum posts suggest that this isn't quite possible - I'd have to do some funky stuff with Windows to accomplish this. However, on our testing floor, this has apparently been accomplished with LabView, and I have found the code that's used (below is a screenshot of some of the code). On the testing floor, there is a computer with a USB cable going to a small homemade relay box to control a few different relays. I haven't been able to find the schematic or take apart the box, but I've been told it was made by an old engineer here and is mostly made up of shift registers and relays and just uses the data wires of the USB cable (I think).


I've tried to test this code on a USB wire that I've chopped up and have connected to an oscilloscope, but so far no good. "USB-DIO" (as shown in the screenshot) must be a custom name given a device, right? The error I get is that LabView can't find an instrument. Is there a way to "fake" a connected instrument in NI MAX and send a high signal through a specific USB port? That seems like what is going on in the screenshot, but I could be wrong.








0 Kudos
Message 1 of 5


You need a real USB device. The cheapest option is an Arduino with LINX and that works from LabVIEW.

Even better you will have analog in also and PWM as a kind of analog output too.

greetings from the Netherlands
Message 2 of 5
Accepted by topic author drew2497

The used VIs look definitely like DAQmx VIs, so your claim that it is just a bare USB cable is almost certainly NOT true. DAQmx works specifically with National Instruments DAQ hardware and nothing else. So somewhere in that hardware box you saw there must be a National instruments interface. NI does sell some of their USB hardware as OEM hardware (for instance here for the USB-6501), which means you get a bare PCB with no housing or anything. This is most likely one of these. In reality the hardware is still an NI USB 6501 or similar.


In NI-MAX you then can setup all NI hardware and give it any (unique) name you desire. By default DAQmx likes to call all the devices Dev1, Dev2, Dev3 and so on. But you are free to rename them in NI-MAX to USB-DIO for instance. The only strict requirement is that each device has a unique name on the particular computer.

Rolf Kalbermatter
Averna BV
Message 3 of 5

Thank you both for the replies. I was skeptical about the relay box just being made up of basic electronics. Hopefully, I can get the opportunity to take it apart and see what exactly is in there. I have worked with LINX before, so I may just stick to an Arduino as you mentioned. 

0 Kudos
Message 4 of 5

Or you can get off the shelf one like this,


This one can still be controlled using LV over serial protocol. It depends on what you prefer, whether NI DAQ + Relays, Arduino + LINX + Relays or USB Relays

Semiconductor Validation & Production Test
Soliton Technologies
Message 5 of 5