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.