Measurement DAQFlex User Manual

Document Revision 9 November 2013 © Copyright 2013
DAQFlex
SM DAQFlex_Software.docx
Your new Measurement Computing product comes with a fantastic extra
Management committed to your satisfaction!
Thank you for choosing a Measurement Computing productand congratulations! You own the finest, and you can now enjoy the protection of the most comprehensive warranties and unmatched phone tech support. It’s the embodiment of our mission:
To provide data acquisition hardware and software that will save time and save money.
Simple installations minimize the time between setting up your system and actually making measurements. We offer quick and simple access to outstanding live FREE technical support to help integrate MCC products into a DAQ system.
Limited Lifetime Warranty: Most MCC products are covered by a limited lifetime warranty against defects in materials or workmanship for the life of the product, to the original purchaser, unless otherwise noted. Any products found to be defective in material or workmanship will be repaired, replaced with same or similar device, or refunded at MCC’s discretion. For specific information, please refer to the terms and conditions of sale.
Harsh Environment Program: Any Measurement Computing product that is damaged due to misuse, or any reason, may be eligible for replacement with the same or similar device for 50% of the current list price. I/O boards face some harsh environments, some harsher than the boards are designed to withstand. Contact MCC to determine your product’s eligibility for this program.
30 Day Money-Back Guarantee: Any Measurement Computing Corporation product may be returned within 30 days of purchase for a full refund of the price paid for the product being returned. If you are not satisfied, or chose the wrong product by mistake, you do not have to keep it.
These warranties are in lieu of all other warranties, expressed or implied, including any implied warranty of merchantability or fitness for a particular application. The remedies provided herein are the buyer’s sole and exclusive remedies. Neither Measurement Computing Corporation, nor its employees shall be liable for any direct or indirect, special, incidental or consequential damage arising from the use of its products, even if Measurement Computing Corporation has been notified in advance of the possibility of such damages.
Trademark and Copyright Information
Measurement Computing Corporation, InstaCal, Universal Library, and the Measurement Computing logo are either trademarks or registered trademarks of Measurement Computing Corporation. Refer to the Copyrights & Trademarks section on
mccdaq.com/legal for more information about Measurement Computing trademarks. Other product and company names
mentioned herein are trademarks or trade names of their respective companies. © 2013 Measurement Computing Corporation. All rights reserved. No part of this publication may be reproduced, stored in a
retrieval system, or transmitted, in any form by any means, electronic, mechanical, by photocopying, recording, or otherwise without the prior written permission of Measurement Computing Corporation.
Notice
Measurement Computing Corporation does not authorize any Measurement Computing Corporation product for use in life support systems and/or devices without prior written consent from Measurement Computing Corporation. Life support devices/systems are devices or systems that, a) are intended for surgical implantation into the body, or b) support or sustain life and whose failure to perform can be reasonably expected to result in injury. Measurement Computing Corporation products are not designed with the components required, and are not subject to the testing required to ensure a level of reliability suitable for the treatment and diagnosis of people.
Table of Contents
Preface
About this User's Guide ....................................................................................................................... 5
What you will learn from this user's guide ............................................................................................ 5
Conventions in this user's guide ......................................................................................................... 5
Where to find more information .......................................................................................................... 5
Chapter 1
Introducing DAQFlex Software ............................................................................................................ 6
Platform support ............................................................................................................................... 6
Hardware requirements ..................................................................................................................... 7
Installing the DAQFlex software library ................................................................................................ 7
Windows 8, Windows 7, Windows Vista, and Windows XP .................................................................... 7
Windows CE .................................................................................................................................. 8
Mac OS X ...................................................................................................................................... 8
Linux ............................................................................................................................................ 8
Chapter 2
Using DAQFlex Software ...................................................................................................................... 9
Reading and writing software-paced I/O ............................................................................................ 11
Reading an analog input channel.................................................................................................... 12
Writing to an analog output channel ............................................................................................... 13
Reading a digital bit ..................................................................................................................... 14
Writing to a digital bit ................................................................................................................... 15
Reading a digital port ................................................................................................................... 16
Writing to a digital port ................................................................................................................. 17
Reading a counter input channel .................................................................................................... 18
Reading hardware-paced I/O ............................................................................................................ 19
ReadScanData() parameters ......................................................................................................... 20
Internal buffer ............................................................................................................................. 20
CallbackType ............................................................................................................................... 20
Writing hardware-paced I/O ............................................................................................................. 22
WriteScanData() parameters ......................................................................................................... 23
Internal buffer ............................................................................................................................. 23
Chapter 3
DAQFlex Software Reference ............................................................................................................ 24
DaqDeviceManager class ................................................................................................................. 24
DaqDeviceManager.GetDeviceNames() ........................................................................................... 24
DaqDeviceManager.CreateDevice() ................................................................................................ 25
DaqDeviceManager.ReleaseDevice() ............................................................................................... 26
DaqDevice class ............................................................................................................................. 26
DaqDevice.SendMessage() ............................................................................................................ 26
DaqDevice.ReadScanData() ........................................................................................................... 27
DaqDevice.WriteScanData() .......................................................................................................... 28
DaqDevice.EnableCallback() .......................................................................................................... 28
InputScanCallback Delegate .......................................................................................................... 29
DaqDevice.DisableCallback() ......................................................................................................... 29
DaqDevice.GetErrorMessage() ....................................................................................................... 29
DaqDevice.GetSupportedMessages() .............................................................................................. 30
Chapter 4
DAQFlex Message Reference ............................................................................................................ 31
DAQFlex components ...................................................................................................................... 31
Programming messages................................................................................................................... 32
AI .............................................................................................................................................. 32
3
DAQFlex Software User's Guide
AICAL ......................................................................................................................................... 39
AIQUEUE .................................................................................................................................... 39
AISCAN ...................................................................................................................................... 42
AITRIG ....................................................................................................................................... 50
AO ............................................................................................................................................. 52
AOCAL ........................................................................................................................................ 55
AOSCAN ..................................................................................................................................... 55
AOTRIG ...................................................................................................................................... 60
CTR ............................................................................................................................................ 60
DEV ........................................................................................................................................... 61
DIO ............................................................................................................................................ 65
TMR ........................................................................................................................................... 68
Reflection messages ........................................................................................................................ 72
AI .............................................................................................................................................. 72
AISCAN ...................................................................................................................................... 76
AITRIG ....................................................................................................................................... 80
AO ............................................................................................................................................. 81
AOSCAN ..................................................................................................................................... 83
CTR ............................................................................................................................................ 86
DIO ............................................................................................................................................ 88
TMR ........................................................................................................................................... 89
Chapter 5
FlexTest Utility ..................................................................................................................................... 92
FlexTest user interface .................................................................................................................... 93
Messagelog window ...................................................................................................................... 93
Using FlexTest ................................................................................................................................ 93
Read and display scan data ........................................................................................................... 93
Calibrate a device ........................................................................................................................ 94
DAQFlex message reference ............................................................................................................. 95
Chapter 6
C# and VB Example Programs .......................................................................................................... 96
Default installation path ................................................................................................................ 96
Building the DAQFlex example programs ......................................................................................... 96
Chapter 7
Hardware Reference ........................................................................................................................... 98
USB-200 Series .............................................................................................................................. 99
USB-1208FS-Plus ......................................................................................................................... 102
USB-1408FS-Plus ......................................................................................................................... 105
USB-1608FS-Plus ......................................................................................................................... 108
USB-1608G Series ........................................................................................................................ 111
USB-2001-TC ............................................................................................................................... 115
USB-2408 Series .......................................................................................................................... 116
USB-7202 .................................................................................................................................... 120
USB-7204 .................................................................................................................................... 122
4

Preface

About this User's Guide

What you will learn from this user's guide

This user's guide explains how to install, configure, and use the DAQFlex Framework communication protocol.

Conventions in this user's guide

For more information
Text presented in a box signifies additional information and helpful hints related to the subject matter you are reading.
Caution! Shaded caution statements present information to help you avoid injuring yourself and others,
damaging your hardware, or losing your data.
bold text Bold text is used for the names of objects on the screen, such as buttons, text boxes, and check boxes.
italic text Italic text is used for the names of manuals and help topic titles, and to emphasize a word or phrase.

Where to find more information

Additional information about DAQFlex software is available on our website at www.mccdaq.com. You can also contact Measurement Computing Corporation with specific questions.
Knowledgebase: kb.mccdaq.com Phone: 508-946-5100 and follow the instructions for reaching Tech Support Fax: 508-946-9500 to the attention of Tech Support Email: techsupport@mccdaq.com
5
Chapter 1

Introducing DAQFlex Software

DAQFlex is a framework that combines a small footprint driver with a message-based command protocol. It is used to develop data acquisition applications that can be deployed across multiple operating systems and custom embedded systems. The DAQFlex protocol greatly simplifies driver and application development. All DAQ operations are programmed through a common command interface composed of a cross-platform application programming interface (API) and open-source driver.
The DAQFlex framework consists of a software API, DAQFlex device driver, and the DAQ device message engine. The message engine parses and converts the DAQFlex message-based command set into DAQ-specific commands that control the device and process data.
Figure 1. DAQFlex Framework
A DAQFlex program sends DAQFlex methods to the driver. The driver sends the encapsulated messages to the data acquisition device. The device interprets the message using the message engine, and sets its corresponding attributes using the DAQ engine. The data acquisition device then returns the requested data to the DAQFlex driver, which returns the data in an array (ScanData) to the program.
DAQFlex software includes the software API, device driver, FlexTest utility, and example programs.
Platform Support and Hardware Requirements Installing the DAQFlex Software Library Using DAQFlex Software DAQFlex Software Reference DAQFlex Message Reference FlexTest Utility C# and VB .NET Example programs DAQFlex Hardware Reference

Platform support

You can run the DAQFlex communication protocol on a computer running one of the following operating systems and software:
Microsoft Windows (32-bit or 64-bit)
o Windows 8 o Windows 7 o Windows Vista o Windows XP o Microsoft .NET® Framework 2.0 or later
6
DAQFlex Software User's Guide Introducing DAQFlex Software
Microsoft Windows CE
Development requirements:
o Microsoft Windows XP/Vista operating system o Microsoft Visual Studio 2008 or later o Microsoft .NET Compact Framework 3.5 o Microsoft ActiveSync
Deployment requirements:
o Windows CE 5.0 o X86 or ARM CPU o Microsoft .NET Compact Framework 3.5 o DaqFlex.dll o Mcusb.dll o Mcwinceusb.dll
Macintosh (32-bit or 64-bit)
o MAC OS X o Leopard 10.5 or later o Mono Framework 2.0 or later o libusb user-mode driver version 1.0.0.0
Linux (32-bit or 64-bit)
o Linux (2.4 kernel or later) o Mono Framework 2.0 or later o libusb user-mode driver version 1.0.0.0

Hardware requirements

Intel Pentium 4, 1 GHz or higher Minimum of 512 MG of RAM (1 GB or higher recommended) Video card with 128 MB memory Video display with 800 x 600 resolution or greater, and 256 colors or greater Microsoft-compatible mouse

Installing the DAQFlex software library

DAQFlex software operates with standard drivers for Windows, Mac, and Linux. Follow the procedure below specific to your operating system to install the DAQFlex software.

Windows 8, Windows 7, Windows Vista, and Windows XP

1. Go to the DAQFlex download page at www.mccdaq.com/DAQFlexDL and select the Windows 32/64-
bit option.
2. Run the Windows DAQFlex.exe installer file.
3. Follow the installer instructions.
Connect your DAQFlex device after installing the software. You can run the FlexTest.exe test application,
or build and run the C# or VB .NET example programs included in the installation using ExampleBuilder or Visual Studio (version 2005 or later).
Refer to the C# and VB Example Programs chapter on page 96 for instructions on running the DAQFlex example programs, and to the Hardware Reference chapter on page 98 for the API components and messages supported by DAQFlex supported hardware.
7
DAQFlex Software User's Guide Introducing DAQFlex Software

Windows CE

1. Go to the DAQFlex download page at www.mccdaq.com/DAQFlexDL and select the Windows CE
option.
2. Run the DAQFlex for Windows CE.msi installer file.
3. Follow the installer instructions.
4. After the DAQFlex software is installed, copy the Windows CE device drivers (mccusb.dll and
mccwinceusb.dll) from the DAQFlex for Windows CE\Drivers\ directory (\X86 or \XScale
folder) to the device's Windows directory.
Connect your DAQFlex device after installing the software. You can run the FlexTest.exe, or build and
run the C# or VB .NET example programs included in the installation using Visual Studio (version 2008 or later).
Refer to the C# and VB Example Programs chapter on page 96 for instructions on running the DAQFlex example programs, and to the Hardware Reference chapter on page 98 for the API components and messages supported by DAQFlex supported hardware.

Mac OS X

1. Go to the DAQFlex download page at www.mccdaq.com/DAQFlexDL and select the Mac OS option.
2. Run the DAQFlex installer package (DAQFlex.pkg).
3. Follow the installer instructions.
Connect your DAQFlex device after installing the software. You can run the FlexTest application located in the /Applications/Measurement Computing/DAQFlex folder. Additionally, you can build and run the example programs included in the installation using ExampleBuilder.
Refer to the C# and VB Example Programs chapter on page 96 for instructions on running the DAQFlex example programs, and to the Hardware Reference chapter on page 98 for the API components and messages supported by DAQFlex supported hardware.

Linux

1. Using your Software/Package manager, verify that the Mono framework (version 2.4 or later) and
the libusb user-mode driver are installed on your Linux system.
If these versions aren't listed, information on installing, updating, or adding software repositories to your Software/Package manager can be found at the following links. Click here to go to the Mono web site. Click here to go to the libusb web site.
2. As a root user, create a symbolic link to the libusb-1.0 shared object file. For example:
o ln -s /usr/lib/libusb-1.0.so.0/usr/lib/libusb-1.0.so
The actual file location may vary.
3. Extract the files from the DAQFlex-2.0.tar.gz archive file on the DAQFlex software CD using an
archive manager.
4. In a terminal window, set the current directory to DAQFlex/Source/DAQFlexAPI.
5. As a root user, run the following commands:
o make o make install
6. Restart the system.
Connect your DAQFlex device after installing the software. You can run the FlexTest application by running the command $ flextest from a terminal window. Additionally, you can build and run the C# example programs included in the installation using MonoDevelop or the Mono command line interpreter.
Refer to the C# and VB Example Programs chapter on page 96 for instructions on running the DAQFlex example programs, and to the Hardware Reference chapter on page 98 for the API components and messages supported by DAQFlex supported hardware.
8
string[] deviceNames;
deviceNames = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
Dim deviceNames As String()
deviceNames = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
Member Name
Description
NameOnly
The returned values contain only the device name.
NameAndSerno
The return values contain the device name with the device serial number formatted as "DeviceName::SerialNumber".
NameAndID
The return values contains the device name with the device's user-defined ID formatted as "DeviceName::DeviceID".
NameSernoAndID
The return values contains the device name, the device serial number and the device's user-defined ID formatted as "DeviceName::SerialNumber::DeviceID".
int deviceNumber = 0;
DaqDevice device;
string deviceName = deviceNames[deviceNumber];
device = DaqDeviceManager.CreateDevice(deviceName);
Chapter 2

Using DAQFlex Software

The following procedure describes how to program a DAQFlex-supported device with DAQFlex software.
1. Add a reference to the DAQFlex assembly to your project.
o In Visual Studio and MonoDevelop, this assembly is listed under the .NET tab of the Add
Reference dialog as DAQFlex API. If your project is a C# project, add the following statement to your source file:
using MeasurementComputing.DAQFlex;
2. Get a list of device names using the static method GetDeviceNames():
C#
VB
GetDeviceNames gets the names of DAQFlex devices detected by the DAQFlex API. DeviceNameFormat
is an enumeration that specifies the format of the returned values. This enumeration defines four different formats:
Note: Each DAQFlex API method will throw an exception if an error occurs, and should be enclosed
within a Try/Catch block.
3. Get a device object using the static method CreateDevice():
C#
9
DAQFlex Software User's Guide Using DAQFlex Software
Dim deviceNumber As Integer
Dim device As DaqDevice
Dim deviceName As String
deviceNumber = 0
deviceName = deviceNames(deviceNumber)
device = DaqDeviceManager.CreateDevice(deviceName)
DaqResponse response; response = device.SendMessage("AI{0}:RANGE=BIP10V"); // set the input range for channel 0 response = device.SendMessage("?AI{0}:VALUE"); // read a single value from channel 0
Dim response As DaqResponse response = device.SendMessage("AI{0}:RANGE=BIP10V") ' set the input range for channel 0 response = device.SendMessage("?AI{0}:VALUE") ' read a single value from channel 0
string value = response.ToString();
Dim value As String
value = response.ToString()
double value = response.ToValue();
Dim value As Double value = response.ToValue()
DaqDeviceManager.ReleaseDevice(device);
DaqDeviceManager.ReleaseDevice(device)
VB
4. Once you have a DaqDevice object, use the SendMessage() method to program your DAQFlex-
supported device.
C#
VB
The DaqResponse object contains a method for getting the response as a string and a method for
getting the response as a numeric.
To get the response as a string, use the ToString() method:
C#
VB
To get the response as a numeric, use the ToValue() method:
C#
VB
If the response does not contain a numeric value, ToValue() returns Double.NaN.
When you no longer need the DaqDevice object, you can release it by calling the ReleaseDevice() method:
C#
VB
10
DAQFlex Software User's Guide Using DAQFlex Software

Reading and writing software-paced I/O

The following examples demonstrate how to perform asynchronous single-point I/O using DAQFlex software:
Reading an analog input channel Writing to an analog output channel Reading a digital bit Writing to a digital bit Reading a digital port Writing to a digital port Reading a counter input channel
11
DAQFlex Software User's Guide Using DAQFlex Software
// Read the value of analog input channel 0 String[] Devices; DaqDevice MyDevice; DaqResponse Response;
try {
// Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
// Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices[0]);
// Send device messages using the DaqDevice object MyDevice.SendMessage("AI{0}:RANGE=BIP10V"); MyDevice.SendMessage("AI:CAL=ENABLE"); MyDevice.SendMessage("AI:SCALE=ENABLE");
// Read and display the daq response Response = MyDevice.SendMessage("?AI{0}:VALUE"); label1.Text = Response.ToString();
} catch (Exception ex) {
// handle error label1.Text = ex.Message;
}
' Read the value of analog input channel 0 Dim Devices As String () Dim MyDevice As DaqDevice Dim Response As DaqResponse
Try
' Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
' Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0))
' Send device messages using the DaqDevice object MyDevice.SendMessage("AI{0}:RANGE=BIP10V") MyDevice.SendMessage("AI:CAL=ENABLE") MyDevice.SendMessage("AI:SCALE=ENABLE")
' Read and display the daq response Response = MyDevice.SendMessage("?AI{0}:VALUE") Label1.Text = Response.ToString()
Catch Ex As Exception
' handle error Label1.Text = Ex.Message()
End Try

Reading an analog input channel

C#
VB
12
DAQFlex Software User's Guide Using DAQFlex Software
// Write a value to analog output channel 0 String[] Devices; DaqDevice MyDevice;
try {
// Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
// Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices[0]);
// Send device messages MyDevice.SendMessage("AO{0}:RANGE=BIP10V"); MyDevice.SendMessage("AO:CAL=ENABLE"); MyDevice.SendMessage("AO:SCALE=ENABLE"); MyDevice.SendMessage("AO{0}:VALUE=2.53");
} catch (Exception ex) {
// handle error label1.Text = ex.Message;
}
' Write a value to analog output channel 0 Dim Devices As String() Dim MyDevice As DaqDevice
Try
' Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
' Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0))
' Send device messages MyDevice.SendMessage("AO{0}:RANGE=BIP10V") MyDevice.SendMessage("AO:CAL=ENABLE") MyDevice.SendMessage("AO:SCALE=ENABLE") MyDevice.SendMessage("AO{0}:VALUE=2.53")
Catch Ex As Exception
' handle error Label1.Text = Ex.Message
End Try

Writing to an analog output channel

C#
VB
13
DAQFlex Software User's Guide Using DAQFlex Software
// Read the value of digital port 0, bit 0 String[] Devices; DaqDevice MyDevice; DaqResponse Response;
try {
// Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
// Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices[0]);
// Read and display the daq response MyDevice.SendMessage("DIO{0/0}:DIR=IN"); Response = MyDevice.SendMessage("?DIO{0/0}:VALUE"); label1.Text = Response.ToString();
} catch (Exception ex) {
// handle error label1.Text = ex.Message;
}
' Read the value of digital port 0, bit 0 Dim MyDevice As DaqDevice Dim Response As DaqResponse Dim Devices As String ()
Try
' Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
' Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0))
' Read and display the daq response MyDevice.SendMessage("DIO{0/0}:DIR=IN") Response = MyDevice.SendMessage("?DIO{0/0}:VALUE") Label1.Text = Response.ToString()
Catch Ex As Exception
' handle error Label1.Text = Ex.Message
End Try

Reading a digital bit

C#
VB
14
DAQFlex Software User's Guide Using DAQFlex Software
// Write a value to digital port 0, bit 0 String[] Devices; DaqDevice MyDevice; DaqResponse Response;
try {
// Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
// Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices[0]);
// Send device messages MyDevice.SendMessage("DIO{0/0}:DIR= MyDevice.SendMessage("DIO{0/0}:VALUE= label1.Text = response.ToString();
} catch (Exception ex) }
// handle error label1.Text = ex.Message;
}
' Write a value to digital port 0, bit 0 Dim MyDevice As DaqDevice Dim Response As DaqResponse Dim Devices As String ()
Try
' Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
' Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0))
' Send device messages MyDevice.SendMessage("DIO{0/0}:DIR= Response = MyDevice.SendMessage("DIO{0/0}:VALUE= Label1.Text = Response.ToString
Catch Ex As Exception
' handle error Label1.Text = Ex.Message
End Try

Writing to a digital bit

C#
VB
15
DAQFlex Software User's Guide Using DAQFlex Software
// Read the value of digital port 0 String[] Devices; DaqDevice MyDevice; DaqResponse Response;
try {
// Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
// Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices[0]);
// Send device messages MyDevice.SendMessage("DIO{0}:DIR=IN");
// Read and display the daq response Response = MyDevice.SendMessage("?DIO{0}:VALUE"); Label1.Text = Response.ToString();
} catch (Exception ex) {
// handle error label1.Text = ex.Message;
}
' Read the value of digital port 0 Dim MyDevice As DaqDevice Dim Response As DaqResponse Dim Devices As String ()
Try
' Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
' Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0))
' Send device messages MyDevice.SendMessage("DIO{0}:DIR=IN")
' Read and display the daq response Response = MyDevice.SendMessage("?DIO{0}:VALUE") Label1.Text = Response.ToString()
Catch Ex As Exception
' handle error Label1.Text = Ex.Message
End Try

Reading a digital port

C#
VB
16
DAQFlex Software User's Guide Using DAQFlex Software
// Write a value to digital port 0 String[] Devices; DaqDevice MyDevice; DaqResponse Response;
try {
// Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
// Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices[0]);
// Send device messages MyDevice.SendMessage("DIO{0}:DIR=OUT"); MyDevice.SendMessage("DIO{0}:VALUE=128"); label1.Text = response.ToString();
} catch (Exception ex) }
// handle error label1.Text = ex.Message;
}
' Write a value to digital port 0 Dim MyDevice As DaqDevice Dim Response As DaqResponse Dim Devices As String ()
Try
' Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
' Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0))
' Send device messages MyDevice.SendMessage("DIO{0}:DIR=OUT") Response = MyDevice.SendMessage("DIO{0}:VALUE=128") Label1.Text = Response.ToString
Catch Ex As Exception
' handle error Label1.Text = Ex.Message
End Try

Writing to a digital port

C#
VB
17
DAQFlex Software User's Guide Using DAQFlex Software
// Read counter channel 0 String[] Devices; DaqDevice MyDevice; DaqResponse Response;
try {
// Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno);
// Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0));
// Start the counter MyDevice.SendMessage("CTR{0}:VALUE=0"); MyDevice.SendMessage("CTR{0}:START");
// Read and display the daq response for(int i = 1;i<=10;i++) {
System.Threading.Thread.Sleep(750); Response = MyDevice.SendMessage("?CTR{0}:VALUE"); label1.Text = Response.ToString(); Application.DoEvents();
}
// Stop the counter MyDevice.SendMessage("CTR{0}:STOP");
} catch (Exception ex) {
// handle error label1.Text = ex.Message;
}
' Read counter channel 0 Dim MyDevice As DaqDevice Dim Response As DaqResponse Dim Devices As String ()
Try
' Get a list of message-based DAQ devices Devices = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno)
' Get a DaqDevice object for device 0 MyDevice = DaqDeviceManager.CreateDevice(Devices(0))
Dim I As Integer
' Start the counter MyDevice.SendMessage("CTR{0}:VALUE=0") MyDevice.SendMessage("CTR{0}:START")
' Read and display the daq response For I = 1 To 10
System.Threading.Thread.Sleep(750) Response = MyDevice.SendMessage("?CTR{0}:VALUE") Label1.Text = Response.ToString() Application.DoEvents()
Next

Reading a counter input channel

C#
VB
18
DAQFlex Software User's Guide Using DAQFlex Software
' Stop the counter MyDevice.SendMessage("CTR{0}:STOP")
Catch Ex As Exception
' handle error Label1.Text = Ex.Message
End Try
try {
double[,] scanData; string[] names = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno); DaqDevice device = DaqDeviceManager.CreateDevice(names[0]);
device.SendMessage("AISCAN:LOWCHAN=0"); device.SendMessage("AISCAN:HIGHCHAN=0"); device.SendMessage("AISCAN:RATE=1000"); device.SendMessage("AISCAN:SAMPLES=5000"); device.SendMessage("AISCAN:START");
scanData = device.ReadScanData(5000, 0);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
Try
Dim ScanData As Double(,) Dim Names As String() Dim Device As DaqDevice
Names = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno) Device = DaqDeviceManager.CreateDevice(Names(0))
Device.SendMessage("AISCAN:LOWCHAN=0") Device.SendMessage("AISCAN:HIGHCHAN=0") Device.SendMessage("AISCAN:RATE=1000") Device.SendMessage("AISCAN:SAMPLES=5000") Device.SendMessage("AISCAN:START")
ScanData = Device.ReadScanData(5000, 0)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

Reading hardware-paced I/O

The basic approach to programming analog input scans is to set the device's scan properties, send the
START command, and call the ReadScanData() method. The following examples show how to program a
basic input scan.
C#
VB
19
DAQFlex Software User's Guide Using DAQFlex Software
Device.EnableCallback(callbackMethod, callbackType, callbackCount);
Device.EnableCallback(Addressof CallbackMethod, CallbackType, CallbackCount)
void CallbackMethod(ErrorCodes errorCode, CallbackType callbackType, object callbackData)
Sub CallbackMethod(ByVal errorCode As ErrorCodes, ByVal callbackType As CallbackType, _ ByVal callbackData As Object)
Member Name
Description
OnDataAvailable
Specifies that the callback method will be invoked when a specified number of samples becomes available for reading.
OnInputScanComplete
Specifies that the callback method will be invoked when a finite scan has complete or when a continuous scan is stopped.
OnInputScanError
Specifies that the callback method will be invoked when an input scan error occurs.

ReadScanData() parameters

The first parameter to the ReadScanData method is the number of samples to read. The second parameter is a time out value in milli-seconds. A value of 0 indicates no timeout
specified.
The ReadScanData method is synchronous, and will return when the number of requested samples are available for reading. When the number of requested samples are available, the DAQFlex software copies the requested number of samples from an internal buffer to a new array of data. The DAQFlex software keeps track of the buffer index so that multiple calls to ReadScanData always return contiguous data.

Internal buffer

An alternative method for reading scan data is to enable a user-defined callback method. When you enable a callback method, the DAQFlex software invokes your user-defined method when a specified number of samples are available for reading, when a scan completes, or if a scan error occurs. This is done using the EnableCallback method as shown below:
C#
VB
The callbackMethod is the name of the method that will be invoked by the DAQFlex software. The callbackMethod is a class method that must have the following form:
C#
VB
The callbackType is an enumeration that defines when the callback method will be invoked.

CallbackType

Only one callback method can be specified for each callback type. When the callback type is set to OnDataAvailable, set the callbackData parameter to the number of samples you wish to receive in the callback method. When the callback type is set to OnInputScanComplete or OnInputScanError, set the callbackData parameter to null or Nothing.
20
DAQFlex Software User's Guide Using DAQFlex Software
try {
double[,] scanData;
string[] names = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno); DaqDevice device = DaqDeviceManager.CreateDevice(names[0]);
device.EnableCallback(OnReadScanData, CallbackType.OnDataAvailable, 1000); device.EnableCallback(OnReadScanData, CallbackType.OnScanComplete, null);
device.SendMessage("AISCAN:LOWCHAN=0"); device.SendMessage("AISCAN:HIGHCHAN=0"); device.SendMessage("AISCAN:RATE=1000"); device.SendMessage("AISCAN:SAMPLES=5000"); device.SendMessage("AISCAN:START");
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
protected void OnReadScanData(ErrorCodes errorCode, CallbackType callbackType, object callbackData) {
try {
int availableSamples = (int)callbackData; double[,] scanData = device.ReadScanData(availableSamples, 0);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
The following are examples of reading scan data using a callback method:
C#
21
DAQFlex Software User's Guide Using DAQFlex Software
Try
Dim ScanData As Double(,) Dim Names As String() Dim Device As DaqDevice
Names = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno) Device = DaqDeviceManager.CreateDevice(Names(0))
Device.EnableCallback(AddressOf OnReadScanData, CallbackType.OnDataAvailable,
1000) Device.EnableCallback(AddressOf OnReadScanData, CallbackType.OnScanComplete, Nothing)
Device.SendMessage("AISCAN:LOWCHAN=0") Device.SendMessage("AISCAN:HIGHCHAN=0") Device.SendMessage("AISCAN:RATE=1000") Device.SendMessage("AISCAN:SAMPLES=5000") Device.SendMessage("AISCAN:START")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Protected Sub ReadScanData(ByVal errorCode As ErrorCodes, ByVal callbackType As CallbackType, _ ByVal callbackData As Object)
Try
Dim AvailableSamples As Integer Dim ScanData As Double(,)
AvailableSamples = DirectCast(callbackData, Integer) ScanData = Device.ReadScanData(AvailableSamples, 0)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
try {
double[,] scanData = new double[1, 5000];
string[] names = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno); DaqDevice device = DaqDeviceManager.CreateDevice(names[0]);
// fill scanData with data
device.SendMessage("AOSCAN:LOWCHAN=0"); device.SendMessage("AOSCAN:HIGHCHAN=0"); device.SendMessage("AOSCAN:RATE=1000"); device.SendMessage("AOSCAN:SAMPLES=5000"); device.SendMessage("AOSCAN:BUFSIZE=5000");
int timeOut = 0;
device.WriteScanData(scanData, 5000, timeOut);
device.SendMessage("AOSCAN:START");
}
VB
The basic approach to programming analog output scans is to set the device's output scan properties,
call the WriteScanData() method, and send the START command. The following examples show how to
program a basic output scan.
C#
22

Writing hardware-paced I/O

DAQFlex Software User's Guide Using DAQFlex Software
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
Try
Dim ScanData As Double(,) Dim Names As String() Dim Device As DaqDevice Dim TimeOut As Integer
Names = DaqDeviceManager.GetDeviceNames(DeviceNameFormat.NameAndSerno) Device = DaqDeviceManager.CreateDevice(Names(0))
Device.SendMessage("AOSCAN:LOWCHAN=0") Device.SendMessage("AOSCAN:HIGHCHAN=0") Device.SendMessage("AOSCAN:RATE=1000") Device.SendMessage("AOSCAN:SAMPLES=5000")
Device.SendMessage("AOSCAN:BUFSIZE=5000")
int TimeOut = 0
Device.WriteScanData(ScanData, 5000, TimeOut)
Device.SendMessage("AOSCAN:START")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
VB

WriteScanData() parameters

The first parameter to the WriteScanData method is the array containing the output scan data. The second parameter is the number of samples to write. The last parameter is a timeout value in milliseconds.
The WriteScanData method is synchronous, and will return when the number of samples specified have been written to the device’s output buffer.
Each time the WriteScanData method is called, the data is written to an internal buffer starting at the point after the last sample was written. When an output scan completes or is stopped, the write index is reset to the beginning of the buffer.

Internal buffer

23
C#:
static string[] GetDeviceNames(DeviceNameFormat format);
VB:
Shared Function GetDeviceNames(ByVal format As DeviceNameFormat) As String()
Value
Return string format
NameOnly
"Device name"
NameAndSerno
"Device name::Device serial number"
NameAndID
"Device name::Device ID"
NameSernoAndID
"Device name::Device serial number::Device ID"
Chapter 3

DAQFlex Software Reference

The DAQFlex Software API is an open source library that implements a simple message-based protocol consisting of text-based commands, or messages. The API is written in C#, is designed for cross platform portability, and does not require a separate configuration utility or a configuration file.
DAQFlex Software API contains two classes:
DaqDeviceManager class DaqDevice class

DaqDeviceManager class

The DaqDeviceManager class includes the following methods:
GetDeviceNames() – gets a list of devices that support the message-based protocol. CreateDevice() – creates a DaqDevice object, which contains the methods used to communicate
with a DAQ device.
ReleaseDevice() – frees the resources associated with a DaqDevice object.

DaqDeviceManager.GetDeviceNames()

Gets a list of DAQ devices that support the message-based protocol.
Parameter
format
The format to use for a device name. This parameter is a DeviceNameFormat enumeration. The enumeration values and the format of the return strings are listed below:
Return value
An array of strings containing the device names of all DAQ devices that support the message-based protocol.
Remarks
The values contained in the array can be used to create a DaqDevice object for the device that you
want to program.
The DaqDevice object is created using the DaqDeviceManager CreateDevice static method.
With the DaqDevice object, all DAQ operations are configured using one API method called
SendMessage() rather than using multiple operation-specific methods.
The NameOnly format is not useful if multiple devices of the same type are connected, since the
application won't be able to differentiate between one device and the other. If you are using multiple devices of the same type, then use one of the other formats.
24
DAQFlex Software User's Guide DAQFlex Software Reference
C#:
static CreateDevice(string deviceName);
VB:
Shared Function CreateDevice(ByVal deviceName As String) As DaqDevice
try
{
MyDevice = DaqDeviceManager.CreateDevice(deviceName);
}
catch (Exception ex)
{
// handle exception
}
Try
MyDevice = DaqDeviceManager.CreateDevice(deviceName)
Catch Ex As Exception
' handle exception
End Try
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.
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#
VB
25
DAQFlex Software User's Guide DAQFlex Software Reference
C#:
static void ReleaseDevice(DaqDevice device);
VB:
Shared Sub ReleaseDevice(ByVal device As DaqDevice)
C#:
DaqResponse SendMessage (string message);
VB:
Function SendMessage (ByVal Message as String) As DaqResponse

DaqDeviceManager.ReleaseDevice()

Frees the resources associated with a DaqDevice object.
Parameter
Device
A DaqDevice object created by the CreateDevice() method.

DaqDevice class

The DaqDevice class includes the following methods:
SendMessage() – takes a single text-based command that the DAQ device parses to configure a
particular operation.
ReadScanData() – reads scan data. WriteScanData() – outputs scan data. EnableCallback() – enables a user-defined callback method to be invoked when a certain condition
is met. This method is used in conjunction with input scan operations.
DisableCallback() – the condition that invokes the callback method. GetErrorMessage() – gets the error message associated with the error code that is passed to the
user-defined callback.
GetSupportedMessages() – returns a list of messages supported by a DAQ component.

DaqDevice.SendMessage()

Configures DAQ operations. This method takes a single text-based command that the DAQ device parses to configure a particular operation.
Parameter
Message
The text-based message to send to the device.
Return value
The device response as an instance of a DaqResponse object.
Remarks
Message is a string containing a text-based command supported by the device, and Response is a
DaqResponse object containing the device's response.
The DaqResponse object includes two methods: ToString(): gets the response as a string, for example "AI{0}:VALUE=139". ToValue(): gets the response as a numeric value, for example "139.0000". All messages provide a string response, but not all messages provide a numeric response. For those
messages that do not provide a numeric response, the numeric value is set to NaN (not a number).
26
DAQFlex Software User's Guide DAQFlex Software Reference
try {
DaqResponse response = MyDevice.SendMessage(message); label1.Text = response.ToString();
}
Catch (Exception ex) {
// handle exception label1.Text = ex.Message;
}
Try
DaqResponse Response = MyDevice.SendMessage(Message) Label1.Text = Response.ToString()
Catch Ex As Exception
' handle exception Label1.Text = Ex.Message;
End Try
C#:
double[,] ReadScanData(int samplesRequested, int timeOut);
VB:
Function ReadScanData(ByVal samplesRequested As Integer, ByVal timeOut As Integer) As Double(,)
The ToString method has additional overloads that accept formatting parameters. The overloads are
ToString(string format), ToString(IFormatProvider provider) and ToString(string format, IFormatProvider provider). The overloads can be used to format the numeric part of a response, if present. If the response does not contain a numeric, these overloads are ignored.
If an error occurs while sending a message to a device, the SendMessage method will throw an
exception rather than returning an error code. This means the application should encapsulate calls
to SendMessage within a try/catch block.
Refer to the following sample code.
C#
VB

DaqDevice.ReadScanData()

Reads data for a scan operation.
Parameter
samplesRequested
The number of samples per channel to read.
timeOut
The number of milliseconds to wait for the samples requested to become available.
Return value
An array of data samples read from the device.
Remarks
The DAQFlex library always performs scan operations in the background, but ReadScanData()
always runs in the foreground. When called, ReadScanData() returns control to the application that called it when the number of samples requested has been read. When timeOut is non-zero, if the
number of samples requested isn’t available within the time specified by timeOut, an exception is
thrown. The DAQFlex library manages all memory allocation and array indexing so the application doesn't have to.
27
DAQFlex Software User's Guide DAQFlex Software Reference
C#:
void WriteScanData(double[,] scanData, int numberOfSamplesPerChannel, int timeOut);
VB:
Sub WriteScanData(ByVal ScanData(,) As Double, ByVal NumberOfSamplesPerChannel As Integer, ByVal TimeOut As Integer)
C#:
void EnableCallback(ErrorCodes errorCode, InputScanCallbackDelegate callback, CallbackType callbackType, Object callbackData
VB:
Sub EnableCallback(ByVal errorCode as ErrorCodes, ByVal callback as InputScanCallbackDelegate, ByVal callbackType As CallbackType, ByVal callbackData As Object)

DaqDevice.WriteScanData()

Outputs scan data.
Parameter
scanData
Array of data samples to output.
numberOfSamplesPerChannel
The number of data samples per channel to transfer from the scanData array to the device's output buffer.
timeOut
The number of milliseconds to wait for available space in the buffer to write to. This only takes effect when an output scan is running.
Remarks
WriteScanData may be called while a scan is running. However, the maximum number of total
samples must be less than or equal to half the number of samples for which the buffer is allocated. Set the buffer size with the "AOSCAN:BUFSIZE" message.

DaqDevice.EnableCallback()

Enables a user-defined callback method to be invoked when a certain condition is met.
Parameter
callback
The method to be invoked when the condition specified by callbackType is met. Refer to
InputScanCallback Delegate on page 29 for the format of the method.
callbackType
The condition that invokes the callback method. Callback types are defined by the CallbackType enumeration. The supported types are:
o CallbackType.OnDataAvailable – Invokes the callback method when the number of samples
available for reading data is the number of samples specified by the callbackData parameter.
o CallbackType.OnInputScanComplete – Invokes the callback method when an input scan
completes or is stopped.
o CallbackType.OnInputScanError Invokes the callback method when an input scan error
occurs.
callbackData
When callbackType is set to OnDataAvailable, set callbackData to the number of samples per channel to acquire before invoking the user-defined callback method. When callbackType is set to OnInputScanComplete or OnInputScanError, set callbackData to null or Nothing.
28
DAQFlex Software User's Guide DAQFlex Software Reference
C#:
public delegate void InputScanCallbackDelegate(MeasurementComputing.DAQFlex.ErrorCodes errorCode, MeasurementComputing.DAQFlex.CallbackType callbackType, object callbackData)
VB:
Public Delegate Sub InputScanCallbackDelegate(ByVal errorCode As MeasurementComputing.DAQFlex.ErrorCodes, ByVal callbackType As MeasurementComputing.DAQFlex.CallbackType, ByVal callbackData As Object)
C#:
void DisableCallback(CallbackType callbackType)
VB:
Sub DisableCallback(ByVal callbackType As CallbackType)
C#:
string GetErrorMessage(ErrorCodes errorCode)
VB:
Function GetErrorMessage(ByVal errorCode As ErrorCodes)
Return value
The value of callbackType.
Remarks
This method is used in conjunction with input scan operations. EnableCallback may be called once for each callback type. If it is called more than once for the
sample callback type, a DaqException is thrown.

InputScanCallback Delegate

A delegate is a data structure that refers either to a static method, or to a class instance and an instance method of that class. You call the delegate by passing either its address or a pointer to the delegate to the callback parameter of the EnableCallback() method.

DaqDevice.DisableCallback()

Disables the invocation of the user-defined callback method associated with the callback type.
Parameter
callbackType The callback type to disable.

DaqDevice.GetErrorMessage()

Gets the error message associated with the error code that is passed to the user-defined callback.
Parameter
errorCode
The error code that was passed to the user-defined callback method.
Return value
The error message associated with the error code passed to the user-defined callback method.
29
DAQFlex Software User's Guide DAQFlex Software Reference
C#:
public List<string> GetSupportedMessages(string daqComponent);
VB:
Function GetSupportedMessages(ByVal daqComponent As String) As List(Of String)

DaqDevice.GetSupportedMessages()

Gets the messages supported by a DAQ component.
Parameter
daqComponent
A DAQ component, such as AISCAN, DEV, TMR, and so on.
Return value
A list of messages supported by the daqComponent parameter.
30
Loading...
+ 95 hidden pages