07-02-2013 04:26 AM - edited 07-02-2013 04:29 AM
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
Solved! Go to Solution.
07-02-2013 06:14 AM
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
07-03-2013 02:21 AM
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
07-03-2013 02:25 AM
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
07-03-2013 06:23 AM - edited 07-03-2013 06:28 AM
@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).
07-03-2013 08:55 AM
@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
07-03-2013 09:00 AM
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.
07-03-2013 12:16 PM
@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