Jump to content

jbone

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by jbone

  1. And the way to pass variants to the Call Library Node is not as Interface To Data but simply as LabVIEW data. So any of the other three options though it won't really make any difference which you chose as they don't apply to data other than arrays or handles.

    Sorry, but I do not understand if you mean that any other option inside the Adapt to Type is valid or if none of them will work. Would it be possible to get an example on how to pass a variant to a Call Library Function Node (how to configure the parameter options) and how to use the Variant in the C code. I have found the LvVariant class defined in extcode.h but since you says there is no documentation, I do not know how to use it :$

    Thank you very much.

  2. Hi,

    I am working in a DLL to create a Labview component that runs some C code. I was using the Call Library Function, and I see it works to write external functions that get and set Labview data in/from the C code. But now, I would like to make it work with Variants, since I want to allow to wire any kind of data into my CLF Node.

    I have been using the Adapt to Type - Interface to Data option to be able to introspect the LabVIEW Data from my C code and get or set its value. I have been told that Variants are structured very similar to any other LabVIEW Type, so I should be able to use the Interface to Data option as well (with some minor changes in the code and maybe some casts). But the truth is that I cannot even try it since when I connect a Variant to the CLF Node, LabVIEW tells me:

    The data type wired cannot be passed into a Call Library Function Node parameter that is configured to use Adapt to Type with data format of Interface to Data.

    I guess this means that it is not going to be as easy as expected, probably having to do some tricks, workarounds, etc. but right now I do not have any idea on what to try or where to start with. I have been trying to look in the documentation, help and posts anything useful but I did not find anything. So, any help will be greatly appreciated.

    Thank you very much.

  3. Personally I would add an error handler that takes the current parameters and a LabVIEW error cluster as parameters and stuffs the first into the second and also returns an error code (the same stuffed into the cluster) which you can return from the function call to LabVIEW. Every DLL call gets an extra parameter that receives the error cluster and this parameter gets passed to the error handler function whenever it is called.

    Hi,

    I am working in the Error Handling too I would be very interested in know how to do it the way you explain. Because I could not find anything that explains me how to implement the Error Handling and Checking for a DLL that gets called from a CLFN.

    Actually, I would be very happy just if I could associate an error number and message to the "error in" input and "error out" output that the CLFN shows if you select the Default level of Error checking.

    Thanks.

  4. If you're going to allocate memory in your DLL and then hand it back to LabVIEW, you should either use the LabVIEW memory manager functions, or allocate the memory in LabVIEW and then pass pointers to it into your DLL. The LabVIEW memory manager functions are documented in the help, under Code Interface Node functions. Alternately, you can initialize the memory in LabVIEW before calling the DLL by using Initialize Array; for a string, initialize an array of U8 and convert it to a string.

    Thanks a lot! It completely works now... What I do not get is why, if it is necessary to use LabVIEW memory manager functions, I found the examples in Calling C/C++ DLLs Containing Simple and Complex Datatypes from LabVIEW using malloc, realloc, etc.

    Could anyone please clarify?

  5. Ok, If I try to allocate the memory for the string inside the cluster, as shown here:

    _declspec (dllexport) long fillCluster(char* struct_ptr) {        int j;        char* auxS;        char sh[]= "Hello, it works!";      	long* size;	// The cluster stores a handle, that is a pointer to a pointer to the string 	*(*(char***)struct_ptr) = (char*) malloc ( sizeof(long) + (sizeof(char)*strlen(sh)) );    	auxS = *(*(char***)ptr);   	size = (long *)auxS;   	        // Write the size	*size = strlen(sh);	size += 1;		auxS = (char*) size;             			        for(j=0;j<strlen(sh);j++){                auxS[j]=sh[j];        }        return 0;}

    Then, It runs correctly, I do not get any error while saving or running... but, after closing the VI and the project, when I try to close LabVIEW it gets blocked and will never close (I have to kill it).

    Thanks again.

  6. Hi,

    Here is my new problem:

    I am passing a cluster to a DLL function, in this DLL function I want to fill the data of the cluster. So, it works perfectly when I do it with simple elements, but when the cluster has strings or arrays inside, I fill it with the structure explained in How LabVIEW Stores Data in Memory.

    _declspec (dllexport) long fillCluster(char* struct_ptr) {	int j;	char* auxS;	char sh[]= "Hello, it works!";	// The cluster stores a handle, that is a pointer to a pointer to the string 	auxS = *(*(char***)struct_ptr);	// Write the size	*auxS = strlen(sh);	auxS += sizeof(long);				for(j=0;j<strlen(sh);j++){		auxS[j]=sh[j];	}	return 0;}

    And I can see in my VI that the string gets filled correctly. But then, when I try to save the VI, I get this error:

    Fatal Internal Error: "fsane.cpp", line 442

    LabVIEW version 10.0f2

    It seems than some object is making the sanity check fail... so probably it is because I am not filling the cluster object correctly and it gets corrupted. Do I have to allocate the memory for the cluster? for the string inside the clusert? How?

    Can anyone show me how to fill a cluster that is passed to a DLL function as a parameter (pointer to the cluster).

    Any sample code or example will be very appreciated.

    Thank you very much.

  7. You should identify data stored in DLL with some kind of key or handle. Usually just data pointer casted to integer serves well for this purpose (but it may be also an index within some internal array, key-string within associative array or sth like this). So for example: when function in DLL is asked to store some data it allocates memory for it, put the data there and returns a pointer to that area (as an integer). Calling function must keep that pointer and refer to it each time it wants to do something with stored data.

    Ok, I really like that option, because it is the one I started to implement. Thanks very much for the explanation.

    In more advanced case DLL stores a list of pointers it created to keep the track. It gives more control over stored data and helps in fighting with memory leaks.

    This part I do not get it... could you, please, explain it a bit deeper or give me some example on how to do this. Or just tell me a good place to read about.

    Finally, does the Instance Data Pointer anything to do with this purposes? What is it used for?

    Thank you very much.

  8. Like what? Since LV 8.2 callbacks are supported by DLLs.

    I suggest reading my favorite article on the topic: http://expressionflo...ries-and-cins/. Parts 1 and part 3 are of some interest as well.

    Thanks for the info... that explains exactly what I meant to say: in CINs you could have some data associated to each individual instance and I do not see how to do that with CFL and DLLs.

    But let me explain my case:

    I want to make my own LV component that calls some 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? How can I do it with any other possibility?

    Thank you very much.

  9. Hi,

    I want to create a Labview component that runs some C code. I have been trying with the Call Library Function, and I see it works to write external functions that get and return Labview data. But now, I need to store some internal data in the DLL. And, in case I have more than one CLB component calling to the same functions, the data they are going to use should related to the component that is calling the function. So, does anybody know how can I do it?

    I have seen there is something called InstanceDataPtr, but what does it contain? how does it work? Can I use it to identify one LV component from the others? I have been trying to find some example using this parameter, but I didn't found any.

    Thank you very much.

    When I said CLB component, actually I meant CLF (Calling Library Function).

    And another question... I have read about the possibility of using CINs, but... since they are not supported in LV2010, is there any equivalent method or way of doing what you were able to do with them?

  10. Hi,

    I want to create a Labview component that runs some C code. I have been trying with the Call Library Function, and I see it works to write external functions that get and return Labview data. But now, I need to store some internal data in the DLL. And, in case I have more than one CLB component calling to the same functions, the data they are going to use should related to the component that is calling the function. So, does anybody know how can I do it?

    I have seen there is something called InstanceDataPtr, but what does it contain? how does it work? Can I use it to identify one LV component from the others? I have been trying to find some example using this parameter, but I didn't found any.

    Thank you very much.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.