LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with a DLL function

Solved!
Go to solution

Good morning to everybody

 


I have a problem defining a function that is inside a DLL. The function is as follows:

 

  • TRI_API uint32_t TRI_GetSerialNumList (char ** theBufList, int theBufSize, int theListLength)

    This function returns a list of serial numbers of all sensors currently attached to the system. Call this function to obtain a specific serial number to pass to the TRI_Open() call.

    Parameters:
  • out - theBufList - the list of serial numbers
  • in - theBufSize the size of each serial number buffer
  • in - theListLength  - the length of the buffer list
    Returns:
    The number of sensors present.
 
 

I definied the function like the photo  Definition.png

 

Definition.PNG

When i use the function, see the image Use.png

 

This generates an error in labview that causes it to close. Can someone help me please??

Use.PNG

Pablo Pérez 

 

  

Download All
0 Kudos
Message 1 of 12
(3,133 Views)

My first guess would be you're using the wrong calling convention...

0 Kudos
Message 2 of 12
(3,109 Views)

But also (once it doesn't crash anymore) the string probably won't work. When LabVIEW get's it back, it will be truncated at the first \00. \00 are probably used to separate the items, so at best you'll get the first.

 

So either pass an array of U8s, and split manually, or allocate memory (DS functions) and do the math on the pointer. I'd begin with the first...

0 Kudos
Message 3 of 12
(3,104 Views)

Thanks for your answer


I have tried a new definition in consequence of what you were telling me:

 

Pablo_Novadep_0-1586351349932.png

 


still not working could you give me some indication of how I should define it?

 

Thank you very much

 

 

0 Kudos
Message 4 of 12
(3,092 Views)
Solution
Accepted by topic author Pablo_Novadep

This function expects almost certainly an array of string pointers. That is not something you can directly configure in the LabVIEW Call Library Node. You never can be fully sure with these things as the C syntax is not rich enough to describe these details. The function could as well allocate a memory buffer itself and return that in the first parameter and simply seperate all the strings with a special character such as a \00 byte. The extra parameters that indicate the list size and the string size however would indicate against this option.

 

What you will most likely need to do is to configure the parameter as an array of pointer sized integers. Then in a loop before calling this function you need to create theListLength number of pointers with the vi.lib/Utility/importsl/DSNewPtr.vi node with theBufSize as size input. Pass this array to the first parameter together with the theBufSize to the second and theListLength to the third. After the function, loop through the returned array and retrieve the string value with vi.lib\Utility\importsl\GetValueByPointerGetValueByPointer.xnode and also dispose the pointer with vi.lib/Utility/importsl/DSDisposePtr.vi.

 

To be completely correct you would also use the return value of the function to conditionally retrieve string values for only the number of strings that the function actually filled in. Easist would be to simply seperate the read string value and dispose pointer into two different loops. Pass the return value of the function to the read string loop N terminal and let the dispose loop go through each array element with autoindexing only.

 

It's pretty much similar to this post here, although I didn't use the importsl subVIs there but directly called the necessary LabVIEW manager functions.

Rolf Kalbermatter
My Blog
Message 5 of 12
(3,088 Views)

Good afternoon Rolf

 

Many many many thanks for your help!!! I am already seeing the light at the end of the tunnel because I do not have much knowledge of C. Once I have the detector's own Handle, the rest of the functions are like other detectors I've worked with.

 

This is my solution with your help:

 

 

Captura.PNG

 

With this I have obtained the corresponding serial number, No i have to introduce this serial number in the function TRI_OPEN

 

TRI_API TRI_tHandle TRI_Open (const char * theSerialNum)


I have defined the function like this:

 

Captura2.PNG

 


But it does not work.  Do I have to change the string to U8 array??

 

Again thank you very much for your help.

0 Kudos
Message 6 of 12
(3,064 Views)

@Pablo_Novadep wrote:

Captura.PNG

Don't wire a string inside a cluster to the GetValuePointer node. It's not wrong but doesn't add anything useful either. A simple string is enough and saves you the unbundle node later. Also the String Subset node should not be needed. The Get Value Pointer node should only return the string up to the \00 character anyways, which will generally be shorter than the BufSize value anyways.

 

Also you should not just return the first string! This function is meant to return you the strings for all devices that the shared library could find. Return an array of strings to the caller instead and let him select the correct sensor from the list if there are more than one.

 

With this I have obtained the corresponding serial number, Now i have to introduce this serial number in the function TRI_OPEN

 

TRI_API TRI_tHandle TRI_Open (const char * theSerialNum)


I have defined the function like this:

 

Captura2.PNG

 


But it does not work.  Do I have to change the string to U8 array?? 


It should work. What doesn't work? What error do you get?

 

And your TRI_tHandle MIGHT be a pointer sized value, but without seeing the header file that can't be determined.

Rolf Kalbermatter
My Blog
Message 7 of 12
(3,057 Views)

The definiton of the function is:

 

typedef int TRI_tHandle

 

TRI_API TRI_tHandle TRI_Open (const char * theSerialNum)

 

This function initializes the USB interface and opens a specific sensor for use. It returns a handle for the sensor to use in subsequent library calls. Prior to calling TRI_Open(), call TRI_GetSerialNumList() to obtain a list of attached serial numbers.

Parameters:
in - theSerialNum  -the serial number of the sensor to open
Returns:
The handle to the sensor. TRI_HANDLE_NULL if not opened.

 

The value of the 8 letters/numbers of the serial number is M23KS3V2.

 

And the error is:

 

Use.PNG

 

 

 

0 Kudos
Message 8 of 12
(3,050 Views)
Solution
Accepted by topic author Pablo_Novadep

@Pablo_Novadep wrote:

 

And the error is:

 

Use.PNG


Calling Convention is correctly configured?

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 12
(3,045 Views)

Ok this is the problem. You are a crack!!!!

 

 

Many many thanks for your support and your help!!!

0 Kudos
Message 10 of 12
(3,041 Views)