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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conrad 393905 4x Relay Board

Hi,

I try to write a VI for an USB Relay card (USB Interface: Silabs CP2104). Sadly, befor using the available CP210xRuntime.DLL´, you need to call CreateFile function (windows.h) where I struggle with getting a handle.

I tried writing an own .DLL where I call this function in and just start it over LabVIEW but I only get the ERROR 0xC0000005 (with disabled Error in the dll node) or  0x449 (enabled Error in dll node).

I have a c++ programmed test program vom Silabs which works fine, also I programmed my own c++ programm which also works fine, but I want to use the Relay card in an existing VI where I need to call the CP210xRuntimeDLL with that windows COM-Handle.

I also tried to get a communication over MAX, but I don´t know which Commands to use so I didn´t get any reaction from the device. An attempt of a serial Communication over VISA was also not successful.

Google is no help, I find plenty of people with the same Problem, but noone seemed to get it done saying how?.

 

Hope someone has an idea.

 

Thanks!

 

Greetings from Germany

Jooris

 

0 Kudos
Message 1 of 7
(4,108 Views)

I solved the problem. If anyone is interested in LabVIEW communication withe the Conrad 39 39 05 4x USB Relais card, here is my VI.

 

0 Kudos
Message 2 of 7
(4,035 Views)

 AAirich ,

Thanks a lot Smiley Tongue

0 Kudos
Message 3 of 7
(3,466 Views)

Due to a Version Conversion request, I am adding a version that has been converted to LabVIEW 2012.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(2,958 Views)

That VI will sooner or later crash as the call to the CP210xRT_GetPartNumber() function passes an empty LabVIEW string handle to the function whereas this function absolutely positively never ever will be able to deal with a LabVIEW string handle. Even if it doesn't crash it corrupts memory anyhow.

The extra DLL to wrap CreateFile() is a noble approach but pretty much overkill too.

A better approach would be this (attached VIs are in 2009 format):

Create Conrad USB.png

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 7
(2,941 Views)

Very happy to read you guys were able to get this card to work with LabView. I tried your VI and indeed a handle is assigned. Thanks!

 

Next step, however, is still a bit of a mystery to me; how to actually control the board? I see the commands in the manual, but I don't know how to send these. I guess this is something trivial that I'm not getting?

 

Hope anyone of you can help - many thanks in advance!

0 Kudos
Message 6 of 7
(2,873 Views)

You will need to use the Call Library Node to call the function CP210xRT_WriteLatch() function in the CP210xRuntime.dll.

 

This function will need to be configured as follows:

 

Library Name: CP210xRuntime.dll

Function Name: CP210xRT_WriteLatch

calling convention: stdcall

return value: int32

1st parameter: handle, pointer sized integer, pass by value

2nd parameter: mask, 8 bit unsigned integer, pass by value

3rd parameter: value, 8 bit unsigned integer, pass by value

 

The first parameter is connected to the handle value that comes from the Conrad_4x_Relaiskarte_USB_StartUp.vi.

The second variable defines which channels should be modified, with one bit per relay and the least significant 4 bits are used.

The third variable defines if the relay should be closed (bit cleared to 0) or if the relay should be opened (bit set to 1).

Only the relays are changed for which the bit in the mask is set to 1.

 

You can also read back the current relay settings by calling the function CP210xRT_ReadLatch().

 

Library Name: CP210xRuntime.dll

Function Name: CP210xRT_ReadLatch

calling convention: stdcall

return value: int32

1st parameter: handle, pointer sized integer, pass by value

2nd parameter: value, 8 bit unsigned integer, pass pointer to value

 

The first parameter is connected to the handle value that comes from the Conrad_4x_Relaiskarte_USB_StartUp.vi.

The second value will return after a call the current setting of the relays in the lowest significant 4 bits.

 

For both functions you also should evaluate the return value. If it is not 0, there was an error and the function was not successful.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 7
(2,840 Views)