LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to treat linked list with struct values in Call library function node

Solved!
Go to solution

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,

DYLeephysics_0-1632384260894.png

 

DYLeephysics_1-1632384341534.png

 

I set the type of return type is void.

 

It returns noting. How should I do?

0 Kudos
Message 1 of 2
(736 Views)
Solution
Accepted by topic author DYLee.physics

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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 2
(701 Views)