09-23-2021 03:06 AM
I'm working with some DLLs for control devices.
I'm trying to generate "Call Library Function Node" for control my relay device.
The DLL has the "struct" with "linked list".
So Import - Shared Library does not fully work for this case.
the header includes cpp codes like below
enum usb_relay_device_type
{
USB_RELAY_DEVICE_ONE_CHANNEL = 1,
USB_RELAY_DEVICE_TWO_CHANNEL = 2,
USB_RELAY_DEVICE_FOUR_CHANNEL = 4,
USB_RELAY_DEVICE_EIGHT_CHANNEL = 8
};
/*usb relay board info structure*/
struct usb_relay_device_info
{
unsigned char *serial_number;
char *device_path;
usb_relay_device_type type;
usb_relay_device_info* next;
};
/* .... some functions */
/*Enumerate the USB Relay Devices.*/
struct usb_relay_device_info EXPORT_API * usb_relay_device_enumerate(void);
and I have the LabVIEW code,
I set the type of return type is void.
It returns noting. How should I do?
Solved! Go to Solution.
09-23-2021 07:28 AM
First: LabVIEW strings are not C string pointers. The string in that struct can't be done like that.
Second: LabVIEW can't directly handle C pointers. So linked lists can NOT be easily accessed for sure.
You "could" handle that if you are able to work as well as a C compiler but it is CUMBERSOME!
The function really returns in terms of LabVIEW a cluster containing these elements:
cluster (32-bit LabVIEW)
{
uint32 serialNumberPtr;
uint32 deviceNamePtr;
uint32 type;
uint32 nextPtr;
}
cluster (64-bit LabVIEW)
{
uint64 serialNumberPtr;
uint64 deviceNamePtr;
uint32 type;
uint32 filler;
uint64 nextPtr;
}
Now you need to convert this by treating each pointer accordingly.
For the serialNumber and deviceName you likely want to use the vi.lib/Utility/importsl/GetValueByPointer/GetValueByPointer.xnode with an InputType wired to a string constant and for the nextPtr you use the same function but with above struct wired to it again if its value is not 0. Then you repeat that until the nextPtr value is 0.
Last but not least I would hope that library has a dispose function to which you can pass the initial returned pointer to avoid memory leaks.
09-03-2024 10:56 AM
Hi Everyone,
I am using exactly this relay .dll and having the same issues as the original poster.
(I am enclosing the .dll and header file in this email)
For background:
1) I tried importing the .dll (via the Tools >> Import >> Shared Library (.dll) method, however, the wizard was not able to find the function (usb_relay_device_enumerate)...it stated it following error:
2) After searching NI's site, I found this example and solution....
I followed the example (or solution), but after trying this, LabVIEW freezes (and I have to do a CTRL-ALT-DELETE to kill LabVIEW).
Can someone please post an example (snippet), of the LabVIEW code, on how you got this working?
Thank you so much in advance! 🙂
09-03-2024 12:05 PM
As explained in my previous post, LabVIEW can not deal with pointers itself. Accordingly it can NOT import this DLL interface. Not in a million years.
You could hand code it by doing lots of crazy pointer voodoo on the diagram yourself but that requires more C programming knowledge than if you write a wrapper DLL in C that translates between this and a more LabVIEW friendly interface.
09-04-2024 03:24 AM
There is at least one other thread on this forum using that library: https://forums.ni.com/t5/LabVIEW/controlling-a-5v-relay-throught-usb-port/m-p/4094707/highlight/true...
Here is someone who created a LabVIEW-Library, but it is missing the enumeration function: https://www.labviewforum.de/Thread-USB-Relay-DLL-import
Try if this works
09-04-2024 04:52 AM