beautypg.com

Daqdevicemanager.createdevice(), Createdevice() – Measurement Computing DAQFlex User Guide User Manual

Page 25

background image

DAQFlex Software User's Guide

DAQFlex Software Reference

25

If using a device that does not have an ID assigned, you must use the

NameOnly

or

NameAndSerno

format with the DaqDeviceManager.CreateDevice() method in order to create the device. A device

with no ID will not be created when using the

NameAndID

and

NameSernoAndID

format with

CreateDevice().

DaqDeviceManager.CreateDevice()

Creates a DaqDevice object. The DaqDevice object contains the methods used to configure, read data

from, or write data to a device. With the DaqDevice object, all DAQ operations are configured using one
API method called

DaqDevice.SendMessage()

rather than using multiple operation-specific methods.

SendMessage() takes a single parameter called message. This parameter is a text-based command that

the DAQ device parses to configure a particular operation.

C#:

static CreateDevice(string deviceName);

VB:

Shared Function CreateDevice(ByVal deviceName As String) As DaqDevice

Parameter

deviceName

One of the device names returned by the DaqDeviceManager.GetDevicenames() method.

Return value

An instance of a

DaqDevice object

.

Remarks

Depending on the DeviceNameFormat, the CreateDevice() method creates a DaqDevice object for

the device whose name, name and serial number, name and id, or name, serial number and id are

contained in the deviceName parameter.

The resources associated with the DaqDevice object can be freed by calling the

ReleaseDevice()

method.

The CreateDevice() method can only be called once for a specific device, unless the ReleaseDevice()

method is called.

If CreateDevice() is called more than once for a specific device without calling ReleaseDevice(), the

DaqDevice object

throws an exception

, indicating that a driver handle has already been created for

the device.

Refer to the following sample code:

C#

try
{

MyDevice = DaqDeviceManager.CreateDevice(deviceName);

}

catch (Exception ex)

{

// handle exception
}

VB

Try

MyDevice = DaqDeviceManager.CreateDevice(deviceName)

Catch Ex As Exception

' handle exception

End Try