Hello,
i created c++ libraries for all generic classes (functions are still 1:1 but i need to switch the return parameter to an out parameter). Now there is the new DotNet-adapter available and i want to switch to C#.
Can someone provide a starter example how to execute the generic functions with c#? (I only find examples for specific drivers.) Thx
Answer by Kirk Fertitta · Feb 10, 2017 at 02:45 PM
Ok, so you're talking about the NI adapters then perhaps. Those, combined with the IVI-C class drivers, allow you to use the IVI-C class driver to call into an IVI.NET or IVI-COM driver. That's the only way I know of to have a single application "interchangeably" access different kinds of IVI drivers without changing code and by only changing settings in MAX. I've never tried it myself, but I understand that it should work. This would really be an NI product question, however, as those adapters are not owned or supported by the IVI Foundation.
What you are trying to do is not really a supported IVI scenario -- trying to interchange an IVI-COM specific driver with an IVI.NET specific driver with an IVI-C driver. IVI is really only designed to interchange within a single "kind" of driver. If you write a C# application using the IviSessionFactory and target a Keysight IVI-COM driver and you later want to access another driver of the same class, then that new driver has to be an IVI-COM driver. Same thing with IVI.NET. The only supported way to create an IVI-COM driver in an interchangeable fashion is via the IviSessionFactory and that class has no idea how to create an IVI.NET driver. Same goes for the Ivi.Driver class -- it only knows how to create an IVI.NET driver. The NI class drivers *do* know how to create all three kinds of drivers (assuming the adapters are installed) but they are designed to be invoked from a C/C++ client application -- not from a C# application.
I hope this clears things up for you.
Answer by Kirk Fertitta · Feb 09, 2017 at 03:23 PM
Hi @ToMa,
I'm afraid I'm not following your question. What is it you are trying to do? The IVI Shared Components include .NET interop assemblies for calling through C#.
Answer by Kirk Fertitta · Feb 09, 2017 at 04:31 PM
You just use the IviDriver class in the Ivi.Driver.dll assembly and call it's static "Create" method, like so:
var driver = IviDriver.Create("MyLogicalName");
There are generic overloads ("Create<T>") as well that allow you to get back a more specific interface, if you like, such as "IIviScope", as in the following:
var scope = IviDriver.Create<IIviScope>("MyLogicalName");
Hope this helps.
Answer by Kirk Fertitta · Feb 10, 2017 at 01:50 PM
You mentioned a .NET adapters so I thought you were trying to use an IVI.NET driver under the covers, but the question is ambiguous. Is your underlying specific driver an IVI-COM driver or an IVI.NET driver? If it's an IVI.NET driver, then you add a reference to Ivi.Driver.dll (not Ivi.Driver.Interop) and use the code above. If it's an IVI-COM driver, then you use the IviSessionFactoryClass which is located in Ivi.SessionFactory.Interop.dll.
var factory = new IviSessionFactoryClass(); var driver = (IIviDriver)factory.CreateDriver("MyLogicalName");
Answer by Kirk Fertitta · Feb 10, 2017 at 02:08 PM
I'm afraid I really don't know what you mean by "generic class" or "your generic functions". I'm also not sure what you mean by ".NET adapter". These are not IVI terminology, so I'm struggling to understand what it is exactly you are trying to do. But, NI-MAX isn't doing anything for you functionally (in this particular IVI scenario) except allowing you to edit the IVI Config Store. Essentially, you can assign a name to a driver session and associate that driver session with an installed IVI-COM driver or IVI-C driver or IVI.NET driver. If the underlying thing you are trying to call is an IVI-COM driver, then you use the IviSessionFactory class. If it's an IVI.NET driver, you use the IviDriver class. If it's an IVI-C driver, you use the NI class drivers. If it's not an IVI-compliant driver at all, then I'm not exactly sure what you are trying to do. Can you clarify?
The Ivi.Driver.dll assembly is registered with Visual Studio, so you can add a reference to it using the standard Visual Studio Add Reference dialog. It is actually located under the IVI Foundation folder -- did you see the "Microsoft.NET" folder under there?
Answer by Kirk Fertitta · Feb 10, 2017 at 03:18 PM
Yes, that's my understanding.
However, you've got a lot of layers in there now and I'm not sure you've achieved anything by doing that. In practice, vendors recognize this limitation of IVI and generally provide both an IVI-COM and IVI-C driver or an IVI.NET and IVI-C driver for a particular instrument. This accommodates customers working in C/C++ as well as .NET.
Answer by Kirk Fertitta · Feb 10, 2017 at 03:41 PM
I know that NI has special step types for IVI drivers. I'd make sure those don't suit your needs before introducing all of those layers.
Answer by Kurt-P · Feb 13, 2017 at 09:57 PM
Hey ToMa,
In TestStand, the IVI Steps are located under the IVI folder in the Insertion Palette. You need to make sure you have the logical name configured in MAX and have it be of the correct class (i.e., you need a DMM driver in order for the Dmm step to find it.) Note that they may not meet your needs exactly depending on what kind of functionality you're trying to get out of your instruments. Refer to the TestStand help for more details.
As a note, these steps are not supported in TestStand 64-bit.
Lastly, if you have TestStand questions, you can post them to the TestStand forums.
-KP
Answer by ToMa · Feb 10, 2017 at 01:59 PM
Yes i want to use the NET-adapter for a generic class. Where can i find the file ivi.driver.dll? (It is not under c:\Program Files\Ivi Foundadtion\
My idea is to call all generic functions in c# and open the logical name from MAX.
I thought i can use any driver in MAX (COM, .Net,...) and MAX is doing everything so that i can simply use my generic functions and dont have to care about driver type. is this not correct?
Answer by ToMa · Feb 10, 2017 at 02:33 PM
I mean that my c# programm only uses generic functions and no specific functions. In the program there should be one open function that gets the logical name.
Then the idea is that i may can have three different powersupplies (one with .Net-driver, next with C-driver and next with COM-driver).
If i install all three drivers then i can select one of them in MAX.
Now the open function and all other generic functions should run.
I thought for this there is the new .Net-adapter and the existing COM-adapter available? This is how my add reference dialog looks like:
https://www.file-upload.net/download-12303243/ref.PNG.html
Answer by ToMa · Feb 10, 2017 at 03:06 PM
OK. When i stay in C++ then this:
viStatus = IviDCPwr_init(logicalname, IdQuery, reset, &vi);
will work for all three drivertypes (if adapters are installed)?
So i could use my c++ dll as a layer and import in c# :-) (If i would have too much time)
Answer by ToMa · Feb 13, 2017 at 08:39 AM
Hi Kirk, how can i access these step-types? currently i can selelect in TestStand the DotNet generic class driver (if not using my extra layer). But in MAX i selected a COM-driver under it.
Which means it is possible to execute COM with DotNet? You wrote that DotNet can only open DotNet, so why can i Dotnet open COM in this case?
Answer by ToMa · Feb 14, 2017 at 02:02 PM
Hi Kurt-P, i know how to select the built-in IVI-steps. But in my case i have a custom C++ wrapper for the IVI generic driver that i want to run in TestStand. The current workaround is to create a second layer in C# to make the handling easier and still have all benefits of the C++ dll under it.
How can i add a Driver Software Modules using NI-MAX ? 3 Answers
C# VTEXScanner Read Result 4 Answers