﻿Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices
Imports System.Text

Module ZM
	'===============================================================================================
	' API-ZM(WDM) Definition File
	'===============================================================================================
	
	'-----------------------------------------------------------------------------------------------
	' Frequency
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_FREQUENCY_120HZ As Short = 0						'Frequency : 120Hz
	Public Const ZM_FREQUENCY_1kHZ As Short = 1							'Frequency : 1kHz
	
	'-----------------------------------------------------------------------------------------------
	' Signal Level
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_LEVEL_500mV As Short = 0							'Level : 0.5V
	Public Const ZM_LEVEL_1V As Short = 1								'Level : 1V
	
	'-----------------------------------------------------------------------------------------------
	' Measurement Speed
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_SPEED_FAST As Short = 0								'Measurement speed : FAST
	Public Const ZM_SPEED_NORMAL As Short = 1							'Measurement speed : NORMAL
	Public Const ZM_SPEED_SLOW As Short = 2								'Measurement speed : SLOW
	
	'-----------------------------------------------------------------------------------------------
	' Equivalent Circuit Mode
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_CIRCUIT_AUTO As Short = 0							'Equivalent circuit mode : AUTO
	Public Const ZM_CIRCUIT_SERIAL As Short = 1							'Equivalent circuit mode : SERIAL
	Public Const ZM_CIRCUIT_PARALLEL As Short = 2						'Equivalent circuit mode : PARALLEL
	
	'-----------------------------------------------------------------------------------------------
	' Range
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_RANGE_4nF As Short = 3								'Range : 4nF
	Public Const ZM_RANGE_40nF As Short = 4								'Range : 40nF
	Public Const ZM_RANGE_400nF As Short = 5							'Range : 400nF
	Public Const ZM_RANGE_4uF As Short = 6								'Range : 4uF
	Public Const ZM_RANGE_40uF As Short = 7								'Range : 40uF
	Public Const ZM_RANGE_400uF As Short = 8							'Range : 400uF
	Public Const ZM_RANGE_1400uF As Short = 9							'Range : 1.4mF
	
	'-----------------------------------------------------------------------------------------------
	' Correction
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_CORRECTION_TYPE_OPEN As Short = 0					'Correction type : OPEN
	Public Const ZM_CORRECTION_TYPE_SHORT As Short = 1					'Correction type : SHORT
	Public Const ZM_CORRECTION_FORMAT_OPEN_GB As Short = 1				'Correction format of open : GB
	Public Const ZM_CORRECTION_FORMAT_SHORT_RX As Short = 1				'Correction format of short : RX
	
	'-----------------------------------------------------------------------------------------------
	' Contact Check
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_CONTACTCHECK_DISABLE As Short = 0					'Contact check : Disabled
	Public Const ZM_CONTACTCHECK_BEFORE As Short = 1					'Contact check : Before measurement
	Public Const ZM_CONTACTCHECK_AFTER As Short = 2						'Contact check : After measurement
	Public Const ZM_CONTACTCHECK_BOTH As Short = 3						'Contact check : Before and after measurement
	
	'-----------------------------------------------------------------------------------------------
	' Enable/Disable
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_DISABLE As Short = 0								'Disable
	Public Const ZM_ENABLE As Short = 1									'Enable
	
	'-----------------------------------------------------------------------------------------------
	' Definition Value
	'-----------------------------------------------------------------------------------------------
	Public Const CZM_MAX_PROCESS As Short = 16							'Maximum number of process
	Public Const CZM_MAX_DEVICE As Short = 256							'Maximum number of device

	'-----------------------------------------------------------------------------------------------
	' Initialization Error Code
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_ERR_SUCCESS As Short = 0							'Normality completion
	Public Const ZM_ERR_INI_RESOURCE As Short = 1						'Failed in the acquisition of the resource
	Public Const ZM_ERR_INI_INTERRUPT As Short = 2						'Failed in the registration of the interruption routine
	Public Const ZM_ERR_INI_MEMORY As Short = 3							'Failed in the allocation of the memory. This error would hardly occur. If this error occurred, please extend the memory
	Public Const ZM_ERR_INI_REGISTRY As Short = 4						'Failed in the access of registry
	Public Const ZM_ERR_SYS_RECOVERED_FROM_STANDBY As Short = 7			'Execute ZmResetDevice function because the device has recovered from standby mode
	Public Const ZM_ERR_INI_NOT_FOUND_SYS_FILE As Short = 8				'Initialization failed because czm.sys is not found
	Public Const ZM_ERR_INI_DLL_FILE_VERSION As Short = 9				'Initialization failed because the file version of czm.dll cannot be acquired
	Public Const ZM_ERR_INI_SYS_FILE_VERSION As Short = 10				'Initialization failed because the file version of czm.sys cannot be acquired
	Public Const ZM_ERR_INI_NO_MATCH_DRV_VERSION As Short = 11			'Initialization failed because the file version of czm.dll is not same as czm.sys

	'-----------------------------------------------------------------------------------------------
	' DLL Error Code
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_ERR_DLL_DEVICE_NAME As Short = 10000				'The device name which wasn't registered by a device manager was specified
	Public Const ZM_ERR_DLL_INVALID_ID As Short = 10001					'Invalid ID was specified. Please confirm whether the initialization function has completed normally. And confirm the scope of variable that stores ID
	Public Const ZM_ERR_DLL_CALL_DRIVER As Short = 10002				'Driver can't be called
	Public Const ZM_ERR_DLL_CREATE_FILE As Short = 10003				'Failed in the creation of the file
	Public Const ZM_ERR_DLL_CLOSE_FILE As Short = 10004					'Failed in the closing of the file
	Public Const ZM_ERR_DLL_CREATE_THREAD As Short = 10005				'Failed in the creation of the thread
	Public Const ZM_ERR_INFO_INVALID_DEVICE As Short = 10050			'Specified device name is not found. Please check spelling
	Public Const ZM_ERR_INFO_NOT_FIND_DEVICE As Short = 10051			'No more device
	Public Const ZM_ERR_INFO_INVALID_INFOTYPE As Short = 10052			'Information type is invalid
	Public Const ZM_ERR_INFO_NOT_FOUND_DEVINFO As Short = 10053			'Not found device information
	Public Const ZM_ERR_DLL_BUFF_ADDRESS As Short = 10100				'Invalid data buffer address

	'-----------------------------------------------------------------------------------------------
	' Driver Error Code
	'-----------------------------------------------------------------------------------------------
	Public Const ZM_ERR_SYS_MEMORY As Short = 20000						'Failed in the allocation of the memory. This error would hardly occur. If this error occurred, please extend the memory
	Public Const ZM_ERR_SYS_NOT_SUPPORTED As Short = 20001				'This function can't be used by this device
	Public Const ZM_ERR_SYS_BOARD_EXECUTING As Short = 20002			'Can not use while by another device works
	Public Const ZM_ERR_SYS_USING_OTHER_PROCESS As Short = 20003		'Can not use because another process is using the device
	Public Const ZM_ERR_SYS_NOT_FOUND_PROCESS_DATA As Short = 20004		'Process information is not found
	Public Const ZM_ERR_SYS_CHANNEL_NO As Short = 20100					'Channel No is out of the settable range
	Public Const ZM_ERR_SYS_FREQUENCY As Short = 20101					'Frequency is out of the settable range
	Public Const ZM_ERR_SYS_LEVEL As Short = 20102						'Level is out of the settable range
	Public Const ZM_ERR_SYS_SPEED As Short = 20103						'Speed is out of the settable range
	Public Const ZM_ERR_SYS_AVERAGE_COUNT As Short = 20104				'AverageCount is out of the settable range
	Public Const ZM_ERR_SYS_CIRCUIT As Short = 20105					'Circuit is out of the settable range
	Public Const ZM_ERR_SYS_RANGE As Short = 20106						'Range is out of the settable range
	Public Const ZM_ERR_SYS_TRIGGER As Short = 20107					'Trigger is out of the settable range
	Public Const ZM_ERR_SYS_TYPE As Short = 20108						'Type is out of the settable range
	Public Const ZM_ERR_SYS_ENABLE As Short = 20109						'Enable is out of the settable range
	Public Const ZM_ERR_SYS_MODE As Short = 20110						'Mode is out of the settable range
	Public Const ZM_ERR_SYS_BIN_NO As Short = 20111						'BinNo is out of the settable range
	Public Const ZM_ERR_SYS_TIME As Short = 20112						'Time is out of the settable range
	Public Const ZM_ERR_SYS_FORMAT As Short = 20113						'Format is out of the settable range
	Public Const ZM_ERR_SYS_TIMEOUT As Short = 20114					'Timeout is out of the settable range
	Public Const ZM_ERR_SYS_CONTACTCHECK As Short = 20115				'ContactCheck is out of the settable range
	Public Const ZM_ERR_SYS_MEASURE_STOP As Short = 20116				'Measurement stopped
	Public Const ZM_ERR_SYS_MEASURE_TIMEOUT As Short = 20117			'Measurement time out
	Public Const ZM_ERR_SYS_CONTACTCHECK_ENABLE As Short = 20118		'This setting is not possible because the contact check function is enabled

	'-----------------------------------------------------------------------------------------------
	' Prototype Declaration
	'-----------------------------------------------------------------------------------------------
	'Common Function
	Declare Function ZmInit Lib "CZM.DLL" (ByVal DeviceName As String, ByRef Id As Short) As Integer
	Declare Function ZmExit Lib "CZM.DLL" (ByVal Id As Short) As Integer
	Declare Function ZmResetDevice Lib "CZM.DLL" (ByVal Id As Short) As Integer
	Declare Function ZmGetErrorString Lib "CZM.DLL" (ByVal ErrorCode As Integer, ByVal ErrorString As StringBuilder) As Integer

	'Information Acquisition Function
	Declare Function ZmQueryDeviceName Lib "CZM.DLL" (ByVal Index As Short, ByVal DeviceName As String, ByVal Device As String) As Integer
	Declare Function ZmGetMaxChannels Lib "CZM.DLL" (ByVal Id As Short, ByVal MaxChannels As UShort) As Integer

	'Measurement Condition Function
	Declare Function ZmSetFrequency Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Frequency As UShort) As Integer
	Declare Function ZmGetFrequency Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Frequency As UShort) As Integer
	Declare Function ZmSetLevel Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Level As UShort) As Integer
	Declare Function ZmGetLevel Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Level As UShort) As Integer
	Declare Function ZmSetSpeed Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Speed As UShort, ByVal AverageCount As UInteger) As Integer
	Declare Function ZmGetSpeed Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Speed As UShort, ByRef AverageCount As UInteger) As Integer
	Declare Function ZmSetCircuit Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Circuit As UShort) As Integer
	Declare Function ZmGetCircuit Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Circuit As UShort) As Integer
	Declare Function ZmSetRange Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Range As UShort) As Integer
	Declare Function ZmGetRange Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Range As UShort) As Integer
	Declare Function ZmCorrection Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Type As UShort) As Integer
	Declare Function ZmSetCorrectionEnable Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Type As UShort, ByVal Enable As UShort) As Integer
	Declare Function ZmGetCorrectionEnable Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Type As UShort, ByRef Enable As UShort) As Integer
	Declare Function ZmSetCorrectionValue Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Type As UShort, ByVal correction_value_1 As Single, ByVal correction_value_2 As Single, ByVal format As UShort) As Integer
	Declare Function ZmGetCorrectionValue Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Type As UShort, ByRef correction_value_1 As Single, ByRef correction_value_2 As Single, ByVal format As UShort) As Integer
	Declare Function ZmSetStartDelay Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Time As Single) As Integer
	Declare Function ZmGetStartDelay Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Time As Single) As Integer
	Declare Function ZmSetSignalOutputDelay Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Time As Single) As Integer
	Declare Function ZmGetSignalOutputDelay Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Time As Single) As Integer
	Declare Function ZmSetTriggerSyncEnable Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal Enable As UShort) As Integer
	Declare Function ZmGetTriggerSyncEnable Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef Enable As UShort) As Integer
	Declare Function ZmSetContactCheck Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByVal ContactCheck As UShort) As Integer
	Declare Function ZmGetContactCheck Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef ContactCheck As UShort) As Integer

	'Measurement Operation Function
	Declare Function ZmSingleCMeasure Lib "CZM.DLL" (ByVal Id As Short, ByVal Channel As UShort, ByRef CValue As Single, ByRef DValue As Single, ByRef Status As UInteger) As Integer

End Module