LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET assembly with CVI

Solved!
Go to solution

Hello all,

 

I am using CVI2017 and the tool "Create .NET controller" in order to create an instrument driver for a .NET assembly I have received from Racelogic company. This assembly is to control a GNSS-speed sensor called VBOX. They have created the dll's in a .NET language and they assure that they have done it in a COM compatible way.

 

I have received 3 x dll files and 1 x tlb file. Also a .bat file that registers the COM components. The first question I have is whether I need to create an instrument controller for each dll. The high level functions that I need are in only one of the dll's. I don't know if having an instrument controller for only this dll and having the other dll's all in the same dir would be enough so that they can call to each other.

 

I have created the instrument controller of only the dll with the functions that I need, and the behavior of the program is the following:

....

sError = CDotNetGetErrorDescription(Initialize_Racelogic_SetupApi ());   //sError = ""

sError = CDotNetGetErrorDescription(Racelogic_SetupApi_VBoxSetupApi__Create (&instanceHandle, 0));  //sError ="" and instance Handle is properly addressed
sError = CDotNetGetErrorDescription(Racelogic_SetupApi_VBoxSetupApi_Connect (instanceHandle, "COM1", &serialNumber, &returnValue, ExceptionHandle)); //sError = "", serialNumber=0, returnValue=0, ExceptionHandle=0 ->The connection failed but I have no error information at all

The "Connect" function above is not working and I have no way to know why. Do you have any idea? or any "complete" example of how to use a .NET assembly?

Btw: I also tried to do the explicit linking and it doesn't work neither (the pointer obtained with GetProcAddress is NULL

 

Thanks

0 Kudos
Message 1 of 3
(3,229 Views)

The fact that .Not isn’t really based on COM (but uses it internally anyways) makes me wonder about the documentation quality of your component. Possible the underlaying DLLs are actually ActiveX based (which is fully build on COM) and your .Net DLL is just a .Net Interop wrapper around these COM interfaces.

This all makes trouble shooting this rather difficult. As far as the ActiveX interfaces are concerned should their location be in the registry through that batch file you said you run. Of course you can’t move those DLLs after you registered them.

With .Net DLLs MS moved again away from registering the components in the system and instead went back to a (by default simplified) system similar to classical DLLs of standard locations that it will search for loading .Net assemblies. Theses are the Global Assembly Cache GAC and the directory in which the exe file is located which started the current process. LabVIEW adds to this in the development environment the directory in which the project is located from which the calling VI is executed, possibly CVI does the same for its prj files! That’s it! No other directories are searched by default from .Net.

Not knowing which of those sub DLLs are .Net and which are ActiveX/COM makes it impossible to give you a detailed instruction what you should do.

ActiveX/COM DLLs can’t be moved after being registered (or more correctly need to be reregistered after moving them) and .Net DLLs (except the one you directly reference in your code as CVI will request the full path from .Net ) should be either in the GAC or the root directory of your application.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 3
(2,896 Views)
Solution
Accepted by topic author Lloren

Thanks for the reply Rolfk,

 

I managed to make it work.

 

First, even though I had 4 x dll files from the supplier I only had to create a .NET controller for one of them. The one named Racelogic.SetupApi.dll (impossible to know this beforehand). The other 3 dll's are used from this SetupApi.dll and have to be all in the same dir as the exe file.

 

This is how it looks the instrument driver created by "Tools -> Create .NET controller":

Lloren_0-1580109324493.png

 

Then the sequence of functions in my .c file:

Racelogic_SetupApi_VBoxSetupApi instanceHandle = NULL;

....

Initialize_Racelogic_SetupApi ()

Racelogic_SetupApi_VBoxSetupApi__Create (&instanceHandle, 0)

Racelogic_SetupApi_VBoxSetupApi_Connect (instanceHandle, sSerialCOM, &VBOX.SerialNumber, &returnValue, ExceptionHandle)  

......

Racelogic_SetupApi_VBoxSetupApi_Disconnect(instanceHandle, &returnValue, ExceptionHandle)

Close_Racelogic_SetupApi ()

 

CDotNetDiscardAssemblyHandle(instanceHandle)

0 Kudos
Message 3 of 3
(2,870 Views)