LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

call library node - using a structure with dll

Solved!
Go to solution

Hi folks.

I was hoping to recieve some help or advice on solving this problem I am having in labview:

 

Some background info - I am trying to use the 'call library node' to allow me to use a .dll to allow for control of a remote power supply over RS-232.

 

I have been doing fine up till now, however I am now trying to use the following:

 

int TC4GetFnBlockSettings(struct T_FnBlock *p_fnblock, unsigned int type)

int TC4SetFnBlockSettings(struct T_FnBlock *p_fnblock, unsigned int type)

 

where

struct T_FnBlock

{

unsigned int BaseFunction;

double Amplitude;

double Offset;

double Symmetry;

double Frequency;

int BipolarAmplitude;

int RectifyAmplitude;

double ExpTimeConstant;

unsigned int NumPeriods;

unsigned int UserDefAmplitude;

unsigned int UserDefTimePrescaler;

double UserDefPeriodLength;

unsigned int UserDefNumPoints;

unsigned int InactiveLevelType;

double InactiveLevel;

unsigned int AAPInputType;

unsigned int AAPInputFilterKoeff;

unsigned int AAPFlags;

double AAPInputScaling;};  

 

Obviously there is no such thing as a structure in Labview; I had hoped to use a cluster in it's place however the CLN does not allow for input or output of a cluster.

 

Any help would be appreciated!

Thanks

 

0 Kudos
Message 1 of 8
(2,837 Views)
Solution
Accepted by topic author boileroo

A cluster is a struct. In this case you dont actually want the struct, but the pointer to it, that's problematic. I've read several posts about problems with that. The easiest solution would be to expose a function with the struct as input instead of the pointer, if you have the possibility.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 8
(2,822 Views)

Thanks for your reply

 

Unfortunately I dont have access to editing the function (at least I if I do, I dont know how!). I guess I'll have to find another means

 

Thanks a lot anyway

0 Kudos
Message 3 of 8
(2,801 Views)

unfortunalty the call library node doesnt map labview types to c types very well. It can be done but took me a lot of time and effort (and overworking google) to manage it. In the end i abandoned the cln and write a c# code that interfaces between my dll and labview. 

sorry cant be of much more help.

 

I think NI need to improve this functionality as the CLN could be useful but hard to get working on anything beyond a simple dll interface

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 4 of 8
(2,799 Views)

@Akiel wrote:

unfortunalty the call library node doesnt map labview types to c types very well. It can be done but took me a lot of time and effort (and overworking google) to manage it. In the end i abandoned the cln and write a c# code that interfaces between my dll and labview. 

sorry cant be of much more help.

 

I think NI need to improve this functionality as the CLN could be useful but hard to get working on anything beyond a simple dll interface


That is not true!

 

The Call Library Node does a tremendous job in providing configuration options to map LabVIEW data to most C datatypes. In most cases the two match directly except when arrays and strings are concerned. Those two are very different in LabVIEW than in C but the Call Library Node allows to configure parameters to map LabVIEW strings and arrays to according C string and array pointers.

 

A structure in C is directly equivalent to a LabVIEW cluster unless it contains strings or arrays. Also there is the potential of structure element alignment which you have to take care of explicitedly but that is hardly the fault of LabVIEW but rather a direct consequence of the rather low level character of the C language.

 

Since the OPs C struct only contains scalar datatypes you can directly create a LabVIEW cluster with the same elements and the same order of elements and pass that cluster to the Call Library Node parameter configured as Adapt to Type.

 

The reason that you might have to get google overworked for such things is not because LabVIEWs support for interfacing to C code is bad, but because interfacing to C code is such a complex topic in itself. Without a lot of low level knowledge about what a C compiler really does when creating functions you are bound to do a lot of trial and error and googling. You get the same issue when trying to interface unmanaged code in C# (.Net).

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 8
(2,782 Views)

@rolfk wrote:

Since the OPs C struct only contains scalar datatypes you can directly create a LabVIEW cluster with the same elements and the same order of elements and pass that cluster to the Call Library Node parameter configured as Adapt to Type.

 

Isn't the pointers always a hassle, or have i misunderstood something? In this case it's the pointer that's needed although the structure itself is easy enough. I'd be happy if i'm wrong. 🙂
Good points.
/Y
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 8
(2,763 Views)

A struct passed by value would be equal to each element in the struct being passed as individual function parameter. A struct passed with Adapt to Type will pass the pointer to the struct to the DLL function.

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

@rolfk wrote:

 A struct passed with Adapt to Type will pass the pointer to the struct to the DLL function.


Cool, didn't know that. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(2,745 Views)