Attribute VB_Name = "CNT"
Option Explicit

'======================================================================
'======================================================================
'  API-CAP(W32)
'  CCAPCNT.H                   CONTEC.CO.,LTD.
'======================================================================
'======================================================================


'======================================================================
' Error Code
'======================================================================
Public Const CNT_ERR_SUCCESS = 0                        'Successed
Public Const CNT_ERR_INI_MEMORY = 3                     'Cannot allocate memory
Public Const CNT_ERR_INI_REGISTRY = 4                   'Cannot acceess setting file
Public Const CNT_ERR_DLL_DEVICE_NAME = 10000            'Used DeviceName unwritten in setting file
Public Const CNT_ERR_DLL_INVALID_ID = 10001             'Invalid Id
Public Const CNT_ERR_START = 10002                      'Module start error
Public Const CNT_ERR_DLL_CREATE_FILE = 10003            'Cannot open
Public Const CNT_ERR_DLL_CLOSE_FILE = 10004             'Close error
Public Const CNT_ERR_ACCESS_RIGHT = 10005               'Access rights error
Public Const CNT_ERR_DLL_TIMEOUT = 10006                'Timeout
Public Const CNT_ERR_COMPOSITION = 10007                'System error
Public Const CNT_ERR_INFO_INVALID_DEVICE = 10050        'Invalid device
Public Const CNT_ERR_INFO_NOT_FIND_DEVICE = 10051       'Not find device
Public Const CNT_ERR_DLL_MODE = 10100                   'Invalid mode
Public Const CNT_ERR_DLL_BUFF_ADDRESS = 10101           'Buffer address error
Public Const CNT_ERR_SYS_NOT_SUPPORTED = 20001          'Function is not supported
Public Const CNT_ERR_SYS_CH_NO = 20201                  'Invalid channdl number
Public Const CNT_ERR_SYS_CH_NUM = 20202                 'Invalid number of channels
Public Const CNT_ERR_SYS_CH_VALUE = 20203               'Invalid counter value

'======================================================================
' Parameter Definition
'======================================================================
Public Const CNT_ZPHASE_NOT_USE = 1         'Not use
Public Const CNT_ZPHASE_NEXT_ONE = 2        'Next time
Public Const CNT_ZPHASE_EVERY_TIME = 3      'Everytime
'
Public Const CNT_ZLOGIC_POSITIVE = 0        'Positive logic
Public Const CNT_ZLOGIC_NEGATIVE = 1        'Negative logic

Public Const CNT_SIGTYPE_ISOLATE = 0        'Photoisolator
Public Const CNT_SIGTYPE_TTL = 1            'TTL(reserved)
Public Const CNT_SIGTYPE_LINERECEIVER = 2   'Differential(reserved)

Public Const CNT_DIR_DOWN = 0               'Down-count
Public Const CNT_DIR_UP = 1                 'Up-count

Public Const CNT_MODE_1PHASE = 0            '1 Phase
Public Const CNT_MODE_2PHASE = 1            '2 Phase
Public Const CNT_MODE_GATECONTROL = 2       'Gate control

Public Const CNT_MUL_X1 = 0                 'x1
Public Const CNT_MUL_X2 = 1                 'x2
Public Const CNT_MUL_X4 = 2                 'x4

Public Const CNT_CLR_ASYNC = 0              'Asynchronous clear
Public Const CNT_CLR_SYNC = 1               'Synchronous clear
'
'======================================================================
' Function Prototype
'======================================================================
Declare Function CntInit Lib "CCAPCNT.DLL" (ByVal Devicename As String, ByRef Id As Integer) As Long
Declare Function CntExit Lib "CCAPCNT.DLL" (ByVal Id As Integer) As Long
Declare Function CntGetErrorString Lib "CCAPCNT.DLL" (ByVal Err As Long, ByVal szMsg As String) As Long
Declare Function CntQueryDeviceName Lib "CCAPCNT.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 CntSetAccessRight Lib "CCAPCNT.DLL" (ByRef AccsRight As Byte) As Long
Declare Function CntSetDirectMode Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal DirectMode As Integer) As Long
Declare Function CntSetIOInterval Lib "CCAPCNT.DLL" (ByVal Interval As Long) As Long
Declare Function CntStartIO Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal Start As Integer) As Long
Declare Function CntGetRemoteStatus Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByRef Start As Byte, ByRef Status As Byte) As Long

Declare Function CntSetZMode Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal Mode As Integer) As Long
Declare Function CntSetZLogic Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal ZLogic As Integer) As Long
Declare Function CntSelectChannelSignal Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal SigType As Integer) As Long
Declare Function CntSetCountDirection Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal Dir As Integer) As Long
Declare Function CntSetOperationMode Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal Phase As Integer, ByVal Mul As Integer, ByVal SyncClr As Integer) As Long
Declare Function CntSetDigitalFilter Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal FilterValue As Integer) As Long
Declare Function CntSetPulseWidth Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal PlsWidth As Long) As Long

Declare Function CntGetZMode Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef Mode As Integer) As Long
Declare Function CntGetZLogic Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef ZLogic As Integer) As Long
Declare Function CntGetChannelSignal Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef SigType As Integer) As Long
Declare Function CntGetCountDirection Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef Dir As Integer) As Long
Declare Function CntGetOperationMode Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef Phase As Integer, ByRef Mul As Integer, ByRef SyncClr As Integer) As Long
Declare Function CntGetDigitalFilter Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef FilterValue As Integer) As Long
Declare Function CntGetPulseWidth Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef PlsWidth As Long) As Long

Declare Function CntStartCount Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByRef ChNo As Integer, ByVal ChNum As Integer) As Long
Declare Function CntStopCount Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByRef ChNo As Integer, ByVal ChNum As Integer) As Long
Declare Function CntPreset Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByRef ChNo As Integer, ByVal ChNum As Integer, ByRef PresetData As Long) As Long
Declare Function CntSetStartPreset Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal PresetData As Long, ByVal bEnable As Integer) As Long
Declare Function CntGetStartPreset Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef PresetData As Long, ByRef bEnable As Integer) As Long
Declare Function CntReadCount Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByRef ChNo As Integer, ByVal ChNum As Integer, ByRef CntDat As Long) As Long
Declare Function CntReadStatus Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByRef Sts As Integer) As Long
Declare Function CntResetStatus Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal Sts As Integer) As Long
Declare Function CntInputDIByte Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal Reserved As Integer, ByRef bData As Byte) As Long
Declare Function CntSetCountMatchEvent Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal RegNo As Integer, ByVal Count As Long, ByVal Start As Integer) As Long
Declare Function CntGetCountMatchReg Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByVal ChNo As Integer, ByVal RegNo As Integer, ByRef Count As Long) As Long
Declare Function CntGetMaxChannels Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByRef ChannelNum As Integer) As Long
Declare Function CntResetChannel Lib "CCAPCNT.DLL" (ByVal Id As Integer, ByRef ChNo As Integer, ByVal ChNum As Integer) As Long
