From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx.Device issues

Hi,

 

I am able to use  DaqSystem.Local.Devices to get a string array of installed DAQmx devices.  What I want to do is use Device.DeviceID to just get one device in a string since I know there will only be one device hooked up in my test system.

 

The problem is that even if I instantiate the device Class : 

 

Device xDevice = new Device();
string yDevice = xDevice.DeviceID;

 

Although the instantiation gives me access to methods and properties, the compiler complains there are no constructors and I can't figure out via the object browser what constructor(s) I'm supposed to use to get this to compile and run.

 

 

Thanks,

 

synchron.

 

 

0 Kudos
Message 1 of 5
(5,295 Views)

Hi synchron,

 

There are two options that you can explorer. Please see below.

 

// Option 1: if you don't know the device name

 string[] devices = DaqSystem.Local.Devices; string device;

device = devices[0];

Device xDevice = DaqSystem.Local.LoadDevice(device);

 

// Option 2: if you already know the device name

Device xDevice = DaqSystem.Local.LoadDevice("deviceName");

 

Please make sure to do the required error-handling, like making sure that in Option 1, you do have a minimum of 1 device, otherwise device = devices[0]; will thrown an exception.

 

Also, the only way to create a Device object is using the DaqSystem.Local.LoadDevice() method.

 

Please let us know if you need any more help.

0 Kudos
Message 2 of 5
(5,278 Views)

Hi Canisius,

 

Yes, your Option 1 is my situation and I coded it like that exactly for now, temporarily.  The error checking is by looking at the length of the array and if it's not 1, flag the error (No DAQs found or more than 1 found).  My system is duplicated 6 times and are designed to be hot-swappable so this means that TestStation 1 may have, say, a Dev5 and when swapped with TestStation5 it may have, say,  a Dev2 based on when it was seen the 1st time on the PC.

 

But my original question is how to use the Device class correctly (in C# .NET) with the right constructor so I can eventually get the device name via DeviceID  (I may  need access to SerialNumber later on).  There's tons of methods/properties associated with the Device class that look better to use than the DaqSystem class.

 

Synchron.

0 Kudos
Message 3 of 5
(5,272 Views)

Hi,

 

I might not have been very clear in my last post. There is no constructor for the Device class, the only way for you to create a Device object is using the DaqSystem.Local.LoadDevice() method, which takes a device name. Therefore you need to know the device name to create a Device object. You can find the help on this class in the NI Measurement Studio Help under NI Measurement Studio .NET Class Library >> Reference >> NationalInstruments.DAQmx >> Device Class. Once you have this Device object, you can retrieve any device specific information. Please look at the code below for an example.

 

From Option 1

 

string[] devices = DaqSystem.Local.Devices; 

string device = devices[0];

Device xDevice = DaqSystem.Local.LoadDevice(device);

long serialNumber = xDevice.SerialNumber;

 

Hope this is clear. 

 

Thanks,

Canisius

Message 4 of 5
(5,263 Views)

Yes, thanks for making it clearer.  This answers my original question.

 

Synchron.

 

 

0 Kudos
Message 5 of 5
(5,255 Views)