# D2K-DASK

Data Acquisition Software Development Kit

For DAQ-2000 Devices, Windows NT/98/2000/XP

User’s Guide

@Copyright 1997-2004 ADLink Technology Inc.

All Rights Reserved.

Manual Rev. 1.61 : Mar. 17, 2004

The information in this document is subject to change without prior notice in order to improve reliability, design and function and does not represent a commitment on the part of the manufacturer.

In no event will the manufacturer be liable for direct, indirect, special, incidental, or consequential damages arising out of the use or inability to use the product or documentation, even if advised of the possibility of such damages.

This document contains proprietary information protected by copyright. All rights are reserved. No part of this manual may be reproduced by any mechanical, electronic, or other means in any form without prior written permission of the manufacturer.

# Trademarks

DAQ-2000, D2K-DASK and PCI series products names are registered trademarks of ADLink Technology Inc. Other product names mentioned herein are used for identification purposes only and may be trademarks and/or registered trademarks of their respective companies.

# CONTENTS

# INTRODUCTION TO D2K-DASK .

1.1 ABOUT THE D2K-DASK SOFTWARE..
1.2 D2K-DASK HARDWARE SUPPORT . 2
1.3 D2K-DASK LANGUAGE SUPPORT . 2

# THE FUNDAMENTALS OF BUILDING WINDOWSNT/98/2000 APPLICATIONS WITH D2K-DASK.............. 3

2.1 CREATING A WINDOWS NT/98/2000 D2K-DASK APPLICATIONS USING MICROSOFT VISUAL C/C++.. 3
2.2 CREATING A WINDOWS NT/98/2000 D2K-DASK APPLICATIONS USING MICROSOFT VISUAL BASIC. 3

# D2K-DASK UTILITIES.... ... 6

3.1 DAQ-2000 REGISTRY/CONFIGURATION UTILITY (D2KUTIL).. . 6
3.2 D2K-DASK DATA FILE CONVERTER UTILITY (DAQCVT).. . 10
3.3 D2K-DASK SAMPLE PROGRAMS BROWSER (EXAMPLES.EXE) . 11

# D2K-DASK OVERVIEW .... 12

4.1 GENERAL CONFIGURATION FUNCTION GROUP.. . 13
4.2 ANALOG INPUT FUNCTION GROUP ..... 13

4.2.1 Analog Input Configuration Functions . . 13
4.2.2 One-Shot Analog Input Functions... . 13
4.2.3 Continuous Analog Input Functions ......... . 13
4.2.4 Asynchronous Analog Input Monitoring Functions .. . 14

4.3 ANALOG OUTPUT FUNCTION GROUP .. . 15

4.3.1 Analog output Configuration Functions .. . 15
4.3.2 One-Shot Analog Output Functions.. . 15
4.3.3 Continuous Analog Output Functions......... . 15
4.3.4 Asynchronous Analog Output Monitoring Functions ... . 16

4.4 DIGITAL INPUT FUNCTION GROUP .. .. 16
4.4.1 One-Shot Digital Input Functions......... . 16
4.5 DIGITAL OUTPUT FUNCTION GROUP .. .. 16
4.5.1 One-Shot Digital Output Functions .. . 16
4.6 GENERAL TIMER/COUNTER FUNCTION GROUP.. . 17
4.6.1 The General-Purpose Timer/Counter Functions .. . 17
4.7 DIO FUNCTION GROUP.. . 17
4.7.1 Digital Input/Output Configuration Functions .. . 17
4.8 SSI FUNCTION GROUP... . 17
4.9 CALIBRATION FUNCTION GROUP.. . 17

# D2K-DASK APPLICATION HINTS...... 19

5.1 ANALOG INPUT PROGRAMMING HINTS. . 20

5.1.1 One-Shot Analog input programming Scheme.. . 21

5.1.2 Continuous Analog input (with initial default settings) programming Scheme .. . 23

5.1.3 Post Trigger Mode/ Delay Trigger Mode Synchronous Continuous Analog input programming Scheme .. 26

5.1.4 Post Trigger Mode/ Delay Trigger Mode Non-double-buffered Asynchronous Continuous Analog input programming Scheme .. . 27

5.1.5 Post Trigger Mode/ Delay Trigger Mode Double-buffered Asynchronous Continuous Analog input programming Scheme . 29

5.1.6 Pre-Trigger Mode/ Middle-Trigger Mode Non-double-buffered Asynchronous Continuous Analog input programming Scheme . . 32

5.1.7 Pre-Trigger Mode/ Middle-Trigger Mode Double-buffered Asynchronous Continuous Analog input programming Scheme . . 34

5.2 ANALOG OUTPUT PROGRAMMING HINTS ..... .. 37

5.2.1 One-Shot Analog output programming Scheme.. . 38

5.2.2 Continuous Analog output (with initial default settings) programming Scheme .. .. 40

5.2.3 Non-double-buffered Asynchronous Continuous Analog output programming Scheme. . 43

5.2.4 Double-buffered Asynchronous Continuous Analog output programming Scheme. . 45

5.3 DIGITAL INPUT PROGRAMMING HINTS ..... . 49

5.3.1 One-Shot Digital input programming Scheme .. . 49

5.4 DIGITAL OUTPUT PROGRAMMING HINTS..... .. 50

5.4.1 One-Shot Digital output programming Scheme ... . 50

5.5 DAQ EVENT MESSAGE PROGRAMMING HINTS . .. 51

# CONTINUOUS DATA TRANSFER IN D2K-DASK.. . 52

6.1 CONTINUOUS DATA TRANSFER MECHANISM . . 52

6.2 DOUBLE-BUFFERED AI/AO OPERATION . ... .. 52

6.2.1 Double Buffer Mode Principle. . 52

6.2.2 Single-Buffered Versus Double-Buffered Data Transfer . .. 53

6.3 PRE-TRIGGER MODE/ MIDDLE-TRIGGER MODE DATA ACQUISITION FOR ANALOG INPUT. . 54

# DISTRIBUTION OF APPLICATIONS ...... 55

7.1 FILES 55

7.2 AUTOMATIC INSTALLERS.. .. 55

7.3 MANUAL INSTALLATION . ... .. 56

# How to Use This Manual

This manual is to help you use the D2K-DASK software driver for DAQ-2000 PCI-bus data acquisition cards. The manual describes how to install and use the software library to meet your requirements and help you program your own software applications. It is organized as follows:

z Chapter 1, "Introduction to D2K-DASK" describes the hardware and language support of D2K-DASK.
z Chapter 2, "The Fundamentals of Building Windows NT/98 Applications with D2K-DASK" describes the fundamentals of creating D2K-DASK applications in Windows NT and Windows 98.
z Chapter 3, "D2K-DASK Utilities" describes the utilities D2K-DASK provides.
z Chapter 4, "D2K-DASK Overview" describes the classes of functions in D2K-DASK and briefly describes each function.
z Chapter 5, "D2K-DASK Application Hints" provides the programming schemes showing the function flow of that D2K-DASK performs analog I/O and digital I/O.
z Chapter 6, "Continuous Data Transfer in D2K-DASK" describes the mechanism and techniques that D2K-DASK uses for continuous data transfer.
z Chapter 7, " Distribution of Applications" describes the required files to distribute your applications.

# 1

# Introduction to D2K-DASK

# 1.1 About the D2K-DASK Software

D2K-DASK is a software development kit for DAQ-2000 data acquisition cards. It contains a high performance data acquisition driver for developing custom applications under Windows NT, Windows 98 and Windows 2000 environments.

The memory and data buffer management capabilities free developers from dealing with there complex issues. That is, D2K-DASK is constructed to provide a simple programming interface in communication with the DAQ-2000 data acquisition cards. The easy-to-use functions provided by D2K-DASK allow a programmer to use the features of the card in a high level way.

Using D2K-DASK also makes you take advantage of the power and features of Microsoft Win32 System for your data acquisition applications, including running multiple applications and using extended memory. Also, using D2K-DASK under Visual Basic environment makes it easy to create custom user interfaces and graphics.

In addition to the software drivers, some sample programs are provided for your reference to save a lot of programming time and get some other benefits as well.

# 1.2 D2K-DASK Hardware Support

ADLink will periodically upgrade D2K-DASK for new DAQ-2000 data acquisition cards. Please refer to Release Notes for the cards that the current D2K-DASK actually supports. The following cards are those D2K-DASK supports currently or will support in the near future:

z DAQ-2010 : 2MHz 4 channels simultaneous A/D and 2 channels D/A output device with bus mastering DMA transfer capability
z DAQ-2005 : 500kHz 4 channels simultaneous A/D and 2 channels D/A output device with bus mastering DMA transfer capability
z DAQ-2006 : 250kHz 4 channels simultaneous A/D and 2 channels D/A output device with bus mastering DMA transfer capability
z DAQ-2204 : 3MHz 64 channels multiplexed A/D and 2 channels D/A output device with bus mastering DMA transfer capability
z DAQ-2205 : 500kHz 64 channels multiplexed A/D and 2 channels D/A output device with bus mastering DMA transfer capability
z DAQ-2206 : 250kHz 64 channels multiplexed A/D and 2 channels D/A output device with bus mastering DMA transfer capability
z DAQ-2208 : 3MHz 96 channels multiplexed A/D device with bus mastering DMA transfer capability
z DAQ-2213 : 250kHz 16 channels multiplexed A/D device with bus mastering DMA transfer capability
z DAQ-2214 : 250kHz 16 channels multiplexed A/D and 2 channels D/A output device with bus mastering DMA transfer capability
z DAQ-2501 : High Performance 4 channels analog output Multi-function device with bus mastering DMA transfer capability
z DAQ-2502 : High Performance 8 channels analog output Multi-function device with bus mastering DMA transfer capability

# 1.3 D2K-DASK Language Support

D2K-DASK is DLL (Dynamic-Link Library) version for using under Windows NT, Window 98 and Windows 2000. It can work with any Windows programming language that allows calls to a DLL, such as Microsoft Visual C/C++ (4.0 or above), Borland C++ (5.0 or above), or Microsoft Visual Basic (4.0 or above), etc.

D2K-DASK also provides a D2K-DASK function prototype file, D2KDask.pas for use with Borland Delphi 2.x (32-bit) or above.

# 2

# The Fundamentals of BuildingWindowsNT/98/2000 Applications with D2K-DASK

# 2.1 Creating a Windows NT/98/2000 D2K-DASK Applications Using Microsoft Visual C/C++

To create a data acquisition application using D2K-DASK and Microsoft Visual C/C++, follow these steps after entering Visual C/C++:

step 1. Open the project in which you want to use D2K-DASK. This can be a new or existing project

step 2. Include header file D2KDASK.H in the C/C++ source files that call D2K-DASK functions. D2KDASK.H contains all the function declarations and constants that you can use to develop your data acquisition application. Incorporate the following statement in your code to include the header file.

#include “D2KDASK.H”

step 3. Build your application.

Setting the appropriate compile and link options, then build your application by selecting the Build command from Build menu (Visual C/C++ 5.0). Remember to link D2K-DASK’s import library, D2K-DASK.LIB.

# 2.2 Creating a Windows NT/98/2000 D2K-DASK Applications Using Microsoft Visual Basic

To create a data acquisition application using D2K-DASK and Visual Basic, follow these steps after entering Visual Basic:

step 1. Open the project in which you want to use D2K-DASK. This can be a new or existing project Open a new project by selecting the New Project command from the File menu. If it is an existing project, open it by selecting the Open Project command from the File menu. Then the Open Project dialog box appears.

![Open Project\nLook jn: Microsoft Visual Basic\nbitmaps report Auto32ld.vbp\nclisvr samples\nhc setup\nicons setupkit\ninclude VBOnline\nmetafile winapi\nFile name:\nFiles of type: Project Files(*.Vbp;*.Mak)\nOpen\nCancel](.d2k-dask-manual-1/8edab825845c96d90f3d0ad32837e1abec0b3429154d1bcbbdb3cdf1b223eb3c.jpg)

Changed directory to the place the project file located. Double-click the project file name in the File Name list to load the project.

step 2. Add file D2KDASK.BAS into the project if this file is not included in the project. This file contains all the procedure declarations and constants that you can use to develop your data acquisition application.

From the File menu, select the Add File command. The Add File window appears, displaying a list of files in the current directory.

![Add File\nLook in: include\nDisk.bas\nFile name: Disk.bas\nFiles of type: VB Files(*.Frm;*.Bas;*.Cls;*.Res)\nOpen\nCancel](.d2k-dask-manual-1/0c6f2792511ba5d9349d3fa21ed2e3c5c9c40b8a90e581133e1a605d34c614ed.jpg)

Select D2KDASK.BAS from the Files list by double clicking on it. If you can't find this file in the list, make sure the list is displaying files from the correct directory. By default, D2KDASK.BAS is installed in C:\ADLink\D2K-DASK\INCLUDE.

step 3. Design the interface for the application.

To design the interface, you place the desired elements, such as command button, list box, text box, etc., on the Visual Basic form. These are standard controls from the Visual Basic Toolbox. To place a control on a form, you just move pointer to Toolbox, select the desired control and draw it on the form. Or you can double-click the control icon in the Toolbox to place it on the form.

step 4. Set properties for the controls.

To view the property list, click the desired control and then choose the Properties command from the

View menu or press F4, or you can also click the Properties button 图 on the toolbar.

step 5. Write the event code.

The event code defines the action you want to perform when an event occurs. To write the event code, double-click the desired control or form to view the code module and then add code you want. You can call the functions that declared in the file D2KDASK.BAS to perform data acquisition operations.

step 6. Run your application.

To run the application, choose Start from the Run menu, or click the Start icon on the toolbar (you can also press F5).

step 7. Distribute your application.

Once you have finished a project, you can save the application as an executable (.EXE) file by using the Make EXE File command on the File menu. And once you have saved your application as an executable file, you've ready to distribute it. When you distribute your application, remember also to include the D2K-DASK’s DLL and driver files. Please refer to chapter “Distribution of Applications” for the details.

# 3

# D2K-DASK Utilities

This chapter introduces the tools that accompanied with the D2K-DASK package.

# 3.1 DAQ-2000 Registry/Configuration utility (D2kUtil)

D2kUtil is used for the users to register D2K-DASK drivers (Windows NT4 only), remove installed drivers (Windows NT4 only), and set/modify the allocated buffer sizes of AI, AO, DI and DO. The default location of this utility is &lt;InstallDir&gt;\Util directory.

# [D2kUtil in Windows NT]

The D2kUtil main window is shown as the following window. If any D2K-DASK/NT driver has been registered, it will be shown on the Registered Driver list.

![DAQ2000 NT Driver Registry\nExit!\nThis utility is used to make DAQ 2010\nNT driver registry.\nRegistered Drivers :\n(none)\nNew...\nModify...\nRemove\nDone](.d2k-dask-manual-1/bff7210c16c164aff76516e02411393ebd20d134fc1ac4e465bdde0b76f51f01.jpg)

To register one of D2K-DASK drivers, click “New…” button and a Driver Configuration window appears.

![Driver Configuration\nCard Type: Daq2010\nBuffer Allocated (KB):\nAI : 1024\nAO : 1024\nDI : 0\nDO : 0\nOK    Apply    Cancel](.d2k-dask-manual-1/b514805e1d5f79c7c80efd31847d417feacdb94d2e2c044f1a19a52271056111.jpg)

In this window, users can select the driver you want to register and input the parameters in the box corresponding to AI, AO, DI, or DO for the requirement of your applications. The “Buffer Allocated” of AI, AO, DI, DO represent the sizes of contiguous Initially Allocated memory for continuous analog input, analog output, digital input, digital output respectively.

Its unit is KB, i.e. 1024 bytes. Device driver will try to allocate these sizes of memory at system startup time. The size of initially allocated memory is the maximum memory size that DMA or Interrupt transfer can be performed. It will induce an unexpected result in that DMA or Interrupt transfer performed exceeds the initially allocated size.

After the device configurations of the driver you select is finished, click “OK” to register the driver and return to the D2kUtil main window. The driver you just registered will be shown on the registered driver list as the following figure:

![DAQ2000 NT Driver Registry\nExit!\nThis utility is used to make DAQ 2010\nNT driver registry.\nRegistered Drivers :\nDaq2010\nNew...\nModify...\nRemove\nDone](.d2k-dask-manual-1/0f17f936122aa555fa5328e1914c144a724b5b3ae3cf80e32bacc96f5f915ae5.jpg)

Using D2kUtil to change the buffer allocated settings of one of the D2K-DASK drivers, select the driver from the Registered Driver list and click “Modify…” button and then a “Driver Configuration” window is shown as below.

![Driver Configuration\nCard Type: Daq2010\nBuffer Allocated (KB):\nAI : 1024\nAO : 1024\nDI : 0\nDO : 0\nOK Apply Cancel](.d2k-dask-manual-1/b293b6738ad7d45f9b7cf3cd238e5cccb2a50f18db4b3f676cb0e7143cc1b858.jpg)

Inside the allocated buffer size fields of AI, AO, DI and DO are the originally set values. Type the value in the box corresponding to AI, AO, DI, or DO according to the requirement of your applications, and then click “OK” button.

To remove a registered driver, select the driver from the Registered Driver list in The D2kUtil main window and click “Remove” button. The selected driver will be deleted from the registry table.

# [D2kUtil in Windows 98]

This utility is used to set/modify the allocated buffer sizes of AI, AO, DI and DO. The allocated buffer sizes of AI, AO, DI, DO represent the sizes of contiguous Initially Allocated memory for continuous analog input, analog output, digital input, digital output respectively. Its unit is page KB, i.e. 1024 bytes. Device driver will try to allocate these sizes of memory at system startup time. The size of initially allocated memory is the maximum memory size that DMA or Interrupt transfer can be performed. It will induce an unexpected result in that DMA or Interrupt transfer performed exceeds the initially allocated size.

The “Driver Configuration” window is shown as below.

![Driver Configuration\nThis utility is used for the cards that will perform continuous AI, DI or DO operation\nCard Type: Daq2010\nBuffer Allocated (KB):\nAI : 1024\nAO : 1024\nDI : 1024\nDO : 1024\nOK    Apply    Cancel](.d2k-dask-manual-1/b130344768a3118a342eb44c6425c679d8b6fc238a9f0c15eac3e4b23cd735d5.jpg)

Using D2kUtil to change the buffer allocated settings of one of the D2K-DASK drivers, select the driver from the Card Type combo box.

Inside the allocated buffer size fields of AI, AO, DI and DO are the originally set values. Type the value in the box corresponding to AI, AO, DI, or DO according to the requirement of your applications, and then click “Apply” button.

# [D2kUtil in Windows 2000]

This utility is used to set/modify the allocated buffer sizes of AI, AO, DI and DO. The allocated buffer sizes of AI, AO, DI, DO represent the sizes of contiguous Initially Allocated memory for continuous analog input, analog output, digital input, digital output respectively. Its unit is page KB, i.e. 1024 bytes. Device driver will try to allocate these sizes of memory at system startup time. The size of initially allocated memory is the maximum memory size that DMA or Interrupt transfer can be performed. It will induce an unexpected result in that DMA or Interrupt transfer performed exceeds the initially allocated size.

The “Driver Configuration” window is shown as below.

![DAQ2000 Device Driver Configuration\nThis utility is used for the cards that will perform continuous AI, DI or DO operation\nCard Type: Daq2010\nBuffer Allocated (KB):\nAI : 1024\nAO : 1024\nDI : 0\nDO : 0\nOK    Apply    Cancel](.d2k-dask-manual-1/cdce418f7ffbc8339f1cdc5064110c178af1fea1c3ba2505a66e47b8a225e2bf.jpg)

Using D2kUtil to change the buffer allocated settings of one of the D2K-DASK drivers, select the driver from the Card Type combo box.

Inside the allocated buffer size fields of AI, AO, DI and DO are the originally set values. Type the value in the box corresponding to AI, AO, DI, or DO according to the requirement of your applications, and then click “Apply” button.

# 3.2 D2K-DASK Data File Converter utility (DAQCvt)

The data files, generated by the D2K-DASK functions performing continuous data acquisition followed by storing the data to disk, is written in binary format. Since a binary file can’t be read by the normal text editor and can’t be used to analyze the accessed data by Excel, D2K-DASK provides a convenient tool DAQCvt to convert the binary file to the file format read easily. The default location of this utility is &lt;InstallDir&gt;\Util directory. The DAQCvt main window is as the following figure:

![ADLink DAQ File Convert Utility\nInput File\nFile Path:\nBrowse\nCard Type: AD Range:\nChannel number: Scan rate(Hz):\nNumber of scan: Start date:\nData width: Start time:\nChannel order: Channel/Range:\nView\nLoad\nOutput File\nFile Path:\nBrowse\nFormat: Scaled data to text file\nText File\nSeparator: Space Tab, Title/Head\nDigital: Decimal Hexadecimal\nStart Convert About Exit](.d2k-dask-manual-1/0aa2082f43a4dcc1481e13289cd84bb9177afe27a40d02414b271fb18821afba.jpg)

The DAQCvt main window includes two frames. The upper frame, Input File frame is used for the source data file and the lower frame is used for the destination file.

To load the source binary data file, type the binary data file name in File Path field or click Browser button to select the source file from Input File frame, and then click Load button. As the file is loaded, the information related to the data file, e.g. data type, data width, AD Range, …etc., are shown in the corresponding fields in “Input File” frame, and the default converted data file path and format are also listed as the figure below.

![DAQ File Conversion Utility\nInput file\nFile path: I:\Daq2k\Samples\2010\C2010DbfFile\2010d.dat\nBrowse...\nCard type: DAQ-2010 AD range: +/-10V\nChannel number: 4 Scan rate(Hz): 1000.000\nNumber of scan: 2014 Start date: 08/31/01\nData width: 16 bits Start time: 10:57:27.100\nChannel order: Custom Channel/Range: 4 View\nLoad\nOutput file\nFile path: I:\Daq2k\Samples\2010\C2010DbfFile\2010d.cvtColor\nBrowse...\nFormat: Text file with scaled data\nText file\nSeparator: ○ Space ○ Tab ○ , ✓ Title/Head\nDigital: ○ Decimal ○ Hexadecimal\nStart Convert About Exit](.d2k-dask-manual-1/24835aa056d4329872e698d48fa18cac083cb8d7953d25861833fb6b6df7617b.jpg)

The default destination file with a .cvt extension is located in the same directory as the source one. To change the default setting, type the file path you wish or click the Browser button from Output File frame to select the destination file location.

DAQCvt provides three types of data format conversion.

Text file with scaled data :

The data in hexadecimal format is scaled to engineering unit (voltage, ample, …etc) according to the card type, data width and data range and then written to disk in text file format. This type is available for the data accessed from continuous AI operation only.

Binary file with scaled data :

The data in hexadecimal is scaled to engineering unit (voltage, ample, …etc) according to the card type, data width and data range and then written to disk in binary file format. This type is available for the data accessed from continuous AI operation only.

Text file with binary codes :

The data in hexadecimal format or converted to a decimal value is written to disk in text file format. If the original data includes channel information, the raw value will be handled to get the real data value. This type is available for the data accessed form continuous AI and DI operations.

The data separator in converted text file is selectable among space, comma and Tab.

If you want to add title/head which includes the card type information at the beginning of file, check the “Title/Head” box.

After setting the properties (File Path, Format, …etc) related to the converted file, you can push Start Convert button from the Output File frame to perform the file conversion.

# 3.3 D2K-DASK Sample Programs Browser (Examples.exe)

D2K-DASK provides a sample program browser, Examples.exe, for you to view and execute the sample programs that D2K-DASK package includes. The default location of this utility is &lt;InstallDir&gt;\Samples directory. After Examples.exe utility is running, select the device you wish to operate from the device list in the left frame, and then double click the icon of the sample you wish to execute to run this sample program.

![Examples\nD2K-DASK Samples\nDAQ-2010\nSDK2010	C2010DbfA0\nSDK2010DbfAboutTrg	SDK2010DIO\nSDK2010DbfDelayTrg	VB2010AI\nSDK2010DbfPostTrg	VB2010GPTC\nSDK2010DelayTrg\nSDK2010MidTrg\nSDK2010PostTrg\nSDK2010SimuDma\nSDK2010SSIDest\nSDK2010SSISrc\nC2010File\nC2010DbfFile\nC2010A0\nExit](.d2k-dask-manual-1/c0005057769275793b1dff3097dd0539f1c97e7471929503015d245a1eea588a.jpg)

# 4

# D2K-DASK Overview

This chapter describes the classes of functions in D2K-DASK and briefly describes each function.

D2K-DASK functions are grouped to the following classes:

z General Configuration Function Group
z Analog Input Function Group

- Analog Input Configuration functions
- One-Shot Analog Input functions
- Continuous Analog Input functions
- Asynchronous Analog Input Monitoring functions

z Analog Output Function Group

- Analog Output Configuration functions
- One-Shot Analog Output functions
- Continuous Analog Output functions
- Asynchronous Analog Output Monitoring functions

z Digital Input Function Group

- Digital Input Configuration functions
- One-Shot Digital Input functions

z Digital Output Function Group

- Digital Output Configuration functions
- One-Shot Digital Output functions

z General Timer/Counter Function Group

z DIO Function Group

\- Digital Input/Output Configuration function

z SSI Function Group
z Calibration Function Group

# 4.1 General Configuration Function Group

Use these functions to initializes and configures data acquisition card.

<table><tr><td>D2K_Register_Card</td><td>Initializes the hardware and software states of an DAQ-2000 data acquisition card. Register_Card must be called before any other D2K-DASK library functions can be called for that card.</td></tr><tr><td>D2K_Release_Card</td><td>Tells D2K-DASK library that this registered card is not used currently and can be released. This would make room for new card to register.</td></tr><tr><td>D2K_AIO_Config</td><td>Informs D2K-DASK library of Timer source, and analog trigger source for the DAQ-2000 device.</td></tr></table>

# 4.2 Analog Input Function Group

# 4.2.1 Analog Input Configuration Functions

<table><tr><td>D2K_AI_CH_Config</td><td>Informs D2K-DASK library of the AI range selected for the specified analog input channel of DAQ-2000 device. You must call this function before calling function to perform analog input operation.</td></tr><tr><td>D2K_AI_Config</td><td>Informs D2K-DASK library of trigger source, trigger mode, input mode and trigger properties for the analog input operation of DAQ-2000 device. You must call this function before calling function to perform continuous analog input operation of DAQ-2000 device.</td></tr><tr><td>D2K_AI_MuxScanSetup</td><td>Informs stores numChans, chans, and gain_refGnd in the Channel-Gain Queue for a scanned data acquisition operation.</td></tr><tr><td>D2K_AI_InitialMemoryAllocated</td><td>Gets the actual size of analog input memory that is available in the device driver.</td></tr></table>

# 4.2.2 One-Shot Analog Input Functions

<table><tr><td colspan="2">D2K_AI_ReadChannel</td></tr><tr><td></td><td>Performs a software triggered A/D conversion (analog input) on an analog input channel and returns the value converted (unscaled).</td></tr><tr><td colspan="2">D2K_AI_SimuReadChannel</td></tr><tr><td></td><td>Performs a software triggered A/D conversion (analog input) on analog input channels and returns the values converted (unscaled). This function is only available for Simultaneous AD card (e.q. DAQ-2010).</td></tr><tr><td colspan="2">D2K_AI_ReadMuxScan</td></tr><tr><td></td><td>Returns readings for all analog input channels selected by D2K_AI_MuxScanSetup. This function is only available for Multiplexed AD card (e.q. DAQ-2205).</td></tr><tr><td colspan="2">D2K_AI_ScanReadChannels</td></tr><tr><td></td><td>Performs software triggered A/D conversions (analog input) on analog input channels and returns the values converted (unscaled). This function is only available for Multiplexed AD card (e.q. DAQ-2205).</td></tr><tr><td colspan="2">D2K_AI_VReadChannel</td></tr><tr><td></td><td>Performs a software triggered A/D conversion (analog input) on an analog input channel and returns the value scaled to a voltage in units of volts.</td></tr><tr><td>D2K_AI_VoltScale</td><td>Converts the result from an D2K_AI_ReadChannel call to the actual input voltage.</td></tr></table>

# 4.2.3 Continuous Analog Input Functions

D2K\_AI\_ContReadChannel Performs continuous A/D conversions on the specified analog input channel at a rate as close to the rate you specified.

D2K\_AI\_ContScanChannels Performs continuous A/D conversions on the specified continuous analog input channels at a rate as close to the rate you specified. This function is only available for those cards that support auto-scan functionality.

# D2K\_AI\_ContReadMultiChannels

Performs continuous A/D conversions on the specified analog input channels at a rate as close to the rate you specified. This function is only available for those cards that support auto-scan functionality.

# D2K\_AI\_ContReadChannelToFile

Performs continuous A/D conversions on the specified analog input channel at a rate as close to the rate you specified and saves the acquired data in a disk file.

# D2K\_AI\_ContScanChannelsToFile

Performs continuous A/D conversions on the specified continuous analog input channels at a rate as close to the rate you specified and saves the acquired data in a disk file. This function is only available for those cards that support auto-scan functionality.

# D2K\_AI\_ContReadMultiChannelsToFile

Performs continuous A/D conversions on the specified analog input channels at a rate as close to the rate you specified and saves the acquired data in a disk file. This function is only available for those cards that support auto-scan functionality.

D2K\_AI\_ContMuxScan This function initializes the Channel-Gain Queue to point to the start of the scan sequence as specified by D2K\_AI\_MuxScanSetup and starts a multiple-channel scanned data acquisition operation. This function is only available for Multiplexed AD card (e.g. DAQ-2205)

D2K\_AI\_ContMuxScanToFile Initializes the Channel-Gain Queue to point to the start of the scan sequence as specified by D2K\_AI\_MuxScanSetup, starts a multiple-channel scanned data acquisition operation and saves the acquired data in a disk file.

D2K\_AI\_ContVScale Converts the values of an array of acquired data from an continuous A/D conversion call to the actual input voltages.

D2K\_AI\_ContStatus Checks the current status of the continuous analog input operation.

D2K\_AI\_EventCallBack Controls and notifies the user’s application when a specified DAQ event occurs. The notification is performed through a user-specified callback function.

D2K\_AI\_ContBufferSetup Set up the buffer for continuous analog input.

D2K\_AI\_ContBufferReset Reset all the buffers set by function D2K\_AI\_ContBufferSetup.

# 4.2.4 Asynchronous Analog Input Monitoring Functions

D2K\_AI\_AsyncCheck Checks the current status of the asynchronous analog input operation.

D2K\_AI\_AsyncClear Stops the asynchronous analog input operation.

# D2K\_AI\_AsyncDblBufferMode

Enables or Disables double buffer data acquisition mode.

# D2K\_AI\_AsyncDblBufferHalfReady

Checks whether the next half buffer of data in circular buffer is ready for transfer during an asynchronous double-buffered analog input operation.

# D2K\_AI\_AsyncDblBufferToFile

Copies half of the data of circular buffer into a disk file.

# D2K\_AI\_AsyncDblBufferOverrun

Checks or clears overrun status of the double-buffered analog input operation.

# D2K\_AI\_AsyncDblBufferHandled

Notifies D2K-Dask the ready buffer has been handled in user application.

# D2K\_AI\_AsyncReTrigNextReady

Checks whether the data associated to the next trigger signal is ready during an asynchronous re-triggered analog input operation.

# 4.3 Analog Output Function Group

# 4.3.1 Analog output Configuration Functions

D2K\_AO\_CH\_Config Informs D2K-DASK library of the reference voltage value selected for an analog output channel of DAQ-2000 Device. You must call this function before calling function to perform voltage output operation.
D2K\_AO\_Config Informs D2K-DASK library of trigger source, trigger mode, output mode and trigger properties for the analog output operation of DAQ-2000 device. You must call this function before calling function to perform continuous analog output operation of DAQ-2000 device.
Gets the actual size of analog output DMA memory that is available in the device driver.
Assigns one or more analog output channels to a waveform generation group.
Informs D2K-DASK library of stop source and stop mode for the asynchronous analog output operation of a specified group.

# D2K\_AO\_InitialMemoryAllocated

# D2K\_AO\_Group\_Setup

# D2K\_AO\_Group\_WFM\_StopConfig

# 4.3.2 One-Shot Analog Output Functions

# D2K\_AO\_WriteChannel

Writes a binary value to the specified analog output channel.

# D2K\_AO\_SimuWriteChannel

Writes binary values to the specified analog output channels simultaneously. This function is only available for Simultaneous DA card.

# D2K\_AO\_VWriteChannel

Accepts a voltage value, scales it to the proper binary value and writes a binary value to the specified analog output channel.

D2K\_AO\_VoltScale Scales a voltage to a binary value.

# D2K\_AO\_Group\_Update

Writes binary values to the specified group of analog output channels simultaneously.

# D2K\_AO\_Group\_VUpdate

Accepts voltage values, scales them to the proper binary values and writes binary values to the specified group of analog output channels simultaneously.

# 4.3.3 Continuous Analog Output Functions

D2K\_AO\_ContWriteChannel Performs continuous analog output on the specified analog output port at a rate as close to the rate you specified.

# D2K\_AO\_ContWriteMultiChannels

Performs continuous D/A conversions on the specified analog output channels at a rate as close to the rate you specified.

<table><tr><td>D2K_AO_ContStatus</td><td>Checks the current status of the continuous analog output operation.</td></tr><tr><td>D2K_AO_EventCallBack</td><td>Controls and notifies the user&#x27;s application when a specified DAQ event occurs. The notification is performed through a user-specified callback function.</td></tr><tr><td>D2K_AO_ContBufferSetup</td><td>This function set up the buffer for continuous analog output</td></tr><tr><td>D2K_AO_ContReset</td><td>This function reset all the buffers set by function D2K_AO_ContBufferSetup for continuous analog output</td></tr><tr><td>D2K_AO_ContBufferCompose</td><td>The function organizes the data for each channel and filled them in the buffer for continuous analog output operation</td></tr><tr><td>D2K_AO_ContBufferComposeAll</td><td>The function fills the data for a specified channel in the buffer for continuous analog output operation</td></tr><tr><td>D2K_AO_Group_FIFOLoad</td><td>Loads a waveform buffer to on-board DA FIFOs</td></tr><tr><td>D2K_AO_Group_WFM_Start</td><td>Performs continuous D/A conversions on the specified group of analog output channels at a rate as close to the rate you specified.</td></tr></table>

# 4.3.4 Asynchronous Analog Output Monitoring Functions

<table><tr><td>D2K_AO_AsyncCheck</td><td>Checks the current status of the asynchronous analog output operation.</td></tr><tr><td>D2K_AO_AsyncClear</td><td>Stops the asynchronous analog output operation.</td></tr><tr><td>D2K_AO_AsyncDblBufferMode</td><td>Enables or Disables double buffer data acquisition mode.</td></tr></table>

<table><tr><td>D2K_AO_AsyncDbIBufferHalfReady</td></tr><tr><td>Checks whether the next half buffer of data in circular buffer is ready during an asynchronous double-buffered analog output operation.</td></tr></table>

<table><tr><td>D2K_AO_Group_WFM_AsyncCheck</td></tr><tr><td>Checks the current status of the asynchronous analog output operation of a specified group.</td></tr></table>

<table><tr><td>D2K_AO_Group_WFM_AsyncClearStops the asynchronous analog output operation of a specified group.</td></tr></table>

# 4.4 Digital Input Function Group

# 4.4.1 One-Shot Digital Input Functions

<table><tr><td>D2K_DI_ReadLine</td><td>Reads the digital logic state of the specified digital line in the specified port.</td></tr><tr><td>D2K_DI_ReadPort</td><td>Reads digital data from the specified digital input port.</td></tr></table>

# 4.5 Digital Output Function Group

# 4.5.1 One-Shot Digital Output Functions

<table><tr><td>D2K_DO_WriteLineSets the specified digital output line in the specified digital output port to the specified state. This function is only available for those cards that support digital output read-back functionality.</td></tr><tr><td>D2K_DO_WritePortWrites digital data to the specified digital output port.</td></tr><tr><td>D2K_DO_ReadLine</td></tr></table>

# 4.6 General Timer/Counter Function Group

# 4.6.1 The General-Purpose Timer/Counter Functions

<table><tr><td>D2K_GCTR_Setup</td><td>Controls the general-purpose counter to operate in the specified mode.</td></tr><tr><td>D2K_GCTR_Read</td><td>Reads the counter value of the general-purpose counter without disturbing the counting process.</td></tr><tr><td>D2K_GCTR_Control</td><td>Controls for the selected counter/timer by software</td></tr><tr><td>D2K_GCTR_Reset</td><td>Halts the specified general-purpose timer/counter operation and reload the initial value of the timer/counter.</td></tr><tr><td>D2K_GCTR_Status</td><td>Reads the counter value of the general-purpose counter without disturbing the counting process.</td></tr></table>

# 4.7 DIO Function Group

# 4.7.1 Digital Input/Output Configuration Functions

D2K\_DIO\_PortConfig This function is only used by the Digital I/O cards whose I/O port can be set as input port or output port. This function informs D2K-DASK library of the port direction selected for the digital input/output operation. You must call this function before calling functions to perform digital input/output operation.

# 4.8 SSI Function Group

D2K\_SSI\_SourceConn Connets a device to the specified SSI bus trigger line. D2K\_SSI\_SourceDisConn Disconnects a device signal from the specified SSI bus trigger line. D2K\_SSI\_SourceClear Disconnects a device signal from the specified SSI bus trigger line

# 4.9 Calibration Function Group

D2K\_DB\_Auto\_Calibration\_ALL Calibrates your DAQ-2000 device D2K\_EEPROM\_CAL\_Constant\_Update Save new calibration constants to the specified bank of EEPROM D2K\_Load\_CAL\_Data Load calibration constants from the specified bank of EEPROM DAQ2010\_Acquire\_AD\_Error Acquires the offset and gain errors of the specified AI channel in the specified polarity mode DAQ2010\_Acquire\_DA\_Error Acquires the offset and gain errors of the specified DA channel in the specified polarity mode DAQ2005\_Acquire\_AD\_Error Acquires the offset and gain errors of the specified AI channel in the specified polarity mode DAQ2005\_Acquire\_DA\_Error Acquires the offset and gain errors of the specified DA channel in the specified polarity mode

# DAQ2006\_Acquire\_AD\_Error

Acquires the offset and gain errors of the specified AI channel in the specified polarity mode

# DAQ2006\_Acquire\_DA\_Error

Acquires the offset and gain errors of the specified DA channel in the specified polarity mode

# DAQ2204\_Acquire\_AD\_Error

Acquires the offset and gain errors of ADC

# DAQ2204\_Acquire\_DA\_Error

Acquires the offset and gain errors of the specified DA channel in the specified polarity mode

# DAQ2205\_Acquire\_AD\_Error

Acquires the offset and gain errors of ADC

# DAQ2205\_Acquire\_DA\_Error

Acquires the offset and gain errors of the specified DA channel in the specified polarity mode

# DAQ2206\_Acquire\_AD\_Error

Acquires the offset and gain errors of ADC

# DAQ2206\_Acquire\_DA\_Error

Acquires the offset and gain errors of the specified DA channel in the specified polarity mode

# DAQ2208\_Acquire\_AD\_Error

Acquires the offset and gain errors of ADC

# DAQ2213\_Acquire\_AD\_Error

Acquires the offset and gain errors of ADC

# DAQ2214\_Acquire\_AD\_Error

Acquires the offset and gain errors of ADC

# DAQ2214\_Acquire\_DA\_Error

Acquires the offset and gain errors of the specified DA channel in the specified polarity mode

# DAQ250X\_Acquire\_DA\_Error

Acquires the offset and gain errors of the specified DA channel in the specified polarity mode

# DAQ250X\_Acquire\_AD\_Error

Acquires the offset and gain errors of ADC

# 5

# D2K-DASK Application Hints

This chapter provides the programming schemes showing the function flow of that D2K-DASK performs analog I/O and digital I/O.

The figure below shows the basic building blocks of a D2K-DASK application. However, except using Register\_Card at the beginning and Release\_Card at the end, depending on the specific devices and applications you have, the D2K-DASK functions comprising each building block vary.

![The flowchart depicts a linear, four-step process flowing vertically downwards. The blocks and connections are as follows:\n\n1.  **Top Block:** Labeled '**D2K_Regiser_Card**'.\n2.  **Connection:** A downward arrow connects this block to the one below.\n3.  **Second Block:** Labeled '**Configuration Function**'.\n4.  **Connection:** A downward arrow connects this block to the one below.\n5.  **Third Block:** Labeled '**AI/AO/DI//DO**' on the top line and '**Operation Function**' on the bottom line.\n6.  **Connection:** A downward arrow connects this block to the final one.\n7.  **Bottom Block:** Labeled '**D2K_Release_Card**'.](.d2k-dask-manual-1/ab25fc4ef44bc510a0d2dce31cd1b0df64191c07c4edab595e4da097ee190d34.jpg)

The programming schemes for analog input/output and digital input/output are described individually in the following sections.

# 5.1 Analog Input Programming Hints

D2K-DASK provides two kinds of analog input operation  nonbuffered single-point analog input readings and buffered continuous analog input operation.

The non-buffered single-point AI uses software polling method to read data from the device. The programming scheme for this kind of AI operation is described in section 5.1.1.

The buffered continuous analog input uses DMA transfer method to transfer data from device to user’s buffer. The maximum number of count in one transfer depends on the size of initially allocated memory for analog input in the driver. The driver allocates the memory at system boot time (in Window NT) or Windows startup time (in Window 98). We recommend the applications use D2K\_AI\_InitialMemoryAllocated function to get the size of initially allocated memory before performing continuous AI operation.

The buffered continuous analog input includes:

- synchronous continuous AI
- non-double-buffered asynchronous continuous AI
- double-buffered asynchronous continuous AI
- pre/middle triggered non-double-buffered asynchronous continuous AI
- pre/middle triggered double-buffered asynchronous continuous AI

They are described in section 5.1.2 to 5.1.7 section respectively. About the special consideration and performance issues for the buffered continuous analog input, please refer to the Continuous Data Transfer in D2K-DASK chapter for the details.

# 5.1.1 One-Shot Analog input programming Scheme

This section described the function flow typical of non-buffered single-point analog input readings.

a. all types of DAQ-2000 series

![The flowchart begins with a rectangular block labeled **D2K_AI_CH_Config**, which has an arrow pointing downward to a diamond-shaped decision block labeled **Voltage reading ?**.\n\nFrom the **Voltage reading ?** block:\n*   An arrow labeled **No** points left to a rectangular block labeled **D2K_AI_ReadChannel/** on the top line and **D2K_AI_SimuReadChannel** on the bottom line.\n*   An arrow labeled **Yes** points right to a rectangular block labeled **D2K_AI_VReadChannel**.\n\nArrows from both of these rectangular blocks converge and point downward to a second diamond-shaped decision block labeled **Another reading ?**.\n\nFrom the **Another reading ?** block:\n*   An arrow labeled **Yes** loops back to the left and points upward to the line connecting the initial block to the first decision diamond.\n*   An arrow labeled **No** points downward to terminate the flow.](.d2k-dask-manual-1/3a3ff485eb693efea51e201ac2789e63f074f14b827be4acf3578d8d1d4e832d.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_CH\_Config (card, channelNo, AD\_B\_10\_V);

D2K\_AI\_ReadChannel(card, channelNo, &analog\_input[i]);

D2K\_Release\_Card(card);

![This flowchart depicts a process with three main stages connected by arrows:\n\n1.  **Top Block:** A rectangle labeled 'D2K_AI_MuxScanSetup'. To its right is the text 'Fills channel/gain queue'. An arrow points downward from this block.\n2.  **Middle Block:** A rectangle labeled 'D2K_AI_ReadMuxScan'. An arrow points downward from this block to a decision diamond.\n3.  **Bottom Block:** A diamond shape labeled 'Another reading ?'.\n    *   **'Yes' Path:** An arrow labeled 'Yes' exits the left side of the diamond and loops back upward to enter the left side of the 'D2K_AI_ReadMuxScan' block.\n    *   **'No' Path:** An arrow labeled 'No' exits the bottom of the diamond and points downward, indicating the end of the loop.](.d2k-dask-manual-1/253c377600eba7350fba94b08f8ddafde12177916ca632d1bf858ee8185ac681.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2204, card\_number);

CHANNELCOUNT = 1;

chans[0] = 0;

ranges[0] = AD\_B\_10\_V| AI\_RSE;

D2K\_AI\_MuxScanSetup(card, CHANNELCOUNT, chans, ranges);

D2K\_AI\_ReadMuxScan (card, chan\_data);

D2K\_Release\_Card(card);

# 5.1.2 Continuous Analog input (with initial default settings) programming Scheme

This section described the function flow typical of synchronous analog input operation performed by the device with initial default configuration. For synchronous AI, the SyncMode argument in continuous AI functions has to be set as SYNCH\_OP and for asynchronous AI, the SyncMode argument has to be set as ASYNCH\_OP.

Initial default channel configuration:

<table><tr><td>AD data range</td><td>AD_B_10_V</td></tr><tr><td>Reference ground (only available for DAQ-2204, DAQ-2205, DAQ-2206 and DAQ-2208)</td><td>AI_RSE</td></tr></table>

Initial default AI configuration:

<table><tr><td>A/D Conversion source</td><td>DAQ2K_AI_ADCONVSRC_Int (Internal timer pacer)</td></tr><tr><td>A/D Trigger mode</td><td>DAQ2K_AI_TRGMOD_POST (post trigger)</td></tr><tr><td>A/D Trigger source</td><td>DAQ2K_AI_TRGSRC_SOFT (software trigger)</td></tr><tr><td>Auto buffer reset</td><td>TRUE</td></tr></table>

# a. Synchronous Operation

![The flowchart describes a process for setting up and running continuous analog input operations.\n\n**Labeled Blocks:**\n1.  **Register_Card** (Rectangle)\n2.  **D2K_AI_ContBufferSetup** (Rectangle)\n3.  **Sample multiple continuous chans?** (Diamond)\n4.  **D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile** (Rectangle)\n5.  **D2K_AI_ContReadChannel/ D2K_AI_ContReadChannelToFile** (Rectangle)\n6.  **Scale to voltage?** (Diamond)\n7.  **D2K_AI_ContVScale** (Rectangle)\n\n**Connections:**\n*   **Register_Card** connects via a downward arrow to **D2K_AI_ContBufferSetup**.\n*   **D2K_AI_ContBufferSetup** connects via a downward arrow to **Sample multiple continuous chans?**.\n*   From **Sample multiple continuous chans?**, the flow splits:\n    *   A leftward arrow labeled **'Yes'** and **'With SyncMode=SYNCH_OP'** leads to **D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile**.\n    *   A rightward arrow labeled **'No'** and **'With SyncMode=SYNCH_OP'** leads to **D2K_AI_ContReadChannel/ D2K_AI_ContReadChannelToFile**.\n*   Downward arrows from both the **D2K_AI_ContScanChannels...** block and the **D2K_AI_ContReadChannel...** block merge and point to **Scale to voltage?**.\n*   A downward arrow from **Scale to voltage?** leads to **D2K_AI_ContVScale**.\n*   From **D2K_AI_ContVScale**, there are two paths:\n    *   A downward arrow pointing out of the bottom of the block.\n    *   A feedback loop arrow exiting the right side, moving up, and entering the right side of the **Scale to voltage?** diamond.](.d2k-dask-manual-1/fd48fe792d270a7bbe93170e6ad296a2895f80cd9767a4f85a75f49adb3f6c02.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &Id);

D2K\_AI\_ContScanChannels (card, channel, Id, data\_size/(channel+1), scan\_intrv, samp\_intrv, SYNCH\_OP); or

D2K\_AI\_ContReadChannel(card, channel, Id, data\_size, scan\_intrv, samp\_intrv, SYNCH\_OP)

D2K\_Release\_Card(card);

# b. Non-Double Buffered Asynchronous Operation

![Here is the accurate description of the flowchart blocks and connections:\n\n*   **Block:** `Register_Card`\n    *   **Connection:** Points down to `D2K_AI_ContBufferSetup`.\n*   **Block:** `D2K_AI_ContBufferSetup`\n    *   **Connection:** Points down to the decision diamond `Sample multiple continuous chans?`.\n*   **Decision:** `Sample multiple continuous chans?`\n    *   **Connection (Yes):** Points left to a block labeled above with `With SyncMode =ASYNCH OP`. The block text is `D2K_AI_ContScanChannels/D2K_AI_ContScanChannelsToFile`.\n    *   **Connection (No):** Points right to a block labeled above with `With SyncMode =ASYNCH OP`. The block text is `D2K_AI_ContReadChannel/D2K_AI_ContReadChannelToFile`.\n*   **Convergence:** Both blocks listed above have arrows pointing down to a single path leading to `D2K_AI_AsyncCheck`.\n*   **Block:** `D2K_AI_AsyncCheck`\n    *   **Connection:** Points down to the decision diamond `Operation complete?`.\n*   **Decision:** `Operation complete?`\n    *   **Connection (No):** Loops back up to the input of `D2K_AI_AsyncCheck`.\n    *   **Connection (Yes):** Points down to `D2K_AI_AsyncClear`.\n*   **Block:** `D2K_AI_AsyncClear`\n    *   **Connection:** Points downward (exit).](.d2k-dask-manual-1/8744a5601f3dcad9b851bf65282859e4dc3ca74bd17a9678b72b655b15435b97.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_AI\_ContScanChannels (card, channel, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP); or

D2K\_AI\_ContReadChannel(card, channel, BufId, data\_size, ScanIntrv, SampIntrv, ASYNCH\_OP) do {

D2K\_AI\_AsyncCheck(card, &bStopped, &count); } while (!bStopped);

D2K\_AI\_AsyncClear(card, &StartPos, &count);

D2K\_Release\_Card(card);

c. Double Buffered Asynchronous Operation

![The flowchart describes a process starting with card registration and buffer mode setup, branching based on channel sampling, looping through buffer readiness checks, and ending with a clear operation.\n\n**Blocks and Connections:**\n\n1.  **Register_Card**: An arrow labeled **'With Enable=TRUE'** points downward to the next block.\n2.  **D2K_AI_AsyncDblBufferMode**: An arrow points downward to a decision diamond.\n3.  **Sample multiple continuous chans?**: This diamond branches into two paths:\n    *   **Yes**: An arrow labeled **'Yes'** points left and down. A label **'With SyncMode =ASYNC_OP'** is next to it. It leads to the block **'D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile'**.\n    *   **No**: An arrow labeled **'No'** points right and down. A label **'With SyncMode =ASYNC_OP'** is next to it. It leads to the block **'D2K_AI_ContReadChannel/ D2K_AI_ContReadChannelToFile'**.\n4.  Both of the blocks above ('D2K_AI_ContScanChannels...' and 'D2K_AI_ContReadChannel...') have arrows pointing downward that merge into a single path.\n5.  This path leads to the block **D2K_AI_AsyncDblBufferHalfReady**.\n6.  An arrow points downward to the diamond **Next half buffer ready for transfer?**.\n    *   **No**: An arrow labeled **'No'** loops back to the left and upward, pointing into the top of the **D2K_AI_AsyncDblBufferHalfReady** block.\n    *   **Yes**: An arrow labeled **'Yes'** points downward.\n7.  The 'Yes' path leads to the block **Handling the ready data .../ D2K_AI_AsyncDblBufferToFile**.\n8.  An arrow points downward to the diamond **Want to stop the operation?**.\n    *   **No**: An arrow labeled **'No'** loops back to the left and upward, extending all the way up to point into the top of the **D2K_AI_AsyncDblBufferHalfReady** block.\n    *   **Yes**: An arrow labeled **'Yes'** points downward.\n9.  The 'Yes' path leads to the final block **D2K_AI_AsyncClear**. An arrow points downward from this block, indicating the end of the process.](.d2k-dask-manual-1/927758cc0a84bdcf13bd83da9723b5c714eaebbec249ada0776a41b84db857b9.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_AsyncDblBufferMode (card, 1); // Double-buffered AI

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_A\_ContBufferSetup (card, ai\_buf2, data\_size, &BufId);

D2K\_AI\_ContScanChannels (card, channel, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP); or

D2K\_AI\_ContReadChannel(card, channel, BufId, data\_size, ScanIntrv, SampIntrv, ASYNCH\_OP) do {

do { D2K\_AI\_AsyncDblBufferHalfReady(card, &HalfReady, &fstop); } while (!HalfReady);

//Handling the ready data

} while (!clear\_op);

D2K\_AI\_AsyncClear(card, &startPos, &count);

D2K\_Release\_Card(card);

# 5.1.3 Post Trigger Mode/ Delay Trigger Mode Synchronous Continuous Analog input programming Scheme

This section described the function flow typical of post trigger or delay triggered synchronous analog input operation. While performing continuous AI operation, the AI configuration function has to be called at the beginning of your application. In addition, for synchronous AI, the SyncMode argument in continuous AI functions has to be set as SYNCH\_OP.

a. all types of DAQ-2000 series

![The flowchart begins at the top with a block labeled **D2K_AI_CH_Config**. An arrow points downward to a block labeled **D2K_AI_Config / D2K_AI_PostTrig_Config**.\n\nFrom there, the flow proceeds to a decision diamond labeled **External timer base?**:\n*   The **Yes** branch points left to a block labeled **D2K_AIO_Config**. Above this block is text reading 'With TimerBase = DAQ2K_ExtTimeBase'. An arrow from this block flows downward and joins the main path.\n*   The **No** branch points downward to a block labeled **D2K_AI_ContBufferSetup**.\n\nFrom the **D2K_AI_ContBufferSetup** block, an arrow points to a decision diamond labeled **Sample multiple continuous chans?**:\n*   The **Yes** branch points left to a block labeled **D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile**. Above this block is text reading 'With SyncMode =SYNCH_OP'. An arrow flows downward from this block.\n*   The **No** branch points right to an empty rectangular block. Above this block is text reading 'With SyncMode =SYNCH_OP'. An arrow flows downward from this block.\n\nBoth arrows merge and point to a decision diamond labeled **Scale to voltage?**:\n*   The **Yes** branch points downward to a block labeled **D2K_AI_ContVScale**. An arrow flows downward from this block.\n*   The **No** branch (implied by the line extending to the right) curves downward and joins the main downward arrow.\n\nThe final arrow points downward, indicating the end of the process.](.d2k-dask-manual-1/dcde32c3d27203c1f058d1da3d818dd8daa4fa69aa266c12794f161735e1db6b.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_CH\_Config (card, channel, range )

D2K\_AI\_Config (card, 0, DAQ2K\_AI\_TRGMOD\_POST| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 0, 1);

// or

// D2K\_AI\_PostTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 1);

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &Id);

D2K\_AI\_ContScanChannels (card, channel, Id, data\_size/(channel+1), scan\_intrv, samp\_intrv, SYNCH\_OP); or

D2K\_AI\_ContReadChannel(card, channel, Id, data\_size, scan\_intrv, samp\_intrv, SYNCH\_OP)

D2K\_Release\_Card(card);

![The flowchart proceeds as follows:\n\n1.  **D2K_AI_MuxScanSetup** connects downward to **D2K_AI_Config / D2K_AI_PostTrig_Config**.\n2.  This block connects to the decision diamond **External timer base?**.\n    *   The **Yes** path leads left to the block **D2K_AIO_Config** (which has the note 'With TimerBase = DAQ2K_ExtTimeBase' above it). The arrow from this block then curves back to join the main downward path.\n    *   The **No** path leads directly downward.\n3.  Both paths merge and connect to **D2K_AI_ContBufferSetup**.\n4.  This block connects downward to **D2K_AI_ContMuxScan**.\n5.  This block connects downward to the decision diamond **Scale to voltage?**.\n    *   The downward path leads to **D2K_AI_ContVScale**.\n    *   The rightward path loops down to bypass the scaling block and join the final output arrow.](.d2k-dask-manual-1/b7ab3b9c01d9f6e44a47d19d66c54bc86da8fbdc796b0c80d43c5092925db868.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2205, card\_number);

CHANNELCOUNT = 1;

chans[0] = 0;

ranges[0] = AD\_B\_10\_V| AI\_RSE;

D2K\_AI\_MuxScanSetup(card, CHANNELCOUNT, chans, ranges);

D2K\_AI\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGMOD\_POST| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 0, 1);

// or

// D2K\_AI\_PostTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 1);

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &Id);

D2K\_AI\_ContMuxScan (card, Id, data\_size/CHANNELCOUNT, SAMPLE\_INTERVAL\*CHANNELCOUNT, SAMPLE\_INTERVAL, SYNCH\_OP);

D2K\_Release\_Card(card);

# 5.1.4 Post Trigger Mode/ Delay Trigger Mode Non-double-buffered Asynchronous Continuous Analog input programming Scheme

This section described the function flow typical of post trigger or delay triggered, non-double-buffered asynchronous analog input operation. While performing continuous AI operation, the AI configuration function has to be called at the beginning of your application. In addition, for asynchronous AI, the SyncMode argument in continuous AI functions has to be set as ASYNCH\_OP.

a. all types of DAQ-2000 series

![The flowchart begins with a block labeled **D2K_AI_CH_Config**, which flows into **D2K_AI_Config / D2K_AI_PostTrig_Config or D2K_AI_DelayTrig_Config**.\n\nThe next step is a decision diamond labeled **External Timer Base**:\n*   **Yes**: Leads to a block labeled **D2K_AIO_Config**, which then merges back into the main flow.\n*   **No**: Proceeds directly downward.\n\nBoth paths converge into a block labeled **D2K_AI_ContBufferSetup**.\n\nFrom there, the flow reaches a decision diamond labeled **Sample multiple continuous chans?**:\n*   **Yes**: Leads to the left branch. Above the branch, text reads **With SyncMode = ASYNCH OP**. The block below reads **D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile**.\n*   **No**: Leads to the right branch. Above the branch, text reads **With SyncMode = ASYNCH OP**. The block below reads **D2K_AI_ContReadChannel/ D2K_AI_ContReadChannelToFile**.\n\nBoth branches merge into a block labeled **D2K_AI_AsyncCheck**.\n\nThis leads to a decision diamond labeled **Operation complete?**:\n*   **No**: Loops back upward to **D2K_AI_AsyncCheck**.\n*   **Yes**: Proceeds downward to a block labeled **D2K_AI_AsyncClear**, which then points to an end arrow.](.d2k-dask-manual-1/ec8c25a754cdbdad8404c625cd74cd354479ef64fcc3944cf4e53c41cbb77ae0.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_CH\_Config (card, channel, range )

D2K\_AI\_Config (card, 0, DAQ2K\_AI\_TRGMOD\_POST| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 0, 1);

// D2K\_AI\_PostTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 1);

D2k\_AI\_AsyncDblBufferMode (card, 0); //non-double-buffered AI

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_AI\_ContScanChannels (card, channel, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP); or

D2K\_AI\_ContReadChannel(card, channel, BufId, data\_size, ScanIntrv, SampIntrv, ASYNCH\_OP) do {

D2K\_AI\_AsyncCheck(card, &bStopped, &count); } while (!bStopped);

D2K\_AI\_AsyncClear(card, &StartPos, &count);

D2K\_Release\_Card(card);

b. Fills channel gain queue first – only available for DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2208

![The flowchart describes a process flow with the following labeled blocks and connections:\n\n1.  **D2K_AI_MuxScanSetup** flows down into **D2K_AI_Config / D2K_AI_PostTrig_Config or D2K_AI_DelayTrig_Config**.\n2.  This flows into a decision diamond labeled **External Timer Base**.\n    *   The **'Yes'** path leads left to **D2K_AIO_Config**, which then flows down to merge with the main path.\n    *   The **'No'** path flows directly down.\n3.  Both paths merge into **D2K_AI_ContBufferSetup**.\n4.  An arrow labeled **With SyncMode = ASYNCH_OP** points down to **D2K_AI_ContMuxScan / D2K_AI_ContMuxScanToFile**.\n5.  This flows into **D2K_AI_AsyncCheck**.\n6.  This flows into a decision diamond labeled **Operation complete?**.\n    *   The **'No'** path loops back up to the input of **D2K_AI_AsyncCheck**.\n    *   The **'Yes'** path flows down to **D2K_AI_AsyncClear**.\n7.  The process ends with an arrow pointing down from **D2K_AI_AsyncClear**.](.d2k-dask-manual-1/6101f70ba938b326db449714389676675038a933dc95f38608e9b0a9709eb803.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2205, card\_number);

CHANNELCOUNT = 1;

chans[0] = 0;

ranges[0] = AD\_B\_10\_V| AI\_RSE;

D2K\_AI\_MuxScanSetup(card, CHANNELCOUNT, chans, ranges);

D2K\_AI\_Config (card, 0, DAQ2K\_AI\_TRGMOD\_POST| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 0, 1);

// or

// D2K\_AI\_PostTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 1);

D2k\_AI\_AsyncDblBufferMode (card, 0); //non-double-buffered AI

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_AI\_ContMuxScan (card, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP);

D2K\_AI\_AsyncCheck(card, &bStopped, &count);

} while (!bStopped);

D2K\_AI\_AsyncClear(card, &StartPos, &count);

D2K\_Release\_Card(card);

# 5.1.5 Post Trigger Mode/ Delay Trigger Mode Double-buffered Asynchronous Continuous Analog input programming Scheme

This section described the function flow typical of post trigger or delay triggered, double-buffered asynchronous analog input operation. While performing continuous AI operation, the AI configuration function has to be called at the beginning of your application. For asynchronous AI, The SyncMode argument in continuous AI functions has to be set as ASYNCH\_OP. In addition, double-buffered AI operation is enabled by setting Enable argument of D2K\_AI\_AsyncDblBufferMode function to 1. To learn more about double buffer mode, please refer to section 5.2 Double-Buffered AI/DI Operation for the details.

a. all types of DAQ-2000 series

![The flowchart begins with **D2K_AI_CH_Config**, which connects to **D2K_AI_Config/D2K_AI_PostTrig_Config//D2K_AI_DelayTrig_Config**.\n\nFrom there, the flow enters a decision diamond labeled **External timer base?**:\n*   The **yes** path leads to **D2K_AIO_Config**, which then rejoins the main vertical flow.\n*   The **No** path continues downward.\n\nThe next block is **D2K_AI_ContBufferSetup D2K_AI_ContBufferSetup**.\n*   An arrow labeled **With Enable=TRUE** leads to **D2K_AI_AsyncDblBufferMode**.\n\nThis connects to a decision diamond: **Sample multiple continuous chans?**:\n*   The **Yes** path (labeled **With SyncMode =ASYNH_OP**) leads to **D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile**.\n*   The **No** path (labeled **With SyncMode =ASYNH_OP**) leads to **D2K_AI_ContReadChannel/ D2K_AI_ContReadChannelToFile**.\n\nBoth paths merge into **D2K_AI_AsyncDblBufferHalfReady**.\n\nBelow that is a decision diamond: **ready for transfer ? Next half buffer**:\n*   The **No** path loops back upward.\n*   The **Yes** path leads to **Handling the ready data ...or D2K_AI_AsyncDblBufferToFile**.\n\nThis connects to a final decision diamond: **operation want to stop?**:\n*   The **No** path loops back upward.\n*   The **Yes** path leads to **D2K_AI_AsyncClear**, followed by a downward arrow indicating the end.](.d2k-dask-manual-1/35cb7fbc481a992077caaa4aa0cc888a2a25952d50ebc2fd2a8a4621b403e59e.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_CH\_Config (card, channel, range )

D2K\_AI\_Config (card, 0, DAQ2K\_AI\_TRGMOD\_POST| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 0, 1);

// D2K\_AI\_PostTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 1);

D2K\_AI\_AsyncDblBufferMode (card, 1); // Double-buffered AI

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_A\_ContBufferSetup (card, ai\_buf2, data\_size, &BufId);

D2K\_AI\_ContScanChannels (card, channel, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP);

or

D2K\_AI\_ContReadChannel(card, channel, BufId, data\_size, ScanIntrv, SampIntrv, ASYNCH\_OP)

do {

D2K\_AI\_AsyncDblBufferHalfReady(card, &HalfReady, &fstop);

} while (!HalfReady);

//Handling the ready data

} while (!clear\_op);

D2K\_AI\_AsyncClear(card, &startPos, &count);

D2K\_Release\_Card(card);

b. Fills channel gain queue first – only available for DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2208

![**Blocks:**\n*   D2K_AI_MuxScanSetup\n*   D2K_AI_Config/D2K_AI_PostTrig_Config//D2K_AI_DelayTrig_Config\n*   D2K_AIO_Config\n*   External timer base?\n*   D2K_AI_ContBufferSetup\n*   D2K_AI_ContBufferSetup\n*   D2K_AI_AsyncDblBufferMode\n*   D2K_AI_ContMuxScan /\n*   D2K_AI_ContMuxScanToFile\n*   D2K_AI_AsyncDblBufferHalfReady\n*   ready for transfer ?\n*   Next half buffer\n*   Handling the ready data ...or D2K_AI_AsyncDblBufferToFile\n*   operation want to stop?\n*   D2K_AI_AsyncClear\n\n**Connections:**\n*   From **D2K_AI_MuxScanSetup** to **D2K_AI_Config/D2K_AI_PostTrig_Config//D2K_AI_DelayTrig_Config**.\n*   From **D2K_AI_Config/D2K_AI_PostTrig_Config//D2K_AI_DelayTrig_Config** to **External timer base?**.\n*   From **External timer base?** labeled **yes** to **D2K_AIO_Config**.\n*   From **D2K_AIO_Config** to the main flow below **External timer base?**.\n*   From **External timer base?** labeled **No** to **D2K_AI_ContBufferSetup** / **D2K_AI_ContBufferSetup**.\n*   From **D2K_AI_ContBufferSetup** to **D2K_AI_AsyncDblBufferMode** (label: **With Enable=TRUE**).\n*   From **D2K_AI_AsyncDblBufferMode** to **D2K_AI_ContMuxScan / D2K_AI_ContMuxScanToFile** (label: **With SyncMode =ASYNCH_OP**).\n*   From **D2K_AI_ContMuxScan / D2K_AI_ContMuxScanToFile** to **D2K_AI_AsyncDblBufferHalfReady**.\n*   From **D2K_AI_AsyncDblBufferHalfReady** to **ready for transfer ? Next half buffer**.\n*   From **ready for transfer ? Next half buffer** labeled **No** loops back to **D2K_AI_AsyncDblBufferHalfReady**.\n*   From **ready for transfer ? Next half buffer** labeled **Yes** to **Handling the ready data ...or D2K_AI_AsyncDblBufferToFile**.\n*   From **Handling the ready data ...or D2K_AI_AsyncDblBufferToFile** to **operation want to stop?**.\n*   From **operation want to stop?** labeled **No** loops back to **D2K_AI_AsyncDblBufferHalfReady**.\n*   From **operation want to stop?** labeled **Yes** to **D2K_AI_AsyncClear**.](.d2k-dask-manual-1/a65c07444b2569d836e8a2671138c4f307f3af830ca74e1430631e05ca46a920.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2205, card\_number);

CHANNELCOUNT = 1;

chans[0] = 0;

ranges[0] = AD\_B\_10\_V| AI\_RSE;

D2K\_AI\_MuxScanSetup(card, CHANNELCOUNT, chans, ranges);

D2K\_AI\_Config (card, 0, DAQ2K\_AI\_TRGMOD\_POST| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 0, 1);

// D2K\_AI\_PostTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 1);

D2K\_AI\_AsyncDblBufferMode (card, 1); // Double-buffered AI

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_A\_ContBufferSetup (card, ai\_buf2, data\_size, &BufId);

D2K\_AI\_ContMuxScan (card, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP);

do {

do {

D2K\_AI\_AsyncDblBufferHalfReady(card, &HalfReady, &fstop);

} while (!HalfReady);

//Handling the ready data

} while (!clear\_op);

D2K\_AI\_AsyncClear(card, &startPos, &count);

D2K\_Release\_Card(card);

# 5.1.6 Pre-Trigger Mode/ Middle-Trigger Mode Non-double-buffered Asynchronous Continuous Analog input programming Scheme

This section described the function flow typical of Pre-trigger and middle trigger mode double-buffered asynchronous analog input operation. A trigger is an event that occurs based on a specified set of conditions. An interrupt mode or DMA-mode Analog input operation can use a trigger to determinate when acquisition stop. The trigger mode data acquisition programming is almost the same as the non-trigger mode asynchronous analog input programming. Using D2K-DASK to perform pre-trigger or middle mode data acquisition, the SyncMode of continuous AI should be set as ASYNCH\_OP.

a. all types of DAQ-2000 series

![The flowchart begins with a block labeled **D2K_AI_CH_Config**, which points downward to **D2K_AI_Config / D2K_AI_PreTrig_Config or D2K_AI_MiddleTrig_Config**. This leads to a decision diamond labeled **External Timer Base**.\n\n*   The **Yes** path leads left to a block labeled **D2K_AIO_Config**, which then points downward to merge back into the main flow.\n*   The **No** path continues downward to a block labeled **D2K_AI_ContBufferSetup**.\n\nFrom there, an arrow points to a decision diamond labeled **Sample multiple continuous chans?**.\n\n*   The **Yes** path (left) is labeled **With SyncMode =ASYNCH_OP** and leads to a block labeled **D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile**.\n*   The **No** path (right) is labeled **With SyncMode =ASYNCH_OP** and leads to a block labeled **D2K_AI_ContReadChannel/ D2K_AI_ContReadChannelToFile**.\n\nBoth paths merge into a single arrow pointing downward to a block labeled **D2K_AI_AsyncCheck**. This leads to a decision diamond labeled **Operation complete?**.\n\n*   The **No** path loops back up to the input of the **D2K_AI_AsyncCheck** block.\n*   The **Yes** path points downward to a final block labeled **D2K_AI_AsyncClear**, from which an arrow points downward indicating the end of the process.](.d2k-dask-manual-1/1c73856e8d9ec99fa4b4bb11592fb2e39be456f28e913de8dc73538d0ba37a1d.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AI\_CH\_Config (card, channel, range )

D2K\_AI\_Config (card, 0, DAQ2K\_AI\_TRGMOD\_PRE| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 0, 1);

// D2K\_AI\_PreTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, 0, 0, 1);

D2K\_AI\_AsyncDblBufferMode (card, 0); //non-double-buffered AI

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_AI\_ContScanChannels (card, channel, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP); or

D2K\_AI\_ContReadChannel(card, channel, BufId, data\_size, ScanIntrv, SampIntrv, ASYNCH\_OP)

do {

D2K\_AI\_AsyncCheck(card, &bStopped, &count);

} while (!bStopped);

D2K\_AI\_AsyncClear(card, &startPos, &count);

D2K\_Release\_Card(card);

b. Fills channel gain queue first – only available for DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2208

![The flowchart begins at the top with a block labeled **D2K_AI_MuxScanSetup**. An arrow points downward to a block labeled **D2K_AI_Config / D2K_AI_PostTrig_Config or D2K_AI_DelayTrig_Config**.\n\nFrom there, an arrow leads down to a diamond-shaped decision block labeled **External Timer Base**.\n*   A leftward arrow labeled **Yes** points to a block labeled **D2K_AIO_Config**.\n*   An arrow from **D2K_AIO_Config** goes down and merges with the downward path.\n*   A downward arrow labeled **No** originates from the diamond and merges with the path coming from **D2K_AIO_Config**.\n\nBoth paths converge into a downward arrow leading to a block labeled **D2K_AI_ContBufferSetup**.\n\nFollowing this block is a downward arrow labeled with the text **With SyncMode = ASYNCH_OP**. This arrow leads to a block labeled **D2K_AI_ContMuxScan / D2K_AI_ContMuxScanToFile**.\n\nAn arrow points downward to a block labeled **D2K_AI_AsyncCheck**, which then points down to a diamond-shaped decision block labeled **Operation complete?**.\n*   A leftward arrow labeled **No** loops back up to the arrow connecting the previous block (**D2K_AI_ContMuxScan / D2K_AI_ContMuxScanToFile**) and **D2K_AI_AsyncCheck**.\n*   A downward arrow labeled **Yes** leads to a block labeled **D2K_AI_AsyncClear**.\n\nFinally, an arrow points downward from **D2K_AI_AsyncClear**, indicating the end of the process.](.d2k-dask-manual-1/0f21507e7e713e3d951d679b05a4e92016408c48c382a42b41da0ed0746740a3.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2205, card\_number);

CHANNELCOUNT = 1;

chans[0] = 0;

ranges[0] = AD\_B\_10\_V| AI\_RSE;

D2K\_AI\_MuxScanSetup(card, CHANNELCOUNT, chans, ranges);

D2K\_AI\_Config (card, 0, DAQ2K\_AI\_TRGMOD\_MIDL| DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, POSTCOUNT, 0, 0, 1);

// or

// D2K\_AI\_MiddleTrig\_Config (card, DAQ2K\_AI\_ADCONVSRC\_Int, DAQ2K\_AI\_TRGSRC\_ExtD| DAQ2K\_AI\_TrgPositive, POSTCOUNT, 0, 0, 1);

D2K\_AI\_AsyncDblBufferMode (card, 0); //non-double-buffered AI

D2K\_AI\_ContBufferSetup (card, ai\_buf, data\_size, &BufId);

D2K\_AI\_ContMuxScan (card, BufId, data\_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH\_OP); do {

D2K\_AI\_AsyncCheck(card, &bStopped, &count); } while (!bStopped);

D2K\_AI\_AsyncClear(card, &startPos, &count);

D2K\_Release\_Card(card);

# 5.1.7 Pre-Trigger Mode/ Middle-Trigger Mode Double-buffered Asynchronous Continuous Analog input programming Scheme

This section described the function flow typical of trigger mode double-buffered asynchronous analog input operation. A trigger is an event that occurs based on a specified set of conditions. An interrupt mode or DMA-mode Analog input operation can use a trigger to determinate when acquisition stop. The trigger mode data acquisition programming is almost the same as the non-trigger mode asynchronous analog input programming. Using D2K-DASK to perform trigger mode data acquisition, the SyncMode of continuous AI should be set as ASYNCH\_OP. In addition, double-buffered AI operation is enabled by setting Enable argument of D2K\_AI\_AsyncDblBufferMode function to 1. To learn more about double buffer mode, please refer to section 5.2 Double-Buffered AI/DI Operation for the details.

a. all types of DAQ-2000 series

![The flowchart describes a process starting with configuration and moving through buffer setup, data handling, and finally clearing. Here are the labeled blocks and connections:\n\n1.  **D2K_AI_CH_Config** connects downward to **D2K_AI_Config/D2K_AI_PostTrig_Config//D2K_AI_DelayTrig_Config**.\n2.  From there, an arrow points to the decision diamond **External timer base?**.\n    *   The **yes** path leads to **D2K_AIO_Config**, which then connects downward to merge with the flow.\n    *   The **No** path leads downward.\n3.  The paths merge and lead to the block **D2K_AI_ContBufferSetup D2K_AI_ContBufferSetup**.\n4.  An arrow labeled **With Enable=TRUE** points to **D2K_AI_AsyncDblBufferMode**.\n5.  This leads to the decision diamond **Sample multiple continuous chans?**.\n    *   The **Yes** path (labeled **With SyncMode =ASYNH_OP**) leads to **D2K_AI_ContScanChannels/ D2K_AI_ContScanChannelsToFile**.\n    *   The **No** path (labeled **With SyncMode =ASYNH_OP**) leads to **D2K_AI_ContReadChannel/ D2K_AI_ContReadChannelToFile**.\n6.  Both branches merge and lead to **D2K_AI_AsyncDblBufferHalfReady**.\n7.  This leads to the decision diamond **Next Buffer ready for transfer?? Operation Complete?**.\n    *   The **No** path loops back upward to **D2K_AI_AsyncDblBufferHalfReady**.\n    *   The **Yes** path leads to **Handling the ready data ...or D2K_AI_AsyncDblBufferToFile**.\n8.  This leads to the decision diamond **operation want to stop?**.\n    *   The **No** path loops back upward to merge with the line entering **Next Buffer ready for transfer?? Operation Complete?**.\n    *   The **Yes** path leads to **D2K_AI_AsyncClear**.\n9.  The flowchart ends with a downward arrow from **D2K_AI_AsyncClear**.](.d2k-dask-manual-1/054bd024b085d60ecd77d1dd35d90dcb7549886e734c7fbb2ef7692ac67f51d5.jpg)

[Example Code Fragment]
```c
card = D2K_Register_Card(DAQ_2010, card_number);
...
D2K_AI_CH_Config (card, channel, range)
D2K_AI_Config (card, 0, DAQ2K_AI_TRGMOD_PRE|DAQ2K_AI_TRGSRC_ExtD, 0, 0, 0, 1);
// or
// D2K_AI_MiddleTrig_Config (card, DAQ2K_AI_ADCONVSRC_Int, DAQ2K_AI_TRGSRC_ExtD| DAQ2K_AI_TrgPositive, 0, 0, 1);
AI_AsyncDblBufferMode (card, 1); Double-buffered AI
D2K_AI_ContBufferSetup (card, ai_buf, data_size, &Bufld);
D2K_A_ContBufferSetup (card, ai_buf2, data_size, &Bufld);
D2K_AI_ContScanChannels (card, channel, Bufld, data_size/(channel+1), ScanIntrv, U32 SampIntrv, ASYNCH_OP); or
D2K_AI_ContReadChannel(card, channel, Bufld, data_size, ScanIntrv, U32 SampIntrv, ASYNCH_OP)
do {
    do {
    D2K_AI_AsyncDblBufferHalfReady(card, &HalfReady, &fstop);
    } while (!HalfReady && !fstop);

    // handling the ready data ...
    ...

} while (!clear_op && !fstop);

D2K_AI_AsyncClear(card, &startPos, &count);
...
D2K_Release_Card(card);
```

b. Fills channel gain queue first – only available for DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2208
![The flowchart depicts a sequential process with conditional loops. Here are the labeled blocks and connections in order:\n\n1.  **D2K_AI_MuxScanSetup**\n    *   Connects to **D2K_AI_Config/D2K_AI_PreTrig_Config//D2K_AI_MiddleTrig_Config**\n2.  **D2K_AI_Config/D2K_AI_PreTrig_Config//D2K_AI_MiddleTrig_Config**\n    *   Connects to the decision diamond: **External timer base?**\n    *   If **Yes**: Connects to **D2K_AIO_Config**, which then merges back into the main flow.\n    *   If **No**: Connects to **D2K_AI_ContBufferSetup / D2K_AI_ContBufferSetup** (Note: The text appears twice in the box).\n3.  **D2K_AI_ContBufferSetup / D2K_AI_ContBufferSetup**\n    *   Arrow labeled: **With Enable=TRUE**\n    *   Connects to **D2K_AI_AsyncDblBufferMode**\n4.  **D2K_AI_AsyncDblBufferMode**\n    *   Arrow labeled: **With SyncMode =ASYNCH_OP**\n    *   Connects to **D2K_AI_ContMuxScan / D2K_AI_ContMuxScanToFile**\n5.  **D2K_AI_ContMuxScan / D2K_AI_ContMuxScanToFile**\n    *   Connects to **D2K_AI_AsyncDblBufferHalfReady**\n6.  **D2K_AI_AsyncDblBufferHalfReady**\n    *   Connects to the decision diamond: **Next Buffer ready for transfer? / Operation Complete?**\n    *   If **No**: Loops back to **D2K_AI_AsyncDblBufferHalfReady**.\n    *   If **Yes**: Connects to **Handling the ready data ...or D2K_AI_AsyncDblBufferToFile**\n7.  **Handling the ready data ...or D2K_AI_AsyncDblBufferToFile**\n    *   Connects to the decision diamond: **Operation want to stop?**\n    *   If **No**: Loops back to **D2K_AI_AsyncDblBufferHalfReady**.\n    *   If **Yes**: Connects to **D2K_AI_AsyncClear**](.d2k-dask-manual-1/20bb0f8f0c58936719d8c06e62ed9afdea9213c82187ddb9a01ebb1c8e9c01d3.jpg)

[Example Code Fragment]
```c
card = D2K_Register_Card(DAQ_2205, card_number);
...
CHANNELCOUNT = 1;
chans[0] = 0;
ranges[0] = AD_B_10_V| AI_RSE;
D2K_AI_MuxScanSetup(card, CHANNELCOUNT, chans, ranges);
D2K_AI_Config (card, 0, DAQ2K_AI_TRGMOD_RRE| DAQ2K_AI_TRGSRC_ExtD| DAQ2K_AI_TrgPositive, 0, 0, 0, 1);
// or
// D2K_AI_PreTrig_Config (card, DAQ2K_AI_ADCONVSRC_Int, DAQ2K_AI_TRGSRC_ExtD| DAQ2K_AI_TrgPositive, 0, 0, 1);
D2K_AI_AsyncDblBufferMode (card, 1); // Double-buffered AI
D2K_AI_ContBufferSetup (card, ai_buf, data_size, &Bufld);
D2K_A_ContBufferSetup (card, ai_buf2, data_size, &Bufld);
D2K_AI_ContMuxScan (card, Bufld, data_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH_OP);
do {
    do {
    D2K_AI_AsyncDblBufferHalfReady(card, &HalfReady, &fstop);
    } while (!HalfReady);

    //Handling the ready data
    ...
} while (!clear_op);

D2K_AI_AsyncClear(card, &startPos, &count);
...
D2K_Release_Card(card);
```

# 5.2 Analog Output Programming Hints

D2K-DASK provides two kinds of analog output operation  non-buffered single-point analog output operation and buffered continuous analog output operation.

The non-buffered single-point AO uses software polling method to write data to the device. The programming scheme for this kind of AO operation is described in section 5.2.1.

The buffered continuous AO uses DMA transfer method to transfer data from user’s buffer to device. The maximum number of count in one transfer depends on the size of initially allocated memory for analog output in the driver. The driver allocates the memory at system boot time (in Window NT) or Windows startup time (in Window 98). We recommend the applications use D2K\_AO\_InitialMemoryAllocated function to get the size of initially allocated memory before start performing continuous AO operation.

About the special consideration and performance issues for the buffered continuous digital output, please refer to the Continuous Data Transfer in D2K-DASK chapter for the details.

# 5.2.1 One-Shot Analog output programming Scheme

This section described the function flow typical of non-buffered single-point digital output operation. While performing one-shot AO operation, the cards whose I/O port can be set as input or out put port need to include port configuration function at the beginning of your application.

a. DAQ-2005, DAQ-2006, DAQ-2010, DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2214

![The flowchart follows this sequence:\n\n1.  **Start:** A rectangular block labeled **'D2K_AO_CH_Config'** points downward to a decision diamond.\n2.  **Decision 1:** The diamond is labeled **'Output voltage?'**.\n    *   The **'No'** path points to a rectangular block labeled **'D2K_AO_WriteChannel/D2K AO SimuWriteChannel'**.\n    *   The **'Yes'** path points to a rectangular block labeled **'D2K_AO_VWriteChannel'**.\n3.  **Merge:** The paths from both rectangular blocks combine and point downward to a second decision diamond.\n4.  **Decision 2:** The diamond is labeled **'Another outputting?'**.\n    *   The **'Yes'** path loops back to the left and upward, re-entering the flow just before the 'Output voltage?' decision.\n    *   The **'No'** path points downward, indicating the end of the process.](.d2k-dask-manual-1/c7c3a61837c179eac10d234f521fbf06a5fcd8f813d79d9439b85de8df2151cc.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AO\_CH\_Config (card, 0, DAQ2K\_DA\_BiPolar, DAQ2K\_DA\_Int\_REF, 10.0); D2K\_AO\_WriteChannel(card, chan, out\_value);

D2K\_Release\_Card(card);

![The flowchart depicts a control loop process with the following steps:\n\n1.  **Start:** A rectangular block labeled with two lines of text: 'D2K_AO_CH_Config' and 'D2K_AO_Group_Setup'.\n2.  **Decision 1:** An arrow leads down to a diamond labeled 'Output voltage?'.\n    *   **No Path:** An arrow labeled 'No' points left to a rectangular block labeled 'D2K_AO_Group_Update'.\n    *   **Yes Path:** An arrow labeled 'Yes' points right to a rectangular block labeled 'D2K_AO_Group_VUpdate'.\n3.  **Convergence:** Arrows from both update blocks merge and point downward to a second diamond.\n4.  **Decision 2:** The diamond is labeled 'Another outputting?'.\n    *   **Yes Path:** An arrow labeled 'Yes' loops back to the left and up, reconnecting to the flow between the initial block and the first diamond (looping back to the 'Output voltage?' decision).\n    *   **No Path:** An arrow labeled 'No' points downward, indicating the end of the process.](.d2k-dask-manual-1/88142e73e4b7e2612a22509c4ed1c4b64ea308f79bc02142a618729f7cda51ac.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2501, card\_number);

da\_ch = 0;

D2K\_AO\_CH\_Config (card, da\_ch, DAQ2K\_DA\_BiPolar, DAQ2K\_DA\_Int\_REF, 10.0);

D2K\_AO\_Group\_Setup (card, DA\_Group\_A, 1, &da\_ch);

D2K\_AO\_Group\_VUpdate (card, DA\_Group\_A, &out\_V);

D2K\_Release\_Card(card);

# 5.2.2 Continuous Analog output (with initial default settings) programming Scheme

This section described the function flow typical of synchronous analog output operation performed by the device with initial default configuration. While performing continuous AO operation, the AO configuration function has to be called at the beginning of your application. In addition, he SyncMode argument in continuous AO functions has to be set as ASYNCH\_OP.

Initial default channel configuration:

<table><tr><td>D/A Output Polarity</td><td>DAQ2K_DA_BiPolar</td></tr><tr><td>D/A Reference voltage source</td><td>DAQ2K_DA_Int_REF</td></tr><tr><td>D/A Reference voltage value</td><td>10.0</td></tr></table>

Initial default DA configuration:

<table><tr><td>D/A R/W source</td><td>DAQ2K_DA_WRSRC_Int (Internal timer pacer)</td></tr><tr><td>D/A Trigger mode</td><td>DAQ2K_DA_TRGMOD_POST (post trigger)</td></tr><tr><td>D/A Trigger source</td><td>DAQ2K_DA_TRGSRC_SOFT (software trigger)</td></tr><tr><td>Auto buffer reset</td><td>TRUE (except DAQ-2501 and DAQ-2502) FALSE (only for DAQ-2501 and DAQ-2502)</td></tr></table>

1. Non-double-buffered Asynchronous Continuous Analog output programming Scheme

a. DAQ-2005, DAQ-2006, DAQ-2010, DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2214

![The flowchart describes a process flow with the following blocks and connections:\n\n1.  **Top Block**: A rectangle labeled **'D2K_AO_ContBufferSetup'**.\n2.  **Connection**: An arrow points downward from the top block. Text next to the arrow reads: **'With SyncMode=ASYNCH_OP'**.\n3.  **Second Block**: A rectangle labeled **'D2K_AO_ContWritePort'**.\n4.  **Connection**: An arrow points downward from the second block.\n5.  **Third Block**: A rectangle labeled **'D2K_AO_AsyncCheck'**.\n6.  **Connection**: An arrow points downward from the third block to a decision diamond.\n7.  **Decision Block**: A diamond shape labeled **'Operation complete?'**.\n    *   **'No' Path**: An arrow exits the left side of the diamond labeled **'No'**. The line travels upward and points into the left side of the **'D2K_AO_AsyncCheck'** block, creating a loop.\n    *   **'Yes' Path**: An arrow exits the bottom of the diamond labeled **'Yes'**.\n8.  **Fourth Block**: A rectangle labeled **'D2K_AO_AsyncClear'**.\n9.  **Connection**: An arrow points downward from the fourth block, indicating the end of the flow.](.d2k-dask-manual-1/f6bb9f4e3a2425ab4a784b5e58332a810fa105279ea24da333927cb63c46558d.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AO\_ContBufferSetup (card, ao\_buf, data\_size, &DaId);

D2K\_AO\_ContWriteChannel(card, 0, DaId, data\_size, iteration, samp\_intrv, samp\_intrv, ASYNCH\_OP);;

do {

D2K\_AO\_AsyncCheck(card, &bStopped, &count);

} while (!bStopped);

D2K\_AO\_AsyncClear(card, &count, mode);

D2K\_Release\_Card(card);

![This flowchart depicts a sequential process with a loop and a termination path. The blocks and connections are as follows:\n\n1.  **D2K_AO_Group_Setup**\n2.  Arrow down to **D2K_AO_ContBufferSetup**\n3.  Arrow down to **D2K_AO_Group_WFM_Start** (The connecting arrow is labeled **With SyncMode=ASYNCH_OP**)\n4.  Arrow down to **D2K_AO_Group_WFM_AsyncCheck**\n5.  Arrow down to a decision diamond labeled **Operation complete?**\n    *   **No** path loops back up to the input of **D2K_AO_Group_WFM_AsyncCheck**\n    *   **Yes** path proceeds down\n6.  Arrow down to **D2K_AO_Group_WFM_AsyncClear**\n7.  Arrow down to **D2K_AO_ContBufferReset**\n8.  Arrow down (indicating the end of the process)](.d2k-dask-manual-1/abdfee84d3e52d29c09feb82f9f969de9134d383b87becb0f9f4c59a31db1f0d.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2502, card\_number);

D2K\_AO\_Group\_Setup (card, DA\_Group\_A, 1, &da\_ch); //DA channel 0 in group A

D2K\_AO\_ContBufferSetup (card, ao\_buf, data\_size, &DaId);

D2K\_AO\_Group\_WFM\_Start (card, DA\_Group\_A, Id, DaId, data\_size/2, 10, samp\_intrv, 1); do {

D2K\_AO\_Group\_WFM\_AsyncCheck(card, DA\_Group\_A, &bStopped, &count); } while (!bStopped);

D2K\_AO\_Group\_WFM\_AsyncClear(card, DA\_Group\_A, &count, 0);

D2K\_AO\_ContBufferReset (card);

D2K\_Release\_Card(card);

2. Double-buffered Asynchronous Continuous Analog output programming Scheme

a. DAQ-2005, DAQ-2006, DAQ-2010, DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2214

![The flowchart describes a process for asynchronous double buffer mode.\n\n1.  **Start:** The process begins with a block labeled:\n    *   'D2K_AO_ContBufferSetup'\n    *   'D2K_AO_ContBufferSetup'\n    An arrow labeled 'With Enable=TRUE' points downward to the next block.\n\n2.  **Mode Setup:** The next block is labeled 'D2K_AO_AsyncDblBufferMode'. An arrow points downward to a decision diamond.\n\n3.  **Decision 1:** The diamond asks:\n    *   'Sample multiple'\n    *   'continuous chans?'\n    *   **Yes Path:** An arrow labeled 'Yes' goes left. Above the arrow is the text 'With SyncMode' and '=ASYNCH_OP'. This leads to a block labeled 'D2K_AO_ContWriteMultiChannels'.\n    *   **No Path:** An arrow labeled 'No' goes right. Above the arrow is the text 'With SyncMode' and '=ASYNCH_OP'. This leads to a block labeled 'D2K_AO_ContWriteChannel'.\n    Both paths merge and point downward.\n\n4.  **Check Buffer:** The merged path leads to a block labeled 'D2K_AO_AsyncDblBufferHalfReady'. An arrow points downward to a decision diamond.\n\n5.  **Decision 2:** The diamond asks:\n    *   'Next half buffer'\n    *   'Ready?'\n    *   **No Path:** An arrow labeled 'No' goes to the left, loops upward, and re-enters the 'D2K_AO_AsyncDblBufferHalfReady' block.\n    *   **Yes Path:** An arrow labeled 'Yes' points downward to the next block.\n\n6.  **Data Placement:** The next block is labeled 'Placing the output data into the ready buffer ...'. An arrow points downward to a decision diamond.\n\n7.  **Decision 3:** The diamond asks:\n    *   'Want to stop'\n    *   'the operation?'\n    *   **No Path:** An arrow labeled 'No' goes to the left, loops upward, and re-enters the 'D2K_AO_AsyncDblBufferHalfReady' block.\n    *   **Yes Path:** An arrow labeled 'Yes' points downward to the final block.\n\n8.  **End:** The final block is labeled 'D2K_AO_AsyncClear'. An arrow points downward, indicating the end of the flow.](.d2k-dask-manual-1/37f6a60fc058e2e47535ac4215515e3a88b537169fe56d0ac26e2f4a3832e552.jpg)

[Example Code Fragment]
```txt
card = D2K_Register_Card(DAQ_2010, card_number);
D2K_AO_ContBufferSetup (card, ao_buf, data_size, &Dald);
D2K_AO_ContBufferSetup (card, ao_buf2, data_size, &Dald);
D2K_AO_AsyncDblBufferMode (card, 1);
D2K_AO_ContWriteChannel(card, 0, Dald, data_size, 0, samp_intrv, samp_intrv, ASYNCH_OP);
do {
    do {
    D2K_AO_AsyncDblBufferHalfReady(card, &HalfReady);
    } while (!HalfReady);

    // Placing the output data into the ready buffer ...
    ...
} while (!clear_op);

D2K_AO_AsyncClear(card, &count, mode);
...
D2K_Release_Card(card);
```
b. DAQ-2501, DAQ2502

![The flowchart proceeds vertically through a series of blocks and decision points.\n\n**Blocks:**\n1.  D2K_AO_Group_Setup\n2.  D2K_AO_ContBufferSetup\n    D2K_AO_ContBufferSetup\n3.  D2K_AO_AsyncDblBufferMode\n4.  D2K_AO_Group_WFM_Start\n5.  D2K_AO_AsyncDblBufferHalfReady\n6.  Placing the output data into the ready buffer ...\n7.  D2K_AO_Group_WFM_AsyncClear\n8.  D2K_AO_ContBufferReset\n\n**Connections and Annotations:**\n*   An arrow connects **D2K_AO_Group_Setup** to the second block (**D2K_AO_ContBufferSetup** / **D2K_AO_ContBufferSetup**).\n*   An arrow connects the second block to the third block (**D2K_AO_AsyncDblBufferMode**), annotated with: **With Enable=TRUE**.\n*   An arrow connects the third block to the fourth block (**D2K_AO_Group_WFM_Start**), annotated with: **With SyncMode =ASYNCH_OP**.\n*   An arrow connects the fourth block to the fifth block (**D2K_AO_AsyncDblBufferHalfReady**).\n*   An arrow connects the fifth block to a decision diamond labeled: **Next half buffer Ready?**.\n    *   The **'No'** path loops back to the input of the fifth block (**D2K_AO_AsyncDblBufferHalfReady**).\n    *   The **'Yes'** path connects to the block: **Placing the output data into the ready buffer ...**.\n*   An arrow connects this block to a second decision diamond labeled: **Want to stop the operation?**.\n    *   The **'No'** path loops back to the same input point as the first 'No' loop (the input of the fifth block).\n    *   The **'Yes'** path connects to the block: **D2K_AO_Group_WFM_AsyncClear**.\n*   An arrow connects this block to the final block: **D2K_AO_ContBufferReset**.\n*   A final arrow points downward to the text: **(Example Code Fragment)**.](.d2k-dask-manual-1/7214f3849014dafd2401031569b1616168eedf2a0a1486beee3f2972898cab33.jpg)

```c
card = D2K_Register_Card(DAQ_2501, card_number);
D2K_AO_Group_Setup (card, DA_Group_A, 1, &da_ch); //DA channel 0 in group A
D2K_AO_ContBufferSetup (card, ao_buf, data_size, &Dald);
D2K_AO_ContBufferSetup (card, ao_buf2, data_size, &Dald);
D2K_AO_AsyncDblBufferMode (card, 1);
D2K_AO_Group_WFM_Start (card, DA_Group_A, Id, Dald, data_size/2, 0, samp_intrv, 1);
do {
    do {
    D2K_AO_AsyncDblBufferHalfReady(card, &HalfReady);
    } while (!HalfReady);

    // Placing the output data into the ready buffer ...
    ...
} while (!clear_op);

D2K_AO_Group_WFM_AsyncClear(card, DA_Group_A, &count, 0);
D2K_AO_ContBufferReset (card); ...

D2K_Release_Card(card);
```

# 5.2.3 Non-double-buffered Asynchronous Continuous Analog output programming Scheme

This section described the function flow typical of asynchronous analog output operation. While performing continuous AO operation, the AO configuration function has to be called at the beginning of your application. In addition, he SyncMode argument in continuous AO functions has to be set as ASYNCH\_OP.

a. DAQ-2005, DAQ-2006, DAQ-2010, DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2214

![The flowchart follows a vertical sequence with one loop:\n\n1.  **D2K_AO_CH_Config** connects downward to **D2K_AO_Config / D2K_AO_PostTrig_Config / D2K_AO_DelayTrig_Config**.\n2.  This block connects downward to **D2K_AO_ContBufferSetup**.\n3.  An arrow labeled **With SyncMode=ASYNCH_OP** connects this to **D2K_AO_ContWritePort**.\n4.  This block connects downward to **D2K_AO_AsyncCheck**.\n5.  From **D2K_AO_AsyncCheck**, an arrow leads to a diamond labeled **Operation complete?**.\n6.  From the diamond, a path labeled **No** loops back upward to the input of **D2K_AO_AsyncCheck**.\n7.  From the diamond, a path labeled **Yes** leads downward to **D2K_AO_AsyncClear**.\n8.  A final arrow points downward from **D2K_AO_AsyncClear**.](.d2k-dask-manual-1/491b0966e9b4fce84f3407f5f6b8bf476344e282be069aedb2ab1f11a608158e.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AO\_CH\_Config (card, 0, DAQ2K\_DA\_BiPolar, DAQ2K\_DA\_Int\_REF, 10.0);

D2K\_AO\_Group\_Setup (card, DA\_Group\_A, 1, &da\_ch); //DA channel 0 in group A

D2K\_AO\_Config (card, 0, DAQ2K\_DA\_TRGMOD\_POST|DAQ2K\_DA\_TRGSRC\_ExtD, 1, 0, 0,1)

D2K\_AO\_ContBufferSetup (card, ao\_buf, data\_size, &DaId);

D2K\_AO\_ContWriteChannel(card, 0, DaId, data\_size, iteration, samp\_intrv, samp\_intrv, ASYNCH\_OP);; do {

D2K\_AO\_AsyncCheck(card, &bStopped, &count); } while (!bStopped);

D2K\_AO\_AsyncClear(card, &count, mode);

D2K\_Release\_Card(card);

b. DAQ-2501, DAQ2502

![The flowchart depicts a sequential process with a conditional loop. Here are the labeled blocks and their connections:\n\n1.  **D2K_AO_CH_Config**\n    *   Connected via a downward arrow to **D2K_AO_Group_Setup**\n2.  **D2K_AO_Group_Setup**\n    *   Connected via a downward arrow to **D2K_AO_Config / D2K_AO_PostTrigConfig / D2K_AO_DelayTrigConfig**\n3.  **D2K_AO_Config / D2K_AO_PostTrigConfig / D2K_AO_DelayTrigConfig**\n    *   Connected via a downward arrow to **D2K_AO_ContBufferSetup**\n4.  **D2K_AO_ContBufferSetup**\n    *   Connected via a downward arrow (annotated with the text **With SyncMode=ASYNC_OP**) to **D2K_AO_Group_WFM_Start**\n5.  **D2K_AO_Group_WFM_Start**\n    *   Connected via a downward arrow to **D2K_AO_Group_WFM_AsyncCheck**\n6.  **D2K_AO_Group_WFM_AsyncCheck**\n    *   Connected via a downward arrow to a decision diamond labeled **Operation complete?**\n7.  **Operation complete?**\n    *   Connected via a leftward arrow labeled **No** looping back to the start of **D2K_AO_Group_WFM_AsyncCheck**\n    *   Connected via a downward arrow labeled **Yes** to **D2K_AO_Group_WFM_AsyncClear**\n8.  **D2K_AO_Group_WFM_AsyncClear**\n    *   Connected via a downward arrow to **D2K_AO_ContBufferReset**\n9.  **D2K_AO_ContBufferReset**\n    *   Connected via a downward arrow indicating the end of the process.](.d2k-dask-manual-1/3f190e511c491d711a817a32ceb8c5ae3dfd61c96f34cc56062f4e6e8622c0e4.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2501, card\_number);

D2K\_AO\_CH\_Config (card, 0, DAQ2K\_DA\_BiPolar, DAQ2K\_DA\_Int\_REF, 10.0);

D2K\_AO\_Group\_Setup (card, DA\_Group\_A, 1, &da\_ch); //DA channel 0 in group A

D2K\_AO\_Config (card, 0, DAQ2K\_DA\_TRGMOD\_POST|DAQ2K\_DA\_TRGSRC\_ExtD, 1, 0, 0,0);

D2K\_AO\_ContBufferSetup (card, ao\_buf, data\_size, &DaId);

D2K\_AO\_Group\_WFM\_Start (card, DA\_Group\_A, Id, DaId, data\_size/2, 10, samp\_intrv, 1);

D2K\_AO\_Group\_WFM\_AsyncCheck(card, DA\_Group\_A, &bStopped, &count);

} while (!bStopped);

D2K\_AO\_Group\_WFM\_AsyncClear(card, DA\_Group\_A, &count, 0);

D2K\_AO\_ContBufferReset (card);

D2K\_Release\_Card(card);

# 5.2.4 Double-buffered Asynchronous Continuous Analog output programming Scheme

This section described the function flow typical of double-buffered asynchronous analog output operation. While performing continuous AO operation, the AO configuration function has to be called at the beginning of your application. The SyncMode argument in continuous AO functions has to be set as ASYNCH\_OP. In addition, double-buffered AO operation is enabled by setting Enable argument of D2K\_AO\_AsyncDblBufferMode function to 1. To learn more about double buffer mode, please refer to section 5.2 Double-Buffered AI/AO Operation for the details.

a. DAQ-2005, DAQ-2006, DAQ-2010, DAQ-2204, DAQ-2205, DAQ-2206, DAQ-2214

![The flowchart depicts a process for configuring and running asynchronous analog output (AO) channels.\n\n**Blocks and Connections:**\n\n1.  **Start:** The process begins with a block labeled **D2K_AO_CH_Config**.\n2.  **Arrow Down:** Connects to a block containing the text: **D2K_AO_Config / D2K_AO_PostTrigConfig / D2K_AO_DelayTrigConfig**.\n3.  **Arrow Down:** Connects to a block containing the text:\n    **D2K_AO_ContBufferSetup**\n    **D2K_AO_ContBufferSetup**\n4.  **Arrow Down:** Labeled **With Enable=TRUE**. Connects to a block labeled **D2K_AO_AsyncDblBufferMode**.\n5.  **Arrow Down:** Connects to a decision diamond labeled **Sample multiple continuous chans?**.\n    *   **Yes Path (Left):** An arrow labeled **With SyncMode =ASYNCH_OP** leads to a block labeled **D2K_AO_ContWriteMultiChannels**.\n    *   **No Path (Right):** An arrow labeled **With SyncMode =ASYNCH_OP** leads to a block labeled **D2K_AO_ContWriteChannel**.\n6.  **Convergence:** Arrows from both blocks above merge and point to a block labeled **D2K_AO_AsyncDblBufferHalfReady**.\n7.  **Arrow Down:** Connects to a decision diamond labeled **Next half buffer Ready?**.\n    *   **No Path (Left):** An arrow loops back to the input of the **D2K_AO_AsyncDblBufferHalfReady** block.\n    *   **Yes Path (Down):** Connects to a block labeled **Placing the output data into the ready buffer ...**.\n8.  **Arrow Down:** Connects to a decision diamond labeled **Want to stop the operation?**.\n    *   **No Path (Left):** An arrow loops back to the input of the **D2K_AO_AsyncDblBufferHalfReady** block.\n    *   **Yes Path (Down):** Connects to a block labeled **D2K_AO_AsyncClear**.\n9.  **Arrow Down:** Points downward from the final block, indicating the end of the process.](.d2k-dask-manual-1/630a9cba3896a9ef789e96b7661334fa4e76b15bfe7d8cae4b58b01e7bded18e.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

D2K\_AO\_CH\_Config (card, 0, DAQ2K\_DA\_BiPolar, DAQ2K\_DA\_Int\_REF, 10.0);

D2K\_AO\_Config (card, 0, DAQ2K\_DA\_TRGMOD\_POST|DAQ2K\_DA\_TRGSRC\_ExtD, 1, 0, 0,1)

D2K\_AO\_ContBufferSetup (card, ao\_buf, data\_size, &DaId);

D2K\_AO\_ContBufferSetup (card, ao\_buf2, data\_size, &DaId);

D2K\_AO\_AsyncDblBufferMode (card, 1);

D2K\_AO\_ContWriteChannel(card, 0, DaId, data\_size, 0, samp\_intrv, samp\_intrv, ASYNCH\_OP);;

do {

D2K\_AO\_AsyncDblBufferHalfReady(card, &HalfReady);

} while (!HalfReady);

// Placing the output data into the ready buffer …

} while (!clear\_op);

D2K\_AO\_AsyncClear(card, &count, mode);

D2K\_Release\_Card(card);

b. DAQ-2501, DAQ2502
![The flowchart outlines a sequence of operations and a control loop. Here are the blocks and connections in order:\n\n1.  **D2K_AO_CH_Config** connects downward to **D2K_AO_Group_Setup**.\n2.  **D2K_AO_Group_Setup** connects to **D2K_AO_Config / D2K_AO_PostTrigConfig / D2K_AO_DelayTrigConfig**.\n3.  This connects to a block containing two lines of identical text:\n    **D2K_AO_CntBufferSetup**\n    **D2K_AO_CntBufferSetup**\n4.  An arrow labeled **With Enable=TRUE** points to **D2K_AO_AsyncDblBufferMode**.\n5.  An arrow labeled **With SyncMode=ASYNCH_OP** points to **D2K_AO_Group_WFM_Start**.\n6.  This connects to **D2K_AO_AsyncDblBufferHalfReady**.\n7.  From there, a decision diamond appears with the text **Next half buffer Ready?**:\n    *   The **No** path loops back to the arrow entering **D2K_AO_AsyncDblBufferHalfReady**.\n    *   The **Yes** path leads to a block labeled **Placing the output data into the ready buffer ...**.\n8.  From the 'Placing...' block, the flow moves to a decision diamond labeled **Want to stop the operation?**:\n    *   The **No** path loops back to the arrow entering **D2K_AO_AsyncDblBufferHalfReady**.\n    *   The **Yes** path leads to **D2K_AO_Group_WFM_AsyncClear**.\n9.  The diagram ends with the text **(Example Code Fragment)** at the bottom.](.d2k-dask-manual-1/c7b7b1abe881108cfa9238bba545d4c8d28954b58ceedeb978b756d0526e6439.jpg)

```c
card = D2K_Register_Card(DAQ_2502, card_number);
```

```txt
D2K AO CH Config (card, 0, DAQ2K DA BiPolar, DAQ2K DA Int REF, 10.0);
```

```txt
D2K AO Group Setup (card, DA Group A, 1, &da ch); //DA channel 0 in group A
```

```c
D2K_AO_Config (card, 0, DAQ2K_DA_TRGMOD_POST|DAQ2K_DA_TRGSRC_ExtD, 1, 0, 0, 0);
```

```txt
D2K AO ContBufferSetup (card, ao_buf, data_size, &Dald);
```

```c
D2K_AO_ContBufferSetup (card, ao_buf2, data_size, &Dald);
```

```txt
D2K_AO_AsyncDblBufferMode (card, 1);
```

```c
D2K_AO_Group_WFM_Start (card, DA_Group_A, Id, Dald, data_size/2, 0, samp_intrv, 1); do {
```

```txt
do {
```

```javascript
D2K_AO_AsyncDbIBufferHalfReady(card, &HalfReady);
```

```javascript
} while (!HalfReady);
```

```txt
// Placing the output data into the ready buffer ...
```

```txt
} while (!clear_op);
```

```javascript
D2K_AO_Group_WFM_AsyncClear(card, DA_Group_A, &count,0);
```

D2K\_AO\_ContBufferReset (card); …

D2K\_Release\_Card(card);

# 5.3 Digital Input Programming Hints

D2K-DASK provides one kind of digital input operation  non-buffered single-point digital input operation.

The non-buffered single-point DI uses software polling method to read data from the device. The programming scheme for this kind of DI operation is described in section 5.3.1.

# 5.3.1 One-Shot Digital input programming Scheme

This section described the function flow typical of non-buffered single-point digital input readings. While performing oneshot DI operation, the devices whose I/O port can be set as input or out put port need to include port configuration function at the beginning of your application.

![The flowchart begins with a rectangular block labeled **'D2K_DIO_PortConfig'**. An arrow points downward from this block towards a diamond-shaped decision block, labeled on the arrow as **'Port configured as input port'**.\n\nThe diamond block contains the text **'Input data form Line?'**. Two paths emerge from this decision:\n*   The left path, labeled **'No'**, leads to a rectangular block labeled **'D2K_DI_ReadPort'**.\n*   The right path, labeled **'Yes'**, leads to a rectangular block labeled **'D2K_DI_ReadLine'**.\n\nArrows from both 'D2K_DI_ReadPort' and 'D2K_DI_ReadLine' converge and point downward into a second diamond-shaped decision block at the bottom. This bottom diamond contains the text **'Another reading ?'**.\n\nFrom this final decision point:\n*   A path labeled **'Yes'** loops back to the left, re-entering the flow line above the first diamond.\n*   A path labeled **'No'** points downward, indicating the end of the sequence.](.d2k-dask-manual-1/ec2d41d572184ff492ba24d9266da8cbbdde2b10c61339595cf0e4a9f116730b.jpg)

[Example Code Fragment]

card = D2K\_Register\_Card(DAQ\_2010, card\_number); //port configured

D2K\_DIO\_PortConfig(card ,Channel\_P1A, INPUT\_PORT);

D2K\_DIO\_PortConfig(card, Channel\_P1B, INPUT\_PORT);

D2K\_DIO\_PortConfig(card, Channel\_P1CL, INPUT\_PORT);

D2K\_DIO\_PortConfig(card, Channel\_P1CH, INPUT\_PORT); //DI operation

D2K\_DI\_ReadPort(card, Channel\_P1A, &inputA);

D2K\_Release\_Card(card);

# 5.4 Digital Output Programming Hints

D2K-DASK provides one kind of digital output operation  non-buffered single-point digital output operation.

The non-buffered single-point DO uses software polling method to write data to the device. The programming scheme for this kind of DO operation is described in section 5.4.1.

# 5.4.1 One-Shot Digital output programming Scheme

This section described the function flow typical of non-buffered single-point digital output operation. While performing one-shot DO operation, the cards whose I/O port can be set as input or out put port need to include port configuration function at the beginning of your application.

![The flowchart begins with a rectangular block labeled **D2K_DIO_PortConfig**. An arrow points downward from this block toward a diamond-shaped decision block, accompanied by the text label **Port configured as output port**.\n\nThe diamond block is labeled **Output data to Line?**.\n*   A branch labeled **No** points left to a rectangular block labeled **D2K_DO_WritePort**.\n*   A branch labeled **Yes** points right to a rectangular block labeled **D2K_DO_WriteLine**.\n\nThe outputs from both **D2K_DO_WritePort** and **D2K_DO_WriteLine** converge into a downward arrow leading to a second diamond-shaped decision block labeled **Another outputting ?**.\n*   A branch labeled **Yes** loops upward and points back into the flow between the top block and the first decision diamond.\n*   A branch labeled **No** points downward, exiting the diagram.\n\nIn the bottom left corner, outside the diagram, is the text **(Example Code Fragment)**.](.d2k-dask-manual-1/f1970aa4952980e2136d989c0c6611c4fedee62606579e703347cfc55d285235.jpg)

card = D2K\_Register\_Card(DAQ\_2010, card\_number);

//port configured

D2K\_DIO\_PortConfig(card ,Channel\_P1A, OUTPUT\_PORT);

D2K\_DIO\_PortConfig(card, Channel\_P1B, OUTPUT\_PORT);

D2K\_DIO\_PortConfig(card, Channel\_P1CL, OUTPUT\_PORT);

D2K\_DIO\_PortConfig(card, Channel\_P1CH, OUTPUT\_PORT);

//DO operation

D2K\_DO\_WritePort(card, Channel\_P1A, outA\_value);

D2K\_Release\_Card(card);

# 5.5 DAQ Event Message Programming Hints

DAQ Event Message functions are an efficient way to monitor your background data acquisition processes, without dedicating your foreground process for status checking. There are two kinds of events, which are AI/AO operation completeness notification event and half buffer ready notification event.

To receive notification from the D2K-DASK data acquisition process in case of special events, you can call D2K\_AI\_EventCallBack or D2K\_AO\_EventCallBack to specify an event in which you are interested.

Event notification is done through user-defined callbacks. When a user-specified DAQ event occurs, D2K-DASK calls the user-defined callback. After receiving the message, the user’s application can carry out the appropriate task.

The event message mechanism is easy and safe in Windows 98 and NT systems; however, the time delay between the event and notification is highly variable and depends largely on how loaded your system is. In addition, if a callback function is called, succeeding events will not be handled until your callback has returned. If the time interval between events is smaller than the time taken for callback function processing, the succeeding events will not be handled. Therefore this mechanism is not suitable for the frequent events occurrence condition.

[Example Code Fragment]

```c
card = D2K_Register_Card(DAQ_2010, card_number);
```

```txt
D2K_AI_CH_Config (card, channel, range)
```

```c
D2K_AI_Config (card, 0, DAQ2K_AI_TRGMOD_PRE|DAQ2K_AI_TRGSRC_ExtD, 0, 0, 0, 1);
```

```txt
// or
```

```c
// D2K_AI_MiddleTrig_Config (card, DAQ2K_AI_ADCONVSRC_Int, DAQ2K_AI_TRGSRC_ExtD| DAQ2K_AI_TrgPositive, 0, 0, 1);
```

```txt
D2K_AI_AsyncDblBufferMode (card, 1); // Double-buffered AI
```

```txt
D2K_AI_ContBufferSetup (card, ai_buf, data_size, &BufId);
```

```txt
D2K_A_ContBufferSetup (card, ai_buf2, data_size, &BufId);
```

```txt
// Enable half buffer ready event notification
```

```c
D2K_AI_EventCallBack (card, 1, DBEvent, (U32) DB_cbfn);
```

```txt
//Enable AI completeness event notification
```

```txt
D2K_AI_EventCallBack (card, 1, DAQEnd, (U32) AI_cbfn );
```

```txt
D2K_AI_ContScanChannels (card, channel, BufId, data_size/(channel+1), ScanIntrv, SampIntrv, ASYNCH_OP); or
```

```txt
D2K_AI_ContReadChannel(card, channel, Bufld, data_size, ScanIntrv, SampIntrv, ASYNCH_OP)
```

```txt
...
```

```javascript
D2K_Release_Card(card);
```

```txt
//Half buffer ready call back function
```

```txt
void DB_cbfn()
```

```txt
{
```

```txt
//half buffer is ready
```

$\cdots$

```javascript
//AI completeness call back function
```

```txt
void AI_cbfn()
```

```txt
{
```

```javascript
//AI is completed
```

```javascript
D2K_AI_AsyncClear(card, &startPos, &count);
```

$\cdots$

# 6

# Continuous Data Transfer in D2K-DASK

The continuous data transfer functions in D2K-DASK input or output blocks of data to or from a plug-in DAQ-2000 device. For input operations, D2K-DASK must transfer the incoming data to a buffer in the computer memory. For output operations, D2K-DASK must transfer outgoing data from a buffer in the computer memory to the DAQ-2000 device. This chapter describes the mechanism and techniques that D2K-DASK uses for continuous data transfer and the considerations for selecting the continuous data transfer mode (sync. or async., double buffered or not, triggered or non-triggered mode).

# 6.1 Continuous Data Transfer Mechanism

D2K-DASK uses the DMA controller chip to perform a hardware transfer of the data.

# 6.2 Double-Buffered AI/AO Operation

D2K-DASK uses double-buffering techniques in its driver software for continuous input/output of large amounts of data.

# 6.2.1 Double Buffer Mode Principle

The data buffer for double-buffered continuous input operation is a circular buffer logically. It is logically divided into two equal halves. The double-buffered input begins when device starts writing data into the first half of the circular buffer (Figure 6-1a). After device begins writing to the second half of the circular buffer, you can process the data in the first half buffer according to application needs (Figure 6-1b). After the board has filled the second half of the circular buffer, the board returns to the first half buffer and overwrites the old data. You now can process the second half of the circular buffer (Figure 7-1c). The process can be repeated endlessly to provide a continuous stream of data to your application (Figure 7-1d).

![The image is a schematic diagram illustrating a data transfer process across four panels labeled a, b, c, and d, with a legend at the bottom.\n\n**Legend:**\n- White box: 'Empty Buffer'\n- Green box: 'Untransferred Data'\n- Grey patterned box: 'Transferred Data'\n\n**Panel a:**\n- Labeled 'a'. Text reads 'Incoming DMA input data' above an arrow pointing down into a green section of a rectangle labeled 'Circular Buffer'. The buffer is split into a green left section and a white right section. Below is an empty rectangle labeled 'Transfer Buffer'.\n\n**Panel b:**\n- Labeled 'b'. The top rectangle contains a grey section on the left and a green section on the right. Above it, there is a dotted arrow, three ' ) ' symbols, and a solid arrow. Dashed lines show data moving from the top buffer to the bottom buffer, which is now filled with grey 'Transferred Data'.\n\n**Panel c:**\n- Labeled 'c'. The top rectangle has a small green section on the far left and a grey section elsewhere. Above it are ' ) ) ' symbols, a solid arrow, a dotted arrow, and ' ) ) ' symbols. The bottom buffer is filled with grey data.\n\n**Panel d:**\n- Labeled 'd'. The top rectangle has a green section in the middle-right and grey data elsewhere. Above it is a dotted arrow, three ' ) ) ) ' symbols, and a solid arrow. The bottom buffer is filled with grey data.](.d2k-dask-manual-1/7ef139f9eb7a0dc3a10f8290f62e181c758fed6a68d8945cb8a12a9ad737364a.jpg)
Figure 7-1

The D2K-DASK double buffer mode functions were designed according to the principle described above. If you use D2K\_AI\_AsyncDblBufferMode/D2K\_AO\_AsyncDblBufferMode to enable double buffer mode, the following continuous AI/AO function will perform double-buffered continuous AI/AO. You can call D2K\_AI\_AsyncDblBufferHalfReady/ D2K\_AO\_AsyncDblBufferHalfReady to check if data in the circular buffer is half full and ready for copying to the transfer buffer.

# 6.2.2 Single-Buffered Versus Double-Buffered Data Transfer

Single-buffered data transfer is the most common method for continuous data transfer. In single-buffered input operations, a fixed number of samples are acquired at a specified rate and transferred into user’s buffer. After the user’s buffer stores the data, the application can analyze, display, or store the data to the hard disk for later processing. Single-buffered operations are relatively simple to implement and can usually take advantage of the full hardware speed of the device. However, the major disadvantage of single-buffered operation is that the maximum amount of data that can be input at any one time is limited to the amount of initially allocated memory allocated in driver and the amount of free memory available in the computer.

In double-buffered operations, as mentioned above, the data buffer is configured as a circular buffer. Therefore, unlike single-buffered operations, double-buffered operations reuse the same buffer and are able to input or output an infinite number of data points without requiring an infinite amount of memory. However, there exits the undesired result of data overwritten for double-buffered data transfer. The device might overwrite data before D2K-DASK has copied it to the transfer buffer. Another data overwritten problem occurs when an input device overwrites data that D2K-DASK is simultaneously copying to the transfer buffer. Therefore, the data must be processed by the application at least as fast as the rate at which the device is reading data. For most of the applications, this requirement depends on the speed and efficiency of the computer system and programming language.

Hence, double buffering might not be practical for high-speed input applications.

# 6.3 Pre-Trigger Mode/ Middle-Trigger Mode Data Acquisition for Analog Input

A trigger is an event that occurs based on a specified set of conditions. An interrupt mode or DMA-mode analog input operation can use a trigger to determinate when acquisition stops or starts.

D2K-DASK also provides two buffering methods for pre/middle-trigger mode AI – double-buffering and single-buffering. However, the single buffer in pre/middle-trigger mode AI is different from that in non-trigger mode AI. It is a circular buffer just like that in double buffer mode but the data stored in the buffer can be processed only when the continuous data reading is completed. The buffer will be reused until the data acquisition operation is completed. Therefore, to protect the data you want to get from being overwritten, the size of the single buffer should be the same as or larger than the amount of data you wish to access. For example, if you want to perform single-buffered middle-trigger AI with DAQ-2010, and the amount of data you want to collect before and after the trigger event are 1000 and 3000 respectively, the size of single buffer is at least 4000 in order to get all the data you want to collect. Since the data are handled after the input operation is completed, the desired data loss problem hardly occurs.

Since D2K-DASK uses asynchronous AI to perform pre/middle-trigger mode data acquisition, the SyncMode of continuous AI should be set as ASYNCH\_OP.

# 7

# Distribution of Applications

# 7.1 Files

To install an application using D2K-DASK on another computer, you also must install the necessary driver files and supporting libraries on the target machine. You can create an automatic installer to install your program and all of the files needed to run that program or you can manually install the program and program files. Whichever installation method you choose, you must install the following files:

z Required support DLLs:

– D2K-DASK.dll

z Driver files

# Windows 98

– The corresponding driver files in \DAQ2000\W98NT2K \redist\W98\drivers, e.g. daq2010.sys for DAQ-2010. These files should be copied to Windows\system32\drivers directory.
– The corresponding INF files in \DAQ2000\W98NT2K \redist\W98\Inf, e.g. Daq2010.inf for DAQ-2010. These files should be copied to Windows\inf directory.
– Device configuration utility in \DAQ2000\W98NT2K\redist\W98\Util.
– Device calibration utility in \DAQ2000\W98NT2K \redist\W98\Util.

# Windows NT 4.0

– The corresponding driver files in \DAQ2000\W98NT2K \redist\Wnt\drivers, e.g. daq2010.sys for DAQ-2010. These files should be copied to Winnt\system32\drivers directory.
– Device configuration utility in \DAQ2000\W98NT2K/redist\Wnt\Util.
– Device calibration utility in \DAQ2000\W98NT2K \redist\Wnt\Util.

# Windows 2000

– The corresponding driver file in \ DAQ2000\W98NT2K \redist\W2000\drivers, e.g. daq2010.sys for DAQ-2010. These files should be copied to Winnt\system32\drivers directory.
– The corresponding INF file in \ DAQ2000\W98NT2K \redist\W2000\Inf, e.g. daq2010.inf for DAQ-2010. These files should be copied to Winnt\inf directory.
– Device configuration utility in \ DAQ2000\W98NT2K \redist\W2000\Util.
– Device calibration utility in \DAQ2000\W98NT2K \redist\W2000\Util.

z Utility file (option)

– Data Conversion utility DAQCvt.exe in \DAQ2000\ W98NT2K\redist\W98\Util, \ DAQ2000\W98NT2K\redist\Wnt\Util or \ DAQ2000\W98NT2K\redist\W2000\Util to convert the binary data file to the file format read easily.

# 7.2 Automatic Installers

Many programming environments include some form of setup or distribution kit tool. This tool automatically creates an installation program for your program so that you can easily install it on another computer. To function successfully, this tool must recognize which control files and supporting libraries are required by your program and include these in the installation program it creates.

Some of these tools, such as the Visual Basic 5 Setup Wizard, use dependency files to determine which libraries are required by an VB application.

Some setup tools might not automatically recognize which files are required by a program but provide an option to add additional files to the installation program. In this case, verify that all the necessary files described in the previous section are included. You also should verify that the resulting installation program does not copy older versions of a file over a newer version on the target computer.

If your programming environment does not provide a tool or wizard for building an installation program, you can use third-party tools such as InstallShield. Some programming environments provide simplified or trial versions of third-party installer creation tools on their installation CDs.

The installation program not only copies all the required files into the appropriated location, but executes Device configuration utility to configure the devices.

# 7.3 Manual Installation

If your programming environment does not include a setup or distribution kit tool, you can perform the installation task manually. To install your program on another computer, follow these steps:

1. Copy the program executable to the target computer.
2. Copy all required D2K-DASK files described in the section 7.1.1 to the appropriate directory on the target computer.
3. Use DAQ-2000 Device Configuration utility to configure the device.

Note: Do not replace any files on the target computer if the file on the target computer has a newer version than the file you are installing.
[🔗 Link to the original document](.d2k-dask-manual-1/d2k-dask-manual-1.pdf)
