10-06-2008 05:13 AM
Hello, I'm deploying a C# application, upon DAQMx Measurement Studio Library.
When it is statically linked everything works fine, but now I need to get to a dynamic dll linking model.
There are too many customers, with different needs, and we can't force all the customers to update
with a 1 gb driver every time that a single customer needs a new functionality.
What I'm trying to use is the Activator class, example :
public static IMyInterface LoadDll(string strPath)
{
System.Reflection.Assembly asm = Assembly.LoadFrom(strPath);
Type[] typs = asm.GetTypes();
Type dllType = typeof(IMyInterface);
foreach (Type t in typs)
{
if (Array.IndexOf(t.GetInterfaces(), dllType) < 0)
continue;
return (IMyInterface)Activator.CreateInstance(t);
}
}
But what I need is the definition of the interface for my source. Can you post it, or give me a link
where to download it ?
I could then declare in a "proxy" class in my code the needed interfaces,
Or, do you have any piece of code, with a different solution ?
Anything will do, I just need to avoid to statically reference the NationalInstruments.DAQmx.dll
and NationalInstruments.Common.dll on my project.
Best Regards
10-06-2008 07:55 AM - edited 10-06-2008 07:57 AM
Btw, I've found out (don't remember where it comes) a source code example, of an old
NiDaqMx interface. Too bad it is build for VB. Here is the source header :
* National Instruments ' Data Acquisition *
*----------------------------------------------------------------------------*
* Copyright (c) National Instruments 2003. All Rights Reserved. *
*----------------------------------------------------------------------------*
* Title: NIDAQmx.vb adapted from NIDAQmx.h *
* Purpose: VB Declarations for NI-DAQmx library support. *
Where can I find a C# .net 2 equivalent of this code ?
Or at least the NIDAQmx.h file
I would resolve many issues...
Best Regards
10-08-2008 04:35 AM - edited 10-08-2008 04:36 AM
Hi Lorenzpurple.
Unfortunately I think there is no interface source file provided for c#.
Probably the best option in your case would be to exploit a tool which provides interface extraction from assemblies for c# (you can find some on the web).
Otherwise you could do that by hand.
If you right click on a Class Type defined in the DAQmx assembly and then click on "go to definitions" you'll have the extracted interface of the class.
Alternatively, if you want to see the whole interface structure, you can take a look at ....\MeasurementStudioVS2005\VCNET\Include (assuming you're using Measurement Studio 2005) where you can find all daqmx header files.
Finally another solution could be found in using late binding for each daqmx object through the System.Reflection class.
Here I report a very simple example to instantiate a Task object and to invoke its Start() method:
...
using System.Reflection;
...
// we load the daqmx assembly
Assembly a = Assembly.Load("NationalInstruments.DAQmx.dll");
// we get the task type
Type taskType = Type.GetType("NationalInstruments.DAQmx.Task");
// Now we instantiate a Task object
Object myTask = Activator.CreateInstance(taskType);
// Get the start method info for myTask
MethodInfo startMethod = taskType.GetMethod("Start");
//invoke the method
Object returnVal = startMethod.Invoke(myTask, null);//actually need to pass the void type
Please let us know if this works.
Regards
10-08-2008 09:45 AM - edited 10-08-2008 09:52 AM
Hello, thanks a lot for replying.
I also found the NiDaqMx.h file (inside \include dir) but found it too long and difficult to convert manually to C#.
(And I don't want to redo all the work for any new driver version, which happens almost every month).
I also tried the export way (using Reflector.Net) but had no luck, on this solution
the big problem is that the library is connected to other C++ Dll, so the exploit way is blocked.
I also already tried the System.Reflection way, but it is no good, as I need also to pass many different
parameters, in many portions of my code, and I should rebuild too much work.
In the end, I've separated my acquisition module from the calculus core, and made them work
using remoting and tcp callbacks.In this way I will build many different acquisition client, all
of them customized for a particular NI driver...
Hope that there will be some other way some day...
Best Regards