Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling a SainSmart USB relay from LabView?

Hello,

 

I am trying to control a SainSmart 4 channel 12VDC relay (http://www.sainsmart.com/relay/sainsmart-4-channel-12-v-usb-relay-board-module-controller-for-automa... from Labview and having some trouble.  I was hoping to control the module via serial comms but this does not seem to be working. Can anyone suggest an example that I might follow to set this up?

 

Thanks,

 

James

0 Kudos
Message 1 of 13
(8,693 Views)

Hi James,

 

FYI The link you provided below seems to not be working...

 

What version of LabVIEW are you using?  From LabVIEW 2012 if you navigate to Help > Find Examples and then browse to Hardware Input and Output > Serial there are lots of examples that you could use to get you started.  Our other versions of LabVIEW should have similar shipping examples as well.

 

Here is a link to some documentation you might find helpful in getting started as well:

 

http://digital.ni.com/public.nsf/allkb/E22DA85E97818DE78625678C0069BFC9

 

Please give these resources a look and let me know if anything is unclear.  Have a great day!

Andrew T.
National Instruments
0 Kudos
Message 2 of 13
(8,663 Views)

James,

 

Interesting module!

 

It appears that they use the FTDI chips which provide for virtual COM port operation over USB.  However, a quick glance through the documentation files does not show any hints of how to configure the virtual port or what commands are used to control the module. 

 

Have you tried to contact the company to see if they will gieve you the port configuration settings and the command protocol?  With those data it will probably be fairly easy to write a LV prorgram to control the module.  Without it would be a guessing game with a very large number of variables.

 

Lynn

0 Kudos
Message 3 of 13
(8,656 Views)

If someone could try this and see if works for them.  We are using this one on two separate computers with a SainSmart USB 4CH relay board that has the FT245 ftdi chip.  This VI is crude, but works for us.  

Message 4 of 13
(7,021 Views)

Hi Mercedes300turbo,

 

It would be in your best interest to start a new forum post since this one is 5 years old. That will give you better visibility and allow you to ask the specific questions you have for your set up. 

 

Thanks!

Erika
Technical Support Engineer
National Instruments
0 Kudos
Message 5 of 13
(7,009 Views)

There's a LabVIEW driver available on their site ... https://www.sainsmart.com/products/8-channel-12v-usb-relay-module

 

Download and unzip the "Manual" link.  There's documentation and a vi in there that looks like below..KMTronic8Channel.vi.png

 

The documentation also says there's more code here: http://www.kmtronic.com/software-examples.html

 

Craig

0 Kudos
Message 6 of 13
(7,000 Views)

Just to add a note for future users: I found the documentation on the SainSmart website to be incomplete. The solution provided by Mercedes300turbo provides device initialization that is missing in the VISA example. However, on my device the code only enabled me to close one relay at a time. To get around that, I implemented the following:

4CH_SainSmart.png

Clearly the provided FTDI VIs need some work to match good style, but the functionality is there. The 4CH Output control is an array of 4 Booleans. The True values activate the Relays where the False do not.

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 7 of 13
(6,459 Views)

I recently bought 4 of the 4-port 5V relay boards from Sain Smart. I too am struggling to get this working with Labview. As Will said, Mercedes300turbo's version is apparently missing some setup because I could not get it to work consistently. It looks like Will's version (and correct me if I am wrong) works if you only have 1 relay board connected to your PC. I am going to play around with it later. Not familiar with the FTDI VI's.

0 Kudos
Message 8 of 13
(6,355 Views)

True, mine searches for the first board it finds and uses that address. But you should be able to replace the search with specific addresses for specific boards. You need the initialization, otherwise the board likely won’t respond.

 

Hope that helps!

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 9 of 13
(6,352 Views)

Will,

 

It looks like a few of your VI's are not part of the FTDI package unless you renamed them...I believe set bit rate is one of them. I am working on this now. I did try the FTDI example and pulled in the write string portion of yours with no luck. I am sure I will figure it out but I really wished I picked a relay that already had a driver already created. All I want to do is choose the COM port and set appropriately. 😞

 

 

0 Kudos
Message 10 of 13
(6,321 Views)