Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Call to Device() returns null

I have been asked to work on an existing (but not completely functioning) project that includes using a NI GPIB-USB-HS device to control a AC/DC load box.

 

The computer that was being used had to be replaced, so I got everything installed and the project copied over, but now when I run it, I can't connect to the GPIB devices like it used to.

 

I'm trying to figure out why, so I have 2 roads to check:

1) GPIB interface not installed correctly (not a question for this forum)

2) VS 2012 setup / project is not set up correctly.

 

I copied the project from the other computer exactly, but I'm not sure that captures all of the things necessary in order to "hook-up" with the device driver from my project.  I'm very new to this sort of thing, so I apologize for any stupidity on my part.

 

The project has a class defined to encapsuate the load box.  When I try to single step into the constructor function where the project tries to initiate contact with the GPIB device, VS 2012 won't allow me to step into it.

            try
            {
                loadBox1 = new LoadBox(5);
            }
            catch
            {
                does something here;
            }

 The constructor looks like this:

        public LoadBox(byte address)
        {
            //GPIB Address of device
            Address myAddress = new Address(address);

            myLoadBox = new Device(0, myAddress); // NI function
            Load = STATE.OFF;
            Mode = MODE.CC;
            CC_Low = 0.0;
            CC_High = 0.0;
        }

 

 I tried the other computer with no other changes, and I was able to single step into it.  This indicates to me that my project is not able to "connect" with the drivers.  I have the "NationalInstruments.NI4882.dll" included as a reference in my project.

I am able to use the National Instruments utilities to verify that the device is connected and configured exactly how it was on the other computer, so I am pretty sure that I have the drivers installed.

 

Thanks for any help you can provide!

 

Rob

0 Kudos
Message 1 of 7
(4,372 Views)

To verify you have all the drivers installed correctly, you take VS out of the picture and should try using NI-VISA Interactive applet to try to talk to the AC/DC load box.

 

0 Kudos
Message 2 of 7
(4,365 Views)

I am able to "see" both load boxes connected to the GPIB by running the measurement and automation explorer.  I tried running the "Communicate with Device" utility and was able to request its identity,*IDN?, and get a response.  So that tells me the GPIB interface is working and both load boxes are working.  The thing that isn't working is my program, which worked on another computer with the same exact project files.

 

The only difference, it seems, is VS 2012 installation.  I'm NOT an expert using VS, so I don't know what kinds of settings are external to a project that could be causing this.

 

Any ideas are welcomed!

 

Regards,

 

Rob

0 Kudos
Message 3 of 7
(4,349 Views)

You should be able to find some examples at   C:\Users\Public\Documents\National Instruments\NI-VISA\Examples     (Windows 7) to communicate with the AC/DC box using NI-VISA

 

However, it looks like from the code snippet, they are using NI-488.2 to communicate with the AC/DC box so the examples would be at   C:\Users\Public\Documents\National Instruments\NI-488.2\Examples

 

For NI-488.2, you need to add reference to both NI4882.dll and Common.dll

 

 

0 Kudos
Message 4 of 7
(4,346 Views)

I have gotten a bit further than I was this morning, but still not working.

 

It seems that when my program tries to load a .dll that references NationalInstruments.NI4882.dll an exception is thrown:

 

System.IO.FileNotFoundException: Could not load file or assembly 'NationalInstruments.Common, Version=9.0.40.362, Culture=neutral, PublicKeyToken=dc6ad606294fc298' or one of its dependencies. The system cannot find the file specified.

 

Using another utility, I found that the NationalIstruments.NI4882.dll is dependent on GPSVC.DLL and IESHIMS.DLL which cannot be found.

 

Neither of these .dll files seems to be relevant to what I'm trying to do, but the NI .dll is dependent on them for some reason or other.

0 Kudos
Message 5 of 7
(4,335 Views)

Have you tried directly loading the DLLs?

For my computer with VB 2010 Express, the DLLs are located in C:\Program Files\National Instruments\MeasurementStudioVS2010\DotNET\Assemblies\Current

 

Also, does the NI-488.2 version you have support Visual Studio 2012?  3.1 is the latest version

 

 

0 Kudos
Message 6 of 7
(4,333 Views)

I figured out the problem with a lot of help from one of our Visual Studio gurus.

 

It turns out that the NI dll files that were contained in and referenced by our solution were not the ones actually being included in the build on the computer where it had worked.

 

I guess there is something called the GAC, Global Assembly Cache, where these dll files get registered when they are installed.  When I installed the drivers on the new computer, I didn't install the .NET portions, because we already had the files we needed in our project.  By skipping that step, I prevented the necessary files and the means for the operating system to find them to be setup by the installation.

 

Thanks for your help nyc.  Even if you didn't give me an the final answer, you gave me some things to think about and build on.

 

Rob

0 Kudos
Message 7 of 7
(4,322 Views)