﻿Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices
Imports System.Text
Module CCNT
    '============================================================-
	' CCNT.vb
    ' Headder file for CONTEC Counter device
    '                                              CONTEC.Co.,Ltd.
    '============================================================-

    '-------------------------------------------------------------
    'Delegate
    '-------------------------------------------------------------
    Public Delegate Sub PCOUNTUPCALLBACK(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)
    Public Delegate Sub PCOUNTERERRORCALLBACK(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)
    Public Delegate Sub PCARRYBORROWCALLBACK(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)
    Public Delegate Sub PTIMERCALLBACK(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)

    Public Delegate Sub PSAMPLINGSTOPCALLBACK(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)
    Public Delegate Sub PSAMPLINGCOUNTCALLBACK(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)


    '-------------------------------------------------
	' Prototype definition
    '-------------------------------------------------

    ' Common function
    Declare Function CntInit Lib "CCNT.DLL" (ByVal DeviceName As String, ByRef Id As Short) As Integer
    Declare Function CntExit Lib "CCNT.DLL" (ByVal Id As Short) As Integer
    Declare Function CntResetDevice Lib "CCNT.DLL" (ByVal Id As Short) As Integer
    Declare Function CntGetErrorString Lib "CCNT.DLL" (ByVal ErrorCode As Integer, ByVal ErrorString As StringBuilder) As Integer
    ' Setting function (set)
    Declare Function CntSetZMode Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal ZMode As Short) As Integer
    Declare Function CntSetZLogic Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal ZLogic As Short) As Integer
    Declare Function CntSelectChannelSignal Lib "CCNT.DLL " (ByVal Id As Short, ByVal ChNo As Short, ByVal SigType As Short) As Integer
    Declare Function CntSetCountDirection Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal Dir_Renamed As Short) As Integer
    Declare Function CntSetOperationMode Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal Phase As Short, ByVal Mul As Short, ByVal SyncClr As Short) As Integer
    Declare Function CntSetDigitalFilter Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal FilterValue As Short) As Integer
    Declare Function CntSetPulseWidth Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal PlsWidth As Short) As Integer
	Declare Function CntSetDIType Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal InputType As Short) As Integer
	Declare Function CntSetOutputHardwareEvent Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal OutputLogic As Short, ByVal EventType As Integer, ByVal PulseWidth As Short) As Integer
	Declare Function CntSetInputHardwareEvent Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal EventType As Integer, ByVal RF0 As Short, ByVal RF1 As Short, ByVal Reserved As Short) As Integer
	Declare Function CntSetCountMatchHardwareEvent Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal RegisterNo As Short, ByVal EventType As Integer, ByVal Reserved As Short) As Integer
	Declare Function CntSetPresetRegister Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal PresetData As Integer, ByVal Reserved As Short) As Integer

    ' Setting function (get)
    Declare Function CntGetZMode Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef ZMode As Short) As Integer
    Declare Function CntGetZLogic Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef ZLogic As Short) As Integer
    Declare Function CntGetChannelSignal Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef SigType As Short) As Integer
    Declare Function CntGetCountDirection Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef Dir_Renamed As Short) As Integer
    Declare Function CntGetOperationMode Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef Phase As Short, ByRef Mul As Short, ByRef SyncClr As Short) As Integer
    Declare Function CntGetDigitalFilter Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef FilterValue As Short) As Integer
    Declare Function CntGetPulseWidth Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef PlsWidth As Short) As Integer
    ' Counter function
    Declare Function CntStartCount Lib "CCNT.DLL" (ByVal Id As Short, <MarshalAs(UnmanagedType.LPArray)> ByVal ChNo() As Short, ByVal ChNum As Short) As Integer
    Declare Function CntStopCount Lib "CCNT.DLL" (ByVal Id As Short, <MarshalAs(UnmanagedType.LPArray)> ByVal ChNo() As Short, ByVal ChNum As Short) As Integer
    Declare Function CntPreset Lib "CCNT.DLL" (ByVal Id As Short, <MarshalAs(UnmanagedType.LPArray)> ByVal ChNo() As Short, ByVal ChNum As Short, <MarshalAs(UnmanagedType.LPArray)> ByVal PresetData() As Integer) As Integer
    Declare Function CntZeroClearCount Lib "CCNT.DLL" (ByVal Id As Short, <MarshalAs(UnmanagedType.LPArray)> ByVal ChNo() As Short, ByVal ChNum As Short) As Integer
    Declare Function CntReadCount Lib "CCNT.DLL" (ByVal Id As Short, <MarshalAs(UnmanagedType.LPArray)> ByVal ChNo() As Short, ByVal ChNum As Short, <MarshalAs(UnmanagedType.LPArray)> ByVal CntDat() As Integer) As Integer
    Declare Function CntReadStatus Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef Sts As Short) As Integer
    Declare Function CntReadStatusEx Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByRef Sts As Integer) As Integer
    ' Count match function
    Declare Function CntNotifyCountUp Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal RegNo As Short, ByVal Count As Integer, ByVal hWnd As IntPtr) As Integer
    Declare Function CntStopNotifyCountUp Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal RegNo As Short) As Integer
	Declare Function CntNotifyCounterError Lib "CCNT.DLL" (ByVal Id As Short, ByVal hWnd As IntPtr) As Integer
	Declare Function CntStopNotifyCounterError Lib "CCNT.DLL" (ByVal Id As Short) As Integer
	Declare Function CntNotifyCarryBorrow Lib "CCNT.DLL" (ByVal Id As Short, ByVal hWnd As IntPtr) As Integer
    Declare Function CntStopNotifyCarryBorrow Lib "CCNT.DLL" (ByVal Id As Short) As Integer
    Declare Function CntCountUpCallbackProc Lib "CCNT.DLL" (ByVal Id As Short, ByVal SetCountUpCallBackProc As IntPtr, ByVal Param As IntPtr) As Integer
    Declare Function CntCounterErrorCallbackProc Lib "CCNT.DLL" (ByVal Id As Short, ByVal CounterErrorCallBackProc As IntPtr, ByVal Param As IntPtr) As Integer
    Declare Function CntCarryBorrowCallbackProc Lib "CCNT.DLL" (ByVal Id As Short, ByVal CarryBorrowCallBackProc As IntPtr, ByVal Param As IntPtr) As Integer
    ' Timer function
	Declare Function CntNotifyTimer Lib "CCNT.DLL" (ByVal Id As Short, ByVal TimValue As Integer, ByVal hWnd As IntPtr) As Integer
    Declare Function CntStopNotifyTimer Lib "CCNT.DLL" (ByVal Id As Short) As Integer
    Declare Function CntTimerCallbackProc Lib "CCNT.DLL" (ByVal Id As Short, ByVal TimerCallBackProc As IntPtr, ByVal Param As IntPtr) As Integer
    ' General purpose input function
    Declare Function CntInputDIByte Lib "CCNT.DLL" (ByVal Id As Short, ByVal Reserved As Short, ByRef bData As Byte) As Integer
	Declare Function CntOutputDOBit Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal Reserved As Short, ByVal OutData As Byte) As Integer
    ' Information function
	Declare Function CntQueryDeviceName Lib "CCNT.DLL" (ByVal Index As Short, ByVal DeviceName As String, ByVal Device As String) As Integer
    Declare Function CntGetMaxChannels Lib "CCNT.DLL" (ByVal Id As Short, ByRef DeviceType As Short) As Integer
    Declare Function CntGetNetCommunicationInfo Lib "CCNT.DLL" (ByVal Id As Short, ByVal InfoType As Short, ByRef InfoData As Integer) As Integer
	' Test function
	Declare Function CntSetTestPulse Lib "CCNT.DLL" (ByVal Id As Short, ByVal Internal As Short, ByVal Out As Short, ByVal Reserved As Integer) As Integer
	' Sampling mode function
	Declare Function CntSetSyncSignal Lib "CCNT.DLL" (ByVal Id As Short, ByVal StartSignal As Short, ByVal StopSignal As Short, ByVal ClockSignal As Short) As Integer
	Declare Function CntSetStandAlone Lib "CCNT.DLL" (ByVal Id As Short) As Integer
	Declare Function CntSetMaster Lib "CCNT.DLL" (ByVal Id As Short, ByVal ExtSig1 As Short, ByVal ExtSig2 As Short, ByVal ExtSig3 As Short, ByVal MasterHalt As Short, ByVal SlaveHalt As Short) As Integer
	Declare Function CntSetSlave Lib "CCNT.DLL" (ByVal Id As Short, ByVal ExtSig1 As Short, ByVal ExtSig2 As Short, ByVal ExtSig3 As Short, ByVal MasterHalt As Short, ByVal SlaveHalt As Short) As Integer
	Declare Function CntSetCounterMode Lib "CCNT.DLL" (ByVal Id As Short, ByVal ChNo As Short, ByVal CountMode As Short) As Integer
	' Sampling condition function
	Declare Function CntSetSamplingStartTrigger Lib "CCNT.DLL" (ByVal Id As Short, ByVal StartTrg As Short, ByVal CountStartMode As Short, ByVal CountChNum As Short) As Integer
	Declare Function CntSetSamplingClockTrigger Lib "CCNT.DLL" (ByVal Id As Short, ByVal ClockTrg As Short) As Integer
	Declare Function CntSetSamplingStopTrigger Lib "CCNT.DLL" (ByVal Id As Short, ByVal StopTrg As Short, ByVal CountStopMode As Short, ByVal CountChNum As Short) As Integer
	Declare Function CntSetSamplingInternalClock Lib "CCNT.DLL" (ByVal Id As Short, ByVal Clock As Integer, ByVal Unit As Short) As Integer
	Declare Function CntSetSamplingStopNumber Lib "CCNT.DLL" (ByVal Id As Short, ByVal StopNum As Integer) As Integer
	' Sampling message function
	Declare Function CntNotifySamplingStop Lib "CCNT.DLL" (ByVal Id As Short, ByVal hWnd As IntPtr) As Integer
    Declare Function CntNotifySamplingCount Lib "CCNT.DLL" (ByVal Id As Short, ByVal Count As Integer, ByVal hWnd As IntPtr) As Integer
    Declare Function CntSamplingStopCallbackProc Lib "CCNT.DLL" (ByVal Id As Short, ByVal SamplingStopCallBackProc As IntPtr, ByVal Param As IntPtr) As Integer
    Declare Function CntSamplingCountCallbackProc Lib "CCNT.DLL" (ByVal Id As Short, ByVal SamplingCountCallBackProc As IntPtr, ByVal Param As IntPtr) As Integer
	' Sampling operation function
	Declare Function CntSamplingFifoReset Lib "CCNT.DLL" (ByVal Id As Short) As Integer
	Declare Function CntSamplingSetBuffer Lib "CCNT.DLL" (ByVal Id As Short, ByVal Buffer As IntPtr, ByVal ChNum As Short, ByVal ScanNum As Integer, ByVal IsRing As Short) As Integer
	Declare Function CntSamplingStart Lib "CCNT.DLL" (ByVal Id As Short) As Integer
	Declare Function CntSamplingStop Lib "CCNT.DLL" (ByVal Id As Short) As Integer
	' Sampling status function
	Declare Function CntGetSamplingStatus Lib "CCNT.DLL" (ByVal Id As Short, ByRef Status As Integer, ByRef Err As Integer) As Integer
	Declare Function CntGetSamplingCount Lib "CCNT.DLL" (ByVal Id As Short, ByRef ScanCount As Integer, ByRef ScanCarry As Integer) As Integer
	Declare Function CntGetSamplingWritePointer Lib "CCNT.DLL" (ByVal Id As Short, ByRef WritePointer As Integer, ByRef ScanCount As Integer, ByRef ScanCarry As Integer) As Integer

	Declare Function CntGetDeviceInfo Lib "CCNT.DLL" (ByVal Device As String, ByVal InfoType As Short, ByRef Param1 As Integer, ByRef Param2 As Integer, ByRef Param3 As Integer) As Integer
	Declare Function CntGetDeviceType Lib "CCNT.DLL" (ByVal Device As String, ByRef DeviceType As Short) As Integer
    '-------------------------------------------------
	' Device Type
    '-------------------------------------------------
	Public Const DEVICE_TYPE_ISA As Short = 0						'ISA or C bus
	Public Const DEVICE_TYPE_PCI As Short = 1						'PCI bus
    Public Const DEVICE_TYPE_PCMCIA As Short = 2    		        'PCMCIA
    Public Const DEVICE_TYPE_USB As Short = 3               		'USB
    Public Const DEVICE_TYPE_FIT As Short = 4						'FIT
    '-------------------------------------------------
	' Mode definition
    '-------------------------------------------------
    ' Z Phase Mode
    Public Const CNT_ZPHASE_NOT_USE As Short = 1
    Public Const CNT_ZPHASE_NEXT_ONE As Short = 2
    Public Const CNT_ZPHASE_EVERY_TIME As Short = 3
    ' Z Phase Logic
    Public Const CNT_ZLOGIC_POSITIVE As Short = 0
    Public Const CNT_ZLOGIC_NEGATIVE As Short = 1
    ' Signal Source
    Public Const CNT_SIGTYPE_ISOLATE As Short = 0
    Public Const CNT_SIGTYPE_TTL As Short = 1
    Public Const CNT_SIGTYPE_LINERECEIVER As Short = 2
    ' Count Direction
    Public Const CNT_DIR_DOWN As Short = 0
    Public Const CNT_DIR_UP As Short = 1
    ' 1Phase/2Phase
    Public Const CNT_MODE_1PHASE As Short = 0
    Public Const CNT_MODE_2PHASE As Short = 1
    Public Const CNT_MODE_GATECONTROL As Short = 2
    ' Mul
    Public Const CNT_MUL_X1 As Short = 0
    Public Const CNT_MUL_X2 As Short = 1
    Public Const CNT_MUL_X4 As Short = 2
    ' Sync Clear
    Public Const CNT_CLR_ASYNC As Short = 0
    Public Const CNT_CLR_SYNC As Short = 1
	' Gate Control
	Public Const CNT_UPDOWN As Short = 1
	Public ConstCNT_GATECONTROL As Short = 0
    ' Generic I/O Signal
    Public Const CNT_GENIO_LINERECEIVER As Short = 0
    Public Const CNT_GENIO_TTL As Short = 1
	' Output Logic
	Public Const CNT_OEVENT_NEGATIVE As Short = 0
	Public Const CNT_OEVENT_POSITIVE As Short = 1
	' Output Hardware Event
	Public Const CNT_OEVENT_GENOUT As Short = &H0S
	Public Const CNT_OEVENT_MATCH0 As Short = &H1S
	Public Const CNT_OEVENT_MATCH1 As Short = &H2S
	Public Const CNT_OEVENT_FLTERR As Short = &H4S
	Public Const CNT_OEVENT_AIERR As Short = &H8S
	Public Const CNT_OEVENT_ALMERR As Short = &H10S
	' Input Signal Event
	Public Const CNT_IEVENT_GENINP As Short = 0
	Public Const CNT_IEVENT_STARTSTOP As Short = 1
	Public Const CNT_IEVENT_PRESET As Short = 2
	Public Const CNT_IEVENT_CLEAR As Short = 3
	' Count Match Event
	Public Const CNT_MATCH_NONE As Short = 0
	Public Const CNT_MATCH_PRESET As Short = 1
	Public Const CNT_MATCH_CLEAR As Short = 2
	' RIZE/FALL
	Public Const CNT_INP_NONE As Short = 0
	Public Const CNT_INP_RIZE As Short = 1
	Public Const CNT_INP_FALL As Short = 2
	' Error Type
	Public Const CNT_AI_ERROR As Short = 1
	Public Const CNT_FLT_ERROR As Short = 2
	Public Const CNT_ALM_ERROR As Short = 3
	' Carry/Borrow
	Public Const CNT_CB_CARRY As Short = 1
	Public Const CNT_CB_BORROW As Short = 2
    ' Device Information
    Public Const ICNT_DEVICE_TYPE As Short = 0              ' device type.                          Param1:short
	Public Const ICNT_NUMBER_OF_CH As Short = 1						' channel number			Param1:int
	Public Const ICNT_BIT As Short = 2								' bit number				Param1:int
	Public Const ICNT_IS_DIGITAL_FILTER As Short = 3				' digital filter			Param1:BOOL(True/False)
	Public Const ICNT_IS_DEFF As Short = 4							' defferential replace of all-purpose input		Param1:BOOL(True/False)
	Public Const ICNT_CNTSOURCE As Short = 5						' counter signal source		Param1:int(BIT0:TTL, BIT1:PHOTO, BIT2:LINERECEIVER)
	'Cnt Source
    Public Const ICNT_CNTSOURCE_TTL As Short = &H1S
    Public Const ICNT_CNTSOURCE_PHOTO As Short = &H2S
    Public Const ICNT_CNTSOURCE_LINERECEIVER As Short = &H4S
	' SyncSignal
	Public Const CNTS_CLOCK_OUT_OFF As Short = 0
	Public Const CNTS_CLOCK_OUT_ON As Short = 1
	Public Const CNTS_START_OUT_OFF As Short = 0
	Public Const CNTS_START_OUT_ON As Short = 1
	Public Const CNTS_STOP_OUT_OFF As Short = 0
	Public Const CNTS_STOP_OUT_ON As Short = 1
	' ExtSig
	Public Const CNTS_EXT_NOTUSE As Short = 0						' Not Used
	Public Const CNTS_EXT_START_SOFT As Short = 1					' Software Start
	Public Const CNTS_EXT_STOP_SOFT As Short = 2					' Software Stop
	Public Const CNTS_EXT_CLOCK As Short = 3						' Internal Clock
	Public Const CNTS_EXT_EXT_TRG As Short = 4						' External Clock
	Public Const CNTS_EXT_START_EXT_RISE As Short = 5				' External Start Rize
	Public Const CNTS_EXT_START_EXT_FALL As Short = 6				' External Start Fall
	Public Const CNTS_EXT_STOP_EXT_RISE As Short = 7				' External Stop Rize
	Public Const CNTS_EXT_STOP_EXT_FALL As Short = 8				' External Stop Fall
	Public Const CNTS_EXT_CLOCK_ERROR As Short = 9					' Sampling Clock Error
	Public Const CNTS_EXT_TRNSNUM As Short = 10						' Stop Number of Transfer Data
	Public Const CNTS_EXT_CNTMATCH_CH0_REG0 As Short = 11			' Count Match Ch0:REG0
	Public Const CNTS_EXT_CNTMATCH_CH1_REG0 As Short = 12			' Count Match CH1:REG0
	Public Const CNTS_EXT_CNTMATCH_CH2_REG0 As Short = 13			' Count Match CH2:REG0
	Public Const CNTS_EXT_CNTMATCH_CH3_REG0 As Short = 14			' Count Match CH3:REG0
	Public Const CNTS_EXT_CNTMATCH_CH4_REG0 As Short = 15			' Count Match CH4:REG0
	Public Const CNTS_EXT_CNTMATCH_CH5_REG0 As Short = 16			' Count Match CH5:REG0
	Public Const CNTS_EXT_CNTMATCH_CH6_REG0 As Short = 17			' Count Match CH6:REG0
	Public Const CNTS_EXT_CNTMATCH_CH7_REG0 As Short = 18			' Count Match CH7:REG0
	Public Const CNTS_EXT_CNTMATCH_CH0_REG1 As Short = 19			' Count Match CH0:REG1
	Public Const CNTS_EXT_CNTMATCH_CH1_REG1 As Short = 20			' Count Match CH1:REG1
	Public Const CNTS_EXT_CNTMATCH_CH2_REG1 As Short = 21			' Count Match CH2:REG1
	Public Const CNTS_EXT_CNTMATCH_CH3_REG1 As Short = 22			' Count Match CH3:REG1
	Public Const CNTS_EXT_CNTMATCH_CH4_REG1 As Short = 23			' Count Match CH4:REG1
	Public Const CNTS_EXT_CNTMATCH_CH5_REG1 As Short = 24			' Count Match CH5:REG1
	Public Const CNTS_EXT_CNTMATCH_CH6_REG1 As Short = 25			' Count Match CH6:REG1
	Public Const CNTS_EXT_CNTMATCH_CH7_REG1 As Short = 26			' Count Match CH7:REG1
	' Count Mode
	Public Const CNTS_MODE_NORMAL As Short = 0						' Normal Counter
	Public Const CNTS_MODE_DIFF As Short = 1						' Differencial Counter
	' Sampling Start
	Public Const CNTS_START_SOFT As Short = 1						' Software Start
	Public Const CNTS_START_EXT_RISE As Short = 2					' External Start Rize
	Public Const CNTS_START_EXT_FALL As Short = 3					' External Start Fall
	Public Const CNTS_START_CNTMATCH_CH0_REG0 As Short = 4			' Count Match CH0:REG0
	Public Const CNTS_START_CNTMATCH_CH1_REG0 As Short = 5			' Count Match CH1:REG0
	Public Const CNTS_START_CNTMATCH_CH2_REG0 As Short = 6			' Count Match CH2:REG0
	Public Const CNTS_START_CNTMATCH_CH3_REG0 As Short = 7			' Count Match CH3:REG0
	Public Const CNTS_START_CNTMATCH_CH4_REG0 As Short = 8			' Count Match CH4:REG0
	Public Const CNTS_START_CNTMATCH_CH5_REG0 As Short = 9			' Count Match CH5:REG0
	Public Const CNTS_START_CNTMATCH_CH6_REG0 As Short = 10			' Count Match CH6:REG0
	Public Const CNTS_START_CNTMATCH_CH7_REG0 As Short = 11			' Count Match CH7:REG0
	Public Const CNTS_START_CNTMATCH_CH0_REG1 As Short = 12			' Count Match CH0:REG1
	Public Const CNTS_START_CNTMATCH_CH1_REG1 As Short = 13			' Count Match CH1:REG1
	Public Const CNTS_START_CNTMATCH_CH2_REG1 As Short = 14			' Count Match CH2:REG1
	Public Const CNTS_START_CNTMATCH_CH3_REG1 As Short = 15			' Count Match CH3:REG1
	Public Const CNTS_START_CNTMATCH_CH4_REG1 As Short = 16			' Count Match CH4:REG1
	Public Const CNTS_START_CNTMATCH_CH5_REG1 As Short = 17			' Count Match CH5:REG1
	Public Const CNTS_START_CNTMATCH_CH6_REG1 As Short = 18			' Count Match CH6:REG1
	Public Const CNTS_START_CNTMATCH_CH7_REG1 As Short = 19			' Count Match CH7:REG1
	Public Const CNTS_START_EXTSIG_1 As Short = 20					' EXTSIG1
	Public Const CNTS_START_EXTSIG_2 As Short = 21					' EXTSIG2
	Public Const CNTS_START_EXTSIG_3 As Short = 22					' EXTSIG3
	' Counter Start
	Public Const CNTS_START_CNT_NOT_WITH_SAMP As Short = 3			' Counter Start not with Sampling Start
	Public Const CNTS_START_CNT_WITH_SAMP As Short = 4				' Counter Start with Sampling Start
	' Sampling Clock
	Public Const CNTS_CLOCK_CLOCK As Short = 1						' Internal Clock
	Public Const CNTS_CLOCK_EXT_TRG As Short = 2					' External Clock
	Public Const CNTS_CLOCK_EXTSIG_1 As Short = 3					' EXTSIG1
	Public Const CNTS_CLOCK_EXTSIG_2 As Short = 4					' EXTSIG2
	Public Const CNTS_CLOCK_EXTSIG_3 As Short = 5					' EXTSIG3
	' Sampling Stop
	Public Const CNTS_STOP_SOFT As Short = 1						' Software Stop
	Public Const CNTS_STOP_EXT_RISE As Short = 2					' External Stop Rize
	Public Const CNTS_STOP_EXT_FALL As Short = 3					' External Stop Fall
	Public Const CNTS_STOP_NUM As Short = 4							' Stop with Number of Data
	Public Const CNTS_STOP_CNTMATCH_CH0_REG0 As Short = 5			' Count Match CH0:REG0
	Public Const CNTS_STOP_CNTMATCH_CH1_REG0 As Short = 6			' Count Match CH1:REG0
	Public Const CNTS_STOP_CNTMATCH_CH2_REG0 As Short = 7			' Count Match CH2:REG0
	Public Const CNTS_STOP_CNTMATCH_CH3_REG0 As Short = 8			' Count Match CH3:REG0
	Public Const CNTS_STOP_CNTMATCH_CH4_REG0 As Short = 9			' Count Match CH4:REG0
	Public Const CNTS_STOP_CNTMATCH_CH5_REG0 As Short = 10			' Count Match CH5:REG0
	Public Const CNTS_STOP_CNTMATCH_CH6_REG0 As Short = 11			' Count Match CH6:REG0
	Public Const CNTS_STOP_CNTMATCH_CH7_REG0 As Short = 12			' Count Match CH7:REG0
	Public Const CNTS_STOP_CNTMATCH_CH0_REG1 As Short = 13			' Count Match CH0:REG1
	Public Const CNTS_STOP_CNTMATCH_CH1_REG1 As Short = 14			' Count Match CH1:REG1
	Public Const CNTS_STOP_CNTMATCH_CH2_REG1 As Short = 15			' Count Match CH2:REG1
	Public Const CNTS_STOP_CNTMATCH_CH3_REG1 As Short = 16			' Count Match CH3:REG1
	Public Const CNTS_STOP_CNTMATCH_CH4_REG1 As Short = 17			' Count Match CH4:REG1
	Public Const CNTS_STOP_CNTMATCH_CH5_REG1 As Short = 18			' Count Match CH5:REG1
	Public Const CNTS_STOP_CNTMATCH_CH6_REG1 As Short = 19			' Count Match CH6:REG1
	Public Const CNTS_STOP_CNTMATCH_CH7_REG1 As Short = 20			' Count Match CH7:REG1
	Public Const CNTS_STOP_EXTSIG_1 As Short = 21					' EXTSIG1
	Public Const CNTS_STOP_EXTSIG_2 As Short = 22					' EXTSIG2
	Public Const CNTS_STOP_EXTSIG_3 As Short = 23					' EXTSIG3
	' Clock Unit
	Public Const CNTS_TIM_UNIT_S As Short = 1
	Public Const CNTS_TIM_UNIT_MS As Short = 2
	Public Const CNTS_TIM_UNIT_US As Short = 3
	Public Const CNTS_TIM_UNIT_NS As Short = 4
	' Counter Stop
	Public Const CNTS_STOP_CNT_NOT_WITH_SAMP As Short = 3			' Counter Stop not with Sampling Stop
	Public Const CNTS_STOP_CNT_WITH_SAMP As Short = 4				' Counter Stop with Sampling Stop
	' Buffer
	Public Const CNTS_WRITE_ONCE As Short = 0
	Public Const CNTS_WRITE_RING As Short = 1
    '-------------------------------------------------
	' Message
    '-------------------------------------------------
	Public Const CNTM_COUNTUP_CH0 As Short = &H1100S				' COUNTUP, CHANNEL No.0
    Public Const CNTM_COUNTUP_CH1 As Short = &H1101S        '         "                   1
    Public Const CNTM_COUNTUP_CH2 As Short = &H1102S        '         "                   2
    Public Const CNTM_COUNTUP_CH3 As Short = &H1103S        '         "                   3
    Public Const CNTM_COUNTUP_CH4 As Short = &H1104S        '         "                   4
    Public Const CNTM_COUNTUP_CH5 As Short = &H1105S        '         "                   5
    Public Const CNTM_COUNTUP_CH6 As Short = &H1106S        '         "                   6
    Public Const CNTM_COUNTUP_CH7 As Short = &H1107S        '         "                   7

	Public Const CNTM_TIMER As Short = &H1140S						' Timer
	Public Const CNTM_COUNTER_ERROR As Short = &H1141S				' Counter Error
	Public Const CNTM_CARRY_BORROW As Short = &H1142S				' Carry/Borrow

	Public Const CNTM_SAMPLING_STOP As Short = &H1150S				' Stop sampling
	Public Const CNTM_SAMPLING_COUNT As Short = &H1151S				' Specified number sampling completed

	' Count Match Direction(UP=1, DOWN=2)
	Public Const CNTM_DIR_UP As short = 1							' match of up count
	Public Const CNTM_DIR_DOWN As short = 2							' match of down count

	'-------------------------------------------------
	' Status
	'-------------------------------------------------
	Public Const CNTS_STATUS_BMSTOP As short = &H1
	Public Const CNTS_STATUS_CNTSTART As short = &H2
	Public Const CNTS_STATUS_CNTSTOP As short = &H4
	Public Const CNTS_STATUS_TRGIN As short = &H8
	Public Const CNTS_STATUS_OVERRUN As short = &H10

	Public Const CNTS_STATUS_FIFOFULL As short = &H2
	Public Const CNTS_STATUS_SGOVERIN As short = &H4
	Public Const CNTS_STATUS_TRGERR As short = &H8
	Public Const CNTS_STATUS_CLKERR As short = &H10
	Public Const CNTS_STATUS_SLAVEHALT As short = &H20
	Public Const CNTS_STATUS_MASTERHALT As short = &H40

    '-------------------------------------------------
	' Error codes
    '-------------------------------------------------
    ' Initialize Error
    ' Common
	Public Const CNT_ERR_SUCCESS As Short = 0							' Normality completion
	Public Const CNT_ERR_INI_RESOURCE As Short = 1						' Failed in the acquisition of the resource.
	Public Const CNT_ERR_INI_INTERRUPT As Short = 2						' Failed in the registration of the interruption routine.
	Public Const CNT_ERR_INI_MEMORY As Short = 3						' Failed in the allocation of the memory.
	Public Const CNT_ERR_INI_REGISTRY As Short = 4						' Failed in the access of registry.
	Public Const CNT_ERR_SYS_RECOVERED_FROM_STANDBY As Short = 7		' Execute the function CntResetDevice to return from the standby mode.
	Public Const CNT_ERR_INI_NOT_FOUND_SYS_FILE As Short = 8			' Because the ccnt.sys file is not found, it is not possible to initialize it.
	Public Const CNT_ERR_INI_DLL_FILE_VERSION As Short = 9				' Because the version information on the ccnt.dll file cannot be retrieved, it is not possible to initialize it.
	Public Const CNT_ERR_INI_SYS_FILE_VERSION As Short = 10				' Because the version information on the ccnt.sys file cannot be retrieved, it is not possible to initialize it.
	Public Const CNT_ERR_INI_NO_MATCH_DRV_VERSION As Short = 11			' Because the version information of ccnt.dll is not corresponding to the version information of ccnt.sys, it is not possible to initialize it.
    ' CNT

    ' DLL Error
    ' Common
	Public Const CNT_ERR_DLL_DEVICE_NAME As Short = 10000				' The device name which wasn't registered by a device manager was specified.
	Public Const CNT_ERR_DLL_INVALID_ID As Short = 10001				' Invalid ID was specified.
	Public Const CNT_ERR_DLL_CALL_DRIVER As Short = 10002				' CNT driver can't be called (Failed in the device I/O control).
	Public Const CNT_ERR_DLL_CREATE_FILE As Short = 10003				' Failed in the creation of the file (Failed in CreateFile).
	Public Const CNT_ERR_DLL_CLOSE_FILE As Short = 10004				' Failed in the closing of the file (Failed in CloseFile).
	Public Const CNT_ERR_DLL_CREATE_THREAD As Short = 10005				' Failed in the creation of the thread (Failed in CreateThread).
	Public Const CNT_ERR_INFO_INVALID_DEVICE As Short = 10050			' The specified device name is not found. Please check spelling.
	Public Const CNT_ERR_INFO_NOT_FIND_DEVICE As Short = 10051			' No more device.
	Public Const CNT_ERR_INFO_INVALID_INFOTYPE As Short = 10052			' Information type is invalid.
    ' CNT
	Public Const CNT_ERR_DLL_MODE As Short = 10100						' Invalid mode setting.
	Public Const CNT_ERR_DLL_BUFF_ADDRESS As Short = 10101				' Invalid data buffer address.
	Public Const CNT_ERR_DLL_HWND As Short = 10200						' Window handle is invalid.

    ' SYS Error
    ' Common
	Public Const CNT_ERR_SYS_MEMORY As Short = 20000					' It failed in memory allocation for the object preparation.
	Public Const CNT_ERR_SYS_NOT_SUPPORTED As Short = 20001				' This function can't be used by this device.
	Public Const CNT_ERR_SYS_BOARD_EXECUTING As Short = 20002			' Cannot use while by another device works.
	Public Const CNT_ERR_SYS_USING_OTHER_PROCESS As Short = 20003		' Cannot use because another process is using the device.
    'ifndef  STATUS_SYS_USB_CRC
	Public Const STATUS_SYS_USB_CRC As Short = 20020					' The final data packet received from the endpoint have CRC error.
	Public Const STATUS_SYS_USB_BTSTUFF As Short = 20021				' The final data packet received from the endpoint have infract of bit stuff error.
	Public Const STATUS_SYS_USB_DATA_TOGGLE_MISMATCH As Short = 20022	' The final data packet received from the endpoint mismatch with the expected data toggle packet.
	Public Const STATUS_SYS_USB_STALL_PID As Short = 20023				' The STALL packet id returned from the endpoint.
	Public Const STATUS_SYS_USB_DEV_NOT_RESPONDING As Short = 20024		' The device is marked with unresponsive token (IN). Or it cannot support handshake.
	Public Const STATUS_SYS_USB_PID_CHECK_FAILURE As Short = 20025		' The device is marked with unresponsive token (IN). Or it cannot support handshake.
	Public Const STATUS_SYS_USB_UNEXPECTED_PID As Short = 20026			' Received packet id is invalid or undefined.
	Public Const STATUS_SYS_USB_DATA_OVERRUN As Short = 20027			' The size of the data returned from the endpoint is over the permitted maximum length of data packet or buffer remain.
	Public Const STATUS_SYS_USB_DATA_UNDERRUN As Short = 20028			' The size of the data returned from the endpoint is not up to the expectation.
	Public Const STATUS_SYS_USB_BUFFER_OVERRUN As Short = 20029			' The size of the data returned from the endpoint is not up to the expectation.
	Public Const STATUS_SYS_USB_BUFFER_UNDERRUN As Short = 20030		' When doing OUT transfer, the specified buffer cannot store all the data transferred to the device.
	Public Const STATUS_SYS_USB_ENDPOINT_HALTED As Short = 20031		' The status of the endpoint is STALL, transfer failed.
	Public Const STATUS_SYS_USB_NOT_FOUND_DEVINFO As Short = 20032		' The device information is not found.
	Public Const STATUS_SYS_USB_ACCESS_DENIED As Short = 20033			' The access to hardware was refused.
	Public Const STATUS_SYS_USB_INVALID_HANDLE As Short = 20034			' The specified handle is invalid.

    '#endif
    ' CNT
	Public Const CNT_ERR_SYS_MODE As Short = 20100						' Invalid mode setting.
	Public Const CNT_ERR_SYS_CH_NO As Short = 20201						' Channel number is out of range.
	Public Const CNT_ERR_SYS_CH_NUM As Short = 20202					' Number of channels is out of range.
	Public Const CNT_ERR_SYS_CH_VALUE As Short = 20203					' Counter value is out of range.
	Public Const CNT_ERR_SYS_REGNO As Short = 20204						' Compare register number is out of range.
	Public Const CNT_ERR_SYS_TIMER_VALUE As Short = 20300				' Timer value is out of range.
	Public Const CNT_ERR_SYS_OUTPUT_LOGIC As Short = 20301				' The output logic of the control output signal is out of range.
	Public Const CNT_ERR_SYS_EVENT_TYPE As Short = 20302				' The kind of hardware event is out of range.
	Public Const CNT_ERR_SYS_PULSE_WIDTH As Short = 20303				' The coefficient of one-shot pulse width is out of range.
	Public Const CNT_ERR_SYS_INPUT_LOGIC As Short = 20304				' The input logic of control input signal is out of range.
	Public Const CNT_ERR_SYS_OUTPUT_DATA As Short = 20305				' The output data is out of range.
	' CNT Sampling
	Public Const CNT_ERR_SYS_START_SIGNAL As Short = 21000				' The start signal is out of range.
	Public Const CNT_ERR_SYS_STOP_SIGNAL As Short = 21001				' The stop signal is out of range.
	Public Const CNT_ERR_SYS_CLOCK_SIGNAL As Short = 21002				' The clock signal is out of range.
	Public Const CNT_ERR_SYS_SIGNAL As Short = 21003					' The available signal is out of range.
	Public Const CNT_ERR_SYS_COUNT_MODE As Short = 21004				' The count mode is out of range.
	Public Const CNT_ERR_SYS_START_TRG As Short = 21005					' The start condition is out of range.
	Public Const CNT_ERR_SYS_COUNT_START_MODE As Short = 21006			' The count start condition is out of range.
	Public Const CNT_ERR_SYS_CLOCK_TRG As Short = 21007					' The clock condition is out of range.
	Public Const CNT_ERR_SYS_STOP_TRG As Short = 21008					' The stop condition is out of range.
	Public Const CNT_ERR_SYS_CLOCK_VAL As Short = 21009					' The clock value is out of range.
	Public Const CNT_ERR_SYS_CLOCK_UNIT As Short = 21010				' The unit of clock value is out of range.
	Public Const CNT_ERR_SYS_STOP_NUM As Short = 21011					' The time of sampling stop is out of range.
	Public Const CNT_ERR_SYS_COUNT_STOP_MODE As Short = 21012			' The count stop condition is out of range.
	Public Const CNT_ERR_SYS_SCAN_NUM As Short = 21013					' Frequency of scan of the buffer is out of range.
	Public Const CNT_ERR_SYS_RING As Short = 21014						' Buffer repetition use setting is out of range.
	Public Const CNT_ERR_SYS_TRANS_COUNT As Short = 21015				' The data transfer quantity is out of range.

	Public Const CNT_ERR_SYS_PARAM As Short = 21050						' One of parameter is out of range

	Public Const CNT_ERR_SYS_BUFFER As Short = 21100					' Because the buffer was too large, it was not possible to secure it.
	Public Const CNT_ERR_SYS_LOCK_MEMORY As Short = 21101				' The memory cannot be locked.
	Public Const CNT_ERR_SYS_SEQUENCE As Short = 21102					' Execution procedure error.
End Module