Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect if DAQmx drivers installed before GetPhysicalChannels in C#?

Dear All,

There is an C# application in my laboratory to use DAQmx cards for data acquisition. This C# application works normally if DAQmx drivers have been installed already. Unfortunately, the SDD in my notebook was replaced because the old one failed last week. I run this C# application and it quit unexpectedly always. Oh! I forgot to install DAQmx drivers. After installing "NIDAQ1860f2Runtime" downloaded from http://www.ni.com/zh-tw/support/downloads/drivers/download.ni-daqmx.html#291872, it works normally. In order to avoid this C# application keeping crash if DAQmx drivers are NOT installed, I would like to add one or more commands in this C# application to check its prerequisite, i.e. DAQmx drivers installation. Is there any good idea to be added before the command "object obj = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External);"?

OS: WIndows 10 Professional, C#: Visual Studio 2017 version 15.9.10

Both NationalInstruments.Common and NationalInstruments.DAQmx have been included in the reference of this application already. Also NationalInstruments.MStudioCLM.dll and NationalInstruments.NiLmClientDLL.dll are found in the folder "bin\Debug."

0 Kudos
Message 1 of 4
(2,485 Views)

Hi TonyKUO,

Is there any error message when you run without install DAQmx drivers? If got prompt any error message instead of just crash, you can choose to modify the error message by putting your code in the try-catch block. If no, then maybe you have to always make sure that you have install the drivers that need.

Here are some link for your reference:
https://www.halvorsen.blog/documents/programming/csharp/csharp.php
https://www.halvorsen.blog/documents/tutorials/resources/Data%20Acquisition%20in%20CSharp.pdf
http://zone.ni.com/reference/en-XX/help/370473J-01/ninetdaqmxfx40/netdaqmxexamples/

Hope this will help.

0 Kudos
Message 2 of 4
(2,449 Views)

The follows are the codes:

try
{
    object obj = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI,

                        PhysicalChannelAccess.External);
    string[] physicalChannelName = obj as string[];

    foreach (var eachphysicalChannel in physicalChannelName)
    {
        lsbPhysicalChannel.Items.Add(eachphysicalChannel);
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "DAQ Not Available");
}

 

However, this program return the following error:

System.IO.FileNotFoundException

  HResult=0x8007007E

  Message=無法載入檔案或組件 'NationalInstruments.DAQmx.dll' 或其相依性的其中之一。 找不到指定的模組。

It means the NationalInstruments.DAQmx.dll could NOT be found.

This DLL is included as reference before complied by a computer with DAQ drivers. It works on a notebook and desktop if DAQ drivers had been installed on them. But it failed on a computer without DAQ drivers. After installation of DAQ drivers, this computer works normally.

0 Kudos
Message 3 of 4
(2,423 Views)