From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Using LabView to Control a Relay Through USB

Solved!
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.

 

 

Capture.PNG

 

3.PNG

 

 

0 Kudos
Message 1 of 5
(3,162 Views)

Hi

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
(3,117 Views)
Solution
Accepted by 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
My Blog
Message 3 of 5
(3,114 Views)

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
(3,095 Views)

Or you can get off the shelf one like this,

https://numato.com/product/16-channel-usb-relay-module/

https://numato.com/kb/understanding-readallwriteall-commands-for-relay-modules/

 

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

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 5 of 5
(3,062 Views)