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 6
(1,200 Views)
Solution
Accepted by 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
Message 2 of 6
(1,165 Views)

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:

 

JKrop_0-1725378869746.png

 

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! 🙂

0 Kudos
Message 3 of 6
(345 Views)

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.

Rolf Kalbermatter
My Blog
Message 4 of 6
(332 Views)

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

 

 

Message 5 of 6
(310 Views)

@cordm wrote:

 

Try if this works


Looks actually good. 👍

But the 32/64-bit selection being manual is going to be a problem for most LabVIEW users. 😉

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(301 Views)