02-04-2010 05:00 PM
I'm looking for some input from users of the "Call Library Function" function. I am building a wrapper DLL to call into another existing lower-level DLL. In the wrapper DLL I will have some functions that could have a Cluster as a paramater, or I could just use separate elements (all uint32). I have two functions that would have 14 such parameters and another that would have 7. From a LV developer's point of view, when needing to call an external DLL with "Call Library Function", which is preferrable, passing a Cluster or passing the individual elements?
02-04-2010 05:09 PM - edited 02-04-2010 05:09 PM
using cluster = one wire per dll * 3 dlls using dimensional analysis we have 3 wires :). Unless the two wrappers with 14 inputs take the same cluster in which case only 2 wires.
not using cluster = 14 wires * 2 dll's with 14 inputs + 7 wires * 1 dll....21 total wires
If not only for block diagram space, I'd go with clusters!
02-04-2010 06:17 PM
for(imstuck) wrote:using cluster = one wire per
dll* 3 dllsusing dimensional analysis we have 3 wires :). Unless the two wrappers with 14 inputs take the same cluster in which case only 2 wires.
not using cluster = 14 wires * 2 dll's with 14 inputs + 7 wires * 1 dll....21 total wires
If not only for block diagram space, I'd go with clusters!
Message Edited by for(imstuck) on 02-04-2010 05:09 PM
So I'll take your input to mean that you think the savings in block diagram space is worth the extra work to create the Cluster.
02-05-2010 12:05 AM
02-05-2010 11:20 AM
for(imstuck) wrote:
Yeah, but its not that much extra work :). It just seems to me that in any language you would want to pass fewer parameters to a function if you could, not just labVIEW. However, this is assuming all your controls relate. You may want a couple clusters and to group "like" controls. Just think of a cluster as a structure in C.
I get what you're saying. On the down side, I implemented a cluster for one of the functions, and it appears that I will be passing a pointer to the cluster. This means that if the cluster is not created exactly right by the developer, when I dereference this pointer in the DLL I could get an invalid memory access and a crash. Passing in individual parameters is more foolproof, as in the worst case the VI passes in an invalid value, the function doesn't work as intended, but no crash.
Now, if I could use a typedef like I can in C, I could type the parameter the same and the cluster-structure problem is avoided. As it is, it looks like creating a cluster to exactly match the memory alignment of a structure is "fraught with peril". If there is a safer way to do this I'm all ears.
02-05-2010 02:02 PM
Garya505,
Can a refernece cluster not be created (See Below) to ensure that parameters are passed exactly how you specify?
Also, if you use the cluster as a control in you application. You may adjust the type def. of the by editing the control object directly. You may choose to add a Strict Type Def. control to your Labview project, that is a cluster containing the correct elements. Or, create a cluster control on your front panel, Right-Click >> Advanced >> Customize.
Please post any further questions you may have on using the cluster objects.
Thanks,
Pcorcs
Patrick Corcoran
Application Engineering Specialist | Control
National Instruments
02-05-2010 02:37 PM
02-05-2010 04:11 PM
02-05-2010 05:02 PM
Garya505,
From the stand-point of distributing your DLL to developers, whether it be Labview or otherwise, a multitude of programming languages may be used to access the functions you have created. Not all languages, including Labview, will have access to the original types you have defined for your data, i.e. a C structure. That said, to enable developers the most information and universal access to your DLL, that best method would be to configure it to accept individual parameters. Such that, all developers may view the valid data types in the correct order.
I believe I misunderstood the orginal post with regard to the cluster interaction, and assumed you would be directly developing in Labview. In which case, clusters offer an effective method for block diagram clean-up, and passing multiple data types to embedded functions. For working with your DLL, it would be the job of the developer to Strictly type the controls to most efficiently interact with your DLL.
Thanks for your post. Please let us know, if you had any further questions.
PCorcs
Patrick Corcoran
Application Engineering Specialist | Control
National Instruments
02-05-2010 05:58 PM
Pcorcs wrote:Garya505,
From the stand-point of distributing your DLL to developers, whether it be Labview or otherwise, a multitude of programming languages may be used to access the functions you have created. Not all languages, including Labview, will have access to the original types you have defined for your data, i.e. a C structure. That said, to enable developers the most information and universal access to your DLL, that best method would be to configure it to accept individual parameters. Such that, all developers may view the valid data types in the correct order.
I believe I misunderstood the orginal post with regard to the cluster interaction, and assumed you would be directly developing in Labview. In which case, clusters offer an effective method for block diagram clean-up, and passing multiple data types to embedded functions. For working with your DLL, it would be the job of the developer to Strictly type the controls to most efficiently interact with your DLL.
Thanks for your post. Please let us know, if you had any further questions.
PCorcs
The intended distribution is to LabVIEW developers only. We design, manufacture and sell a line of specialized video interface hardware. With the hardware, we currently supply a C/C++ SDK that consists of a DLL and some example apps, for our customers to use in developing their own apps. However, we have customers who would like to use our hardware in a LabVIEW environment, so the target distribution for this new "SDK for LabVIEW" (consisting of the "wrapper" DLL, VIs for each function and VI app examples) is really LabVIEW developers only. I am also implementing a LV User Event for handling interrupts from the hardware, so the new DLL really is LabVIEW-specific. Given all that, I think the cluster might be better, though individual parameters would work fine too. I have created a strict type def for clusters for the 3 structures I need to pass. I would assume that these type defs are portable and the developers could use these in their own apps.
Incidentally, the nature of these clusters is such that they do not make good VI controls as grouped in the cluster. The data elements, though related in their function in the hardware, are almost never grouped together on screen. This means that individual controls will still be created for the elements, and the data from these elements will need to be put into the clusters before the DLL call. So, the clusters have little value from a controls viewpoint but, as you pointed out, would simplify the block diagrams. Two of the structures have 14 elements each, and the third has 6.
I appreciate your input. It looks like I have a judgment call to make ...