AIO16 Driver

Overview

AIO16 is a function driver for the 104-AIO16-16. It works with WDM-compatible versions of Windows, including Windows 98, Windows ME, Windows NT/2000, and Windows NT/XP. Under older versions of Windows (Windows 3.1, Windows 95, and Windows NT 4.x or less), the card can be used with our ACCES32 and IRQGen drivers, at reduced speed.



Interface Documentation

All functions are exported in three forms: underscored with the cdecl calling convention (the easiest for C++), undecorated with the stdcall calling convention (easiest for Visual BASIC), and undecorated with the cdecl calling convention (easiest for most other languages). Import declarations are given for Object Pascal / Delphi, C++ Builder / Visual C++, and Visual BASIC.

Visual BASIC doesn't have true pointers, and thus pointer-using functions are declared in Visual BASIC to always have a non-null pointer.


AIO16_GetNumCards()

function AIO16_GetNumCards: LongWord; cdecl; external 'AIO16.dll';

__declspec(dllimport) unsigned long AIO16_GetNumCards(void);

Public Declare Function AIO16_GetNumCards Lib "AIO16" Alias "VBAIO16_GetNumCards" () As Long

This function returns the number of cards installed in the system with AIO16. The cards are numbered from zero to one less than the number returned by AIO16_GetNumCards(); these card numbers are specified for the CardNum parameters of most other AIO16.dll functions. If an invalid card number is specified to another function, the function will fail.

Note that since the 104-AIO16-16 is not Plug-And-Play, the Add New Hardware wizard must be run to "attach" AIO16 to a card. Once the card appears in Device Manager and its base address and IRQ have been set there, it will get an AIO16 card number.


AIO16_Init()

function AIO16_Init(CardNum: LongWord; Base: PLongWord): LongWord; cdecl; external 'AIO16.dll';

__declspec(dllimport) unsigned long AIO16_Init(unsigned long CardNum, unsigned long *Base);

Public Declare Function AIO16_Init Lib "AIO16" Alias "VBAIO16_Init" (ByVal CardNum As Long, ByRef Base As Long) As Long

This function initializes and calibrates the card indicated by CardNum. It also retrieves the card's base address, so you can tell which physical card corresponds to which card number. If you don't care about the base address of the card(for example, you know you only have one in the system), you can pass a null pointer. AIO16_Init() returns zero if it succeeds, or a Windows error code if it fails. Several possible error codes are:

It can also return any of the error codes CreateFile() can set as the last error.

There is one circumstance under which you may want to call AIO16_Init() more than once: if you physically change the range jumpers on the card, call AIO16_Init() to reload the jumper settings.


AIO16_GetSettings()

function AIO16_GetSettings(CardNum: LongWord; ADC16SE, ADCBip, ADC5V, DACA5V, DACB5V: PLongWord): LongWord; cdecl; external 'AIO16.dll';

__declspec(dllimport) unsigned long AIO16_GetSettings(unsigned long CardNum, unsigned long *ADC16SE, unsigned long *ADCBip, unsigned long *ADC5V, unsigned long *DACA5V, unsigned long *DACB5V);

Public Declare Function AIO16_GetSettings Lib "AIO16" Alias "VBAIO16_GetSettings" (ByVal CardNum As Long, ByRef ADC16SE As Long, ByRef ADCBip As Long, ByRef ADC5V As Long, ByRef DACA5V As Long, ByRef DACB5V As Long) As Long

This function retrieves the range jumper settings of the card indicated by CardNum. It returns zero if it succeeds, or a Windows error code if it fails. Each parameter is a pointer to a DWord to receive the corresponding setting, or a null pointer if you don't care about that setting. The settings are:

Some possible error codes are:

AIO16_ADC_Acquire()

function AIO16_ADC_Acquire(CardNum: LongWord; RateHz: PLongWord; Gain, LoChannel, HiChannel, Count, Oversample: LongWord; UserBuffer: PSingle): LongWord; cdecl; external 'AIO16.dll';

__declspec(dllimport) unsigned long AIO16_ADC_Acquire(unsigned long CardNum, unsigned long *RateHz, unsigned long Gain, unsigned long LoChannel, unsigned long HiChannel, unsigned long Count, unsigned long Oversample, short float *UserBuffer);

Public Declare Function AIO16_ADC_Acquire Lib "AIO16" Alias "VBAIO16_ADC_Acquire" (ByVal CardNum As Long, ByRef RateHz As Long, ByVal Gain As Long, ByVal LoChannel As Long, ByVal HiChannel As Long, ByVal Count As Long, ByVal Oversample As Long, ByRef UserBuffer As Single) As Long

This function starts the card indicated by CardNum taking a block of A/D data. It returns zero if it succeeds, or a Windows error code if it fails. Its parameters are:

Some possible error codes are: It can also return any of the error codes DeviceIoControl() can set as the last error.


AIO16_ADC_Stop()

function AIO16_ADC_Stop(CardNum: LongWord): LongWord; cdecl; external 'AIO16.dll';

__declspec(dllimport) unsigned long AIO16_ADC_Stop(unsigned long CardNum);

Public Declare Function AIO16_ADC_Stop Lib "AIO16" Alias "VBAIO16_ADC_Stop" (ByVal CardNum As Long) As Long

This function stops A/D acquisition for the card indicated by CardNum. It returns zero if it succeeds, or a Windows error code if it fails; however, it can only fail if acquisition was not taking place, so the return value is not terribly useful.


AIO16_ADC_Read()

AIO16_ADC_WaitRead()

function AIO16_ADC_Read(CardNum: LongWord): LongWord; cdecl; external 'AIO16.dll';
function AIO16_ADC_WaitRead(CardNum: LongWord; MinResults: LongWord): LongWord; cdecl; external 'AIO16.dll';

__declspec(dllimport) unsigned long AIO16_ADC_Read(unsigned long CardNum);
__declspec(dllimport) unsigned long AIO16_ADC_WaitRead(unsigned long CardNum, unsigned long MinResults);

Public Declare Function AIO16_ADC_Read Lib "AIO16" Alias "VBAIO16_ADC_Read" (ByVal CardNum As Long) As Long
Public Declare Function AIO16_ADC_WaitRead Lib "AIO16" Alias "VBAIO16_ADC_WaitRead" (ByVal CardNum As Long, ByVal MinResults As Long) As Long

These functions validate A/D data acquired by the card indicated by CardNum. They both return the number of samples validated; the total number of samples acquired and valid can be determined by accumulating this result. The data is in the buffer passed for UserBuffer to AIO16_ADC_Acquire(). They differ in that AIO16_ADC_WaitRead() does not return until at least [MinResults] samples have been validated. AIO16_ADC_WaitRead() can return more than [MinResults] valid samples, but will only return less if an error occurs. If an error occurs in either function, it will return zero, and GetLastError() can retrieve the error code.

An example of use: AIO16_ADC_Acquire is used to acquire 200,000 samples. A call to AIO16_ADC_WaitRead() with MinResults=800 returns 1024 valid samples; UserBuffer[0] through UserBuffer[1023] are now valid. The next call to AIO16_ADC_WaitRead() returns another 1024 valid samples; UserBuffer[1024] through UserBuffer[2047] are now valid as well.


AIO16_DAC_Write()

function AIO16_DAC_Write(CardNum, DACNum: LongWord; Volts: Double): Double; cdecl; external 'AIO16.dll';

__declspec(dllimport) signed double AIO16_DAC_Write(unsigned long CardNum, unsigned long DACNum, signed double Volts);

Public Declare Function AIO16_DAC_Write Lib "AIO16" Alias "VBAIO16_DAC_Write" (ByVal CardNum As Long, ByVal DACNum As Long, ByVal Volts As Double) As Double

This function outputs a voltage to one of the the D/A channels on the card indicated by CardNum. It returns the voltage actually output, or 22222.0 if an error occurs(in which case GetLastError() can retrieve the error code). DACNum should be 0 for DAC A, or 1 for DAC B. Note that the maximum-scale voltage cannot be exactly achieved; for example, the 0-5V range is actually 0-4.9987V, and if you specify 5V, it will wrap to 0V. Calculate the exact maximum-scale voltage by multiplying the listed maximum by 4095/4096.


Control Functions

function AIO16_EEPROM_Enable(CardNum: LongWord): LongWord; cdecl; external 'AIO16.dll';
function AIO16_EEPROM_Disable(CardNum: LongWord): LongWord; cdecl; external 'AIO16.dll';
function AIO16_EEPROM_Read(CardNum, Addr: LongWord): LongWord; cdecl; external 'AIO16.dll';
function AIO16_EEPROM_Write(CardNum, Addr, Data: LongWord): LongWord; cdecl; external 'AIO16.dll';
function AIO16_ADC_Cal(CardNum, M, B: LongWord): LongWord; cdecl; external 'AIO16.dll';
function AIO16_DAC_Cal(CardNum, DACNum, M: LongWord): LongWord; cdecl; external 'AIO16.dll';
function AIO16_LoadCal(CardNum: LongWord): LongWord; cdecl; external 'AIO16.dll';

__declspec(dllimport) unsigned long AIO16_EEPROM_Enable(unsigned long CardNum);
__declspec(dllimport) unsigned long AIO16_EEPROM_Disable(unsigned long CardNum);
__declspec(dllimport) unsigned long AIO16_EEPROM_Read(unsigned long CardNum, unsigned long Addr);
__declspec(dllimport) unsigned long AIO16_EEPROM_Write(unsigned long CardNum, unsigned long Addr, unsigned long Data);
__declspec(dllimport) unsigned long AIO16_ADC_Cal(unsigned long CardNum, unsigned long M, unsigned long B);
__declspec(dllimport) unsigned long AIO16_DAC_Cal(unsigned long CardNum, unsigned long DACNum, unsigned long M);
__declspec(dllimport) unsigned long AIO16_LoadCal(unsigned long CardNum);

Public Declare Function AIO16_EEPROM_Enable Lib "AIO16" Alias "VBAIO16_EEPROM_Enable" (ByVal CardNum As Long) As Long
Public Declare Function AIO16_EEPROM_Disable Lib "AIO16" Alias "VBAIO16_EEPROM_Disable" (ByVal CardNum As Long) As Long
Public Declare Function AIO16_EEPROM_Read Lib "AIO16" Alias "VBAIO16_EEPROM_Read" (ByVal CardNum As Long, ByVal Addr As Long) As Long
Public Declare Function AIO16_EEPROM_Write Lib "AIO16" Alias "VBAIO16_EEPROM_Write" (ByVal CardNum As Long, ByVal Addr As Long, ByVal Data As Long) As Long
Public Declare Function AIO16_ADC_Cal Lib "AIO16" Alias "VBAIO16_ADC_Cal" (ByVal CardNum As Long, ByVal M As Long, ByVal B As Long) As Long
Public Declare Function AIO16_DAC_Cal Lib "AIO16" Alias "VBAIO16_DAC_Cal" (ByVal CardNum As Long, ByVal DACNum As Long, ByVal M As Long) As Long
Public Declare Function AIO16_LoadCal Lib "AIO16" Alias "VBAIO16_LoadCal" (ByVal CardNum As Long) As Long

These functions are not generally useful to the customer, but are exported for use by our calibration program. Briefly: