01-25-2011 09:47 PM
I want to make my own LV component that calls a C function that uses an external API. So the first time my function is called, it creates and defines some API's variables and objects and store them. So the future callings of my function do not need to define and create them again. The main problem is that this variables and objects must be different for any instance. I mean: if I have more than one Call Library Function components, calling to my function, running at the same time, I need them to create their own API's variables and objects, instead of sharing them. So I need to be able to access or allocate some space memory for each different instance of the CLF component that calls to my function.
How can I do this with Call Library Function? Is there any other approach to do this? How?
Thank you very much.
Solved! Go to Solution.
01-26-2011 06:04 PM
Hi eduraser,
When you are configuring your call library function node, have you tried clicking on the "Run in any Thread" option? This should allow multiple instances of your function to execute. Let me know if that works for you.
Thanks,
01-26-2011 06:40 PM
Thanks, but the point is not just having multiple instances of my function to execute. What I want is to be able to have different variables stored for each instance.
01-27-2011 04:09 AM
You'll have to create some container storage somehow. This could be for instance a pointer to a structure that your initilialize C function returns and as far as LabVIEW is concerned it would be simply a pointer sized integer, let's call it handle. You pass this handle from function to function and each function references whatever information it requires out of the underlaying C structure. Don't forget to add a library function that will dispose of this structure and all it's internal resources.
01-27-2011 02:01 PM
Ok, I really appreciate that answer, thank you very much.
Of course, I understand I need to create a function that disposes, cleans, frees, etc. all the objects and variables created. But I do not know where to call it exactly to make the cleaning in the right moment. I want everything to get cleaned when the Labview execution stops (not paused)... so, should I call it as a callback from the Call Library Function? Anywhere else? Any other option?
Thanks a lot!
01-28-2011 01:58 AM - edited 01-28-2011 01:59 AM
@eduraser wrote:
Ok, I really appreciate that answer, thank you very much.
Of course, I understand I need to create a function that disposes, cleans, frees, etc. all the objects and variables created. But I do not know where to call it exactly to make the cleaning in the right moment. I want everything to get cleaned when the Labview execution stops (not paused)... so, should I call it as a callback from the Call Library Function? Anywhere else? Any other option?
Thanks a lot!
Well typically you have the flow "create(), read()/write()/use(), close() in an application" for any resource and close() would be where you would have to call your dispose function.
If you want this done automatically, the only halfway officially documented way is indeed the unaptly named callback feature of the Call Library Node configuration dialog. The way this is done is by declaring one or more extra function that takes a pointer value as parameter. This pointer can contain whatever you want it to be and you can configure your function to have an extra parameter that is not exposed on the diagram but instead is used to pass this pointer to it.
LabVIEW maintains one such pointer per CLN dataspace instance and calls the apropriate callback function at specified events passing it this data pointer. You could for instance check in the call to the create function if this parameter is NULL and if so store a handle to your resource in there. When the Unreserve or Abort callback is called you could go and clean up your resource.