Attribute VB_Name = "AIO"
Option Explicit

'======================================================================
'======================================================================
'  API-CAP(W32)
'  CCAPAIO.BAS                    CONTEC.CO.,LTD.
'======================================================================
'======================================================================

'======================================================================
' Range
'======================================================================
Public Const PM10 = 0                   '+-10V
Public Const PM5 = 1                    '+-5V
Public Const P10 = 50                   '0~10V
Public Const P5 = 51                    '0~5V
Public Const P20MA = 100                '0~20mA

'======================================================================
' Error Code
'======================================================================
Public Const AIO_ERR_SUCCESS = 0                        'Successed
Public Const AIO_ERR_INI_MEMORY = 3                     'Cannot allocate memory
Public Const AIO_ERR_INI_REGISTRY = 4                   'Cannot access setting file
Public Const AIO_ERR_DLL_DEVICE_NAME = 10000            'Used DeviceName unwritten in setting file
Public Const AIO_ERR_DLL_INVALID_ID = 10001             'Invalid Id
Public Const AIO_ERR_DLL_CREATE_FILE = 10003            'Cannot open
Public Const AIO_ERR_DLL_CLOSE_FILE = 10004             'Close error
Public Const AIO_ERR_INFO_NOT_FIND_DEVICE = 10006       'Not find device
Public Const AIO_ERR_PTR_DEVICE_NAME = 10007            'DeviceName is NULL
Public Const AIO_ERR_PTR_DEVICE = 10008                 'Device is NULL
Public Const AIO_ERR_UNKNOWN_DEVICE = 10013             'Unknown device
Public Const AIO_ERR_PTR_DEVICE_TYPE = 10015            'DeviceType is NULL
Public Const AIO_ERR_INFO_INVALID_DEVICE = 10050        'Invalid device
Public Const AIO_ERR_NULL_DEVICE = 10100                'DeviceName is NULL string
Public Const AIO_ERR_PTR_ID = 10101                     'Id is NULL
Public Const AIO_ERR_PTR_ERR_STR = 10180                'ErrorString is NULL
Public Const AIO_ERR_PTR_AI_RANGE = 11051               'AiRange is NULL
Public Const AIO_ERR_AI_RANGE = 11060                   'AiRange is out of range
Public Const AIO_ERR_AI_CHANNEL = 11420                 'AiChannel is out of range
Public Const AIO_ERR_PTR_AI_DATA = 11421                'AiData is NULL
Public Const AIO_ERR_PTR_AI_MAX_CHANNELS = 11720        'AiMaxChannels is NULL
Public Const AIO_ERR_PTR_AI_RESOLUTION = 11740          'AiResolution is NULL
Public Const AIO_ERR_AO_CHANNEL = 13000                 'AoChannel is out of range
Public Const AIO_ERR_AO_CHANNELS = 13020                'AoChannels is out of range
Public Const AIO_ERR_PTR_AO_DATA = 13021                'AoData is NULL
Public Const AIO_ERR_PTR_AO_RESOLUTION = 13040          'AoResolution is NULL
Public Const AIO_ERR_PTR_AO_MAX_CHANNELS = 13080        'AoMaxChannels is NULL
Public Const AIO_ERR_PTR_AO_RANGE = 13111               'AoRange is NULL
Public Const AIO_ERR_AO_RANGE = 13120                   'AoRange is out of range
Public Const AIO_ERR_SYS_NOT_SUPPORTED = 20001          'Function is not supported
Public Const AIO_ERR_DEVICE_BUSY = 20002                'Device is busy
Public Const AIO_ERR_AI_DEVICE_RANGE = 21060            'AiRange is out of range
Public Const AIO_ERR_AI_SET_RANGE = 21063               'Range setting error
Public Const AIO_ERR_AI_DEVICE_CHANNEL = 21420          'AiChannel is out of range
Public Const AIO_ERR_AD_ERROR = 21421                   'AD transter error
Public Const AIO_ERR_AI_CHANNEL_NUM_OVER = 21441        'Number of Channels is over
Public Const AIO_ERR_AO_DEVICE_CHANNEL = 23000          'AoChannel is out of range
Public Const AIO_ERR_DA_ERROR = 23001                   'DA transfer error
Public Const AIO_ERR_AO_DATA_RANGE1 = 23002             'AoData must be from 0 to 4095
Public Const AIO_ERR_AO_DATA_RANGE2 = 23003             'AoData must be from 0 to 605535
Public Const AIO_ERR_AO_CHANNEL_NUM_OVER = 23021        'Number of Channels is over
Public Const AIO_ERR_AO_DEVICE_RANGE = 23120            'AoRange is out of range
Public Const AIO_ERR_AO_SET_RANGE = 23121               'Range setting error
Public Const AIO_ERR_START_ERROR = 28001                'Module start error
Public Const AIO_ERR_NOT_START = 28002                  'Device is not started
Public Const AIO_ERR_ACCESS_RIGHT = 28003               'Access rights error
Public Const AIO_ERR_DLL_TIMEOUT = 28004                'Timeout
Public Const AIO_ERR_COMPOSITION = 28005                'Unknown error

'======================================================================
' Function Prototype
'======================================================================
Declare Function AioInit Lib "CCAPAIO.DLL" (ByVal DeviceName As String, ByRef Id As Integer) As Long
Declare Function AioExit Lib "CCAPAIO.DLL" (ByVal Id As Integer) As Long
Declare Function AioGetErrorString Lib "CCAPAIO.DLL" (ByVal Err As Long, ByVal szMsg As String) As Long
Declare Function AioQueryDeviceName Lib "CCAPAIO.DLL" (ByVal Index As Integer, ByRef GroupID As Integer, ByRef UnitID As Integer, ByRef DeviceID As Integer, ByVal DeviceName As String, ByVal Device As String) As Long
Declare Function AioGetDeviceType Lib "CCAPAIO.DLL" (ByVal Device As String, ByRef DeviceType As Integer) As Long

Declare Function AioSetAccessRight Lib "CCAPAIO.DLL" (ByRef AccsRight As Byte) As Long
Declare Function AioSetDirectMode Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal DirectMode As Integer) As Long
Declare Function AioSetIOInterval Lib "CCAPAIO.DLL" (ByVal Interval As Long) As Long
Declare Function AioStartIO Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal Start As Integer) As Long
Declare Function AioGetRemoteStatus Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByRef Start As Byte, ByRef Status As Byte) As Long

Declare Function AioSingleAi Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AiChannel As Integer, ByRef AiData As Long) As Long
Declare Function AioSingleAiEx Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AiChannel As Integer, ByRef AiData As Single) As Long
Declare Function AioMultiAi Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AiChannels As Integer, ByRef AiData As Long) As Long
Declare Function AioMultiAiEx Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AiChannels As Integer, ByRef AiData As Single) As Long
Declare Function AioGetAiResolution Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByRef AiResolution As Integer) As Long
Declare Function AioGetAiMaxChannels Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByRef AiMaxChannels As Integer) As Long
Declare Function AioSetAiRangeAll Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AiRange As Integer) As Long
Declare Function AioGetAiRange Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AiChannel As Integer, ByRef AiRange As Integer) As Long

Declare Function AioSingleAo Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoChannel As Integer, ByVal AoData As Long) As Long
Declare Function AioSingleAoEx Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoChannel As Integer, ByVal AoData As Single) As Long
Declare Function AioSingleAoEcho Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoChannel As Integer, ByRef AoData As Long) As Long
Declare Function AioMultiAo Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoChannels As Integer, ByRef AoData As Long) As Long
Declare Function AioMultiAoEx Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoChannels As Integer, ByRef AoData As Single) As Long
Declare Function AioMultiAoEcho Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoChannels As Integer, ByRef AoData As Long) As Long
Declare Function AioGetAoResolution Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByRef AoResolution As Integer) As Long
Declare Function AioGetAoMaxChannels Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByRef AoMaxChannels As Integer) As Long
Declare Function AioSetAoRangeAll Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoRange As Integer) As Long
Declare Function AioGetAoRange Lib "CCAPAIO.DLL" (ByVal Id As Integer, ByVal AoChannel As Integer, ByRef AoRange As Integer) As Long