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

Module CLoggerSDK
    '================================================================
    ' clogger_api.vb
    ' Header file for C-Logger
    '                                              CONTEC.Co.,Ltd.
    '================================================================
    '-------------------------------------------------------------
    ' Delegate
    '-------------------------------------------------------------
    Public Delegate Sub PLOGGEREVENTCALLBACK(ByVal Id As Short, ByVal [Event] As UInteger, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)

    '----------------------------------------
    'Function Prototype
    '----------------------------------------
    Declare Function LoggerOpenApplication Lib "clogger_api.dll" (ByVal DeviceName As String, ByRef AppId As Short, ByVal OpenMode As UShort) As Integer
    Declare Function LoggerCloseApplication Lib "clogger_api.dll" (ByVal AppId As Short, ByRef Status As UInteger) As Integer
    Declare Function LoggerStartOperation Lib "clogger_api.dll" (ByVal AppId As Short, ByRef Status As UInteger) As Integer
    Declare Function LoggerStopOperation Lib "clogger_api.dll" (ByVal AppId As Short) As Integer
    Declare Function LoggerGetApplicationStatus Lib "clogger_api.dll" (ByVal AppId As Short, ByRef Status As UInteger) As Integer
    Declare Function LoggerExportSettingFile Lib "clogger_api.dll" (ByVal AppId As Short, ByVal FilePath As String) As Integer
    Declare Function LoggerImportSettingFile Lib "clogger_api.dll" (ByVal AppId As Short, ByVal FilePath As String, ByRef Status As ULong) As Integer
    Declare Function LoggerSaveDataFile Lib "clogger_api.dll" (ByVal AppId As Short, ByVal FilePath As String, ByVal Param1 As Short, ByVal Param2 As Short) As Integer
    Declare Function LoggerLoadDataFile Lib "clogger_api.dll" (ByVal AppId As Short, ByVal FilePath As String) As Integer
    Declare Function LoggerSetDeviceName Lib "clogger_api.dll" (ByVal AppId As Short, ByVal DeviceName As String) As Integer
    Declare Function LoggerGetDeviceName Lib "clogger_api.dll" (ByVal AppId As Short, ByVal DeviceName As StringBuilder) As Integer
    Declare Function LoggerSetChannelSetting Lib "clogger_api.dll" (ByVal AppId As Short, ByVal InputType As UShort, ByVal SequenceNum As UShort, <MarshalAs(UnmanagedType.LPArray)> ByVal ChannelNo() As UShort, <MarshalAs(UnmanagedType.LPArray)> ByVal ChannelName() As Byte, <MarshalAs(UnmanagedType.LPArray)> ByVal Range() As UShort) As Integer
    Declare Function LoggerGetChannelSetting Lib "clogger_api.dll" (ByVal AppId As Short, ByRef InputType As UShort, ByRef SequenceNum As UShort, <MarshalAs(UnmanagedType.LPArray)> ByVal ChannelNo() As UShort, <MarshalAs(UnmanagedType.LPArray)> ByVal ChannelName() As Byte, <MarshalAs(UnmanagedType.LPArray)> ByVal Range() As UShort) As Integer
    Declare Function LoggerSetScaleConversion Lib "clogger_api.dll" (ByVal AppId As Short, ByVal SequenceNo As UShort, ByVal ScaleEnable As UShort, ByVal MinData As Single, ByVal MaxData As Single, ByVal MinScale As Single, ByVal MaxScale As Single) As Integer
    Declare Function LoggerGetScaleConversion Lib "clogger_api.dll" (ByVal AppId As Short, ByVal SequenceNo As UShort, ByRef ScaleEnable As UShort, ByRef MinData As Single, ByRef MaxData As Single, ByRef MinScale As Single, ByRef MaxScale As Single) As Integer
    Declare Function LoggerSetSamplingClock Lib "clogger_api.dll" (ByVal AppId As Short, ByVal ClockType As UShort, ByVal SamplingClockUnit As UShort, ByVal SamplingClock As Double) As Integer
    Declare Function LoggerGetSamplingClock Lib "clogger_api.dll" (ByVal AppId As Short, ByRef ClockType As UShort, ByVal SamplingClockUnit As UShort, ByRef SamplingClock As Double) As Integer
    Declare Function LoggerSetSamplingSetting Lib "clogger_api.dll" (ByVal AppId As Short, ByVal SamplingTimes As UInteger, ByVal ScanClock As Single, ByVal RepeatTimes As UInteger, ByVal StartTriggerType As UShort, ByVal StopTriggerType As UShort, ByVal DelayTime As UInteger) As Integer
    Declare Function LoggerGetSamplingSetting Lib "clogger_api.dll" (ByVal AppId As Short, ByRef SamplingTimes As UInteger, ByRef ScanClock As Single, ByRef RepeatTimes As UInteger, ByRef StartTriggerType As UShort, ByRef StopTriggerType As UShort, ByRef DelayTime As UInteger) As Integer
    Declare Function LoggerSetAnalogLevelTrigger Lib "clogger_api.dll" (ByVal AppId As Short, ByVal StartStopTrigger As UShort, ByVal StartStopTriggerEdge As UShort, ByVal SequenceNo As UShort, ByVal BorderValue As Single) As Integer
    Declare Function LoggerGetAnalogLevelTrigger Lib "clogger_api.dll" (ByVal AppId As Short, ByVal StartStopTrigger As UShort, ByRef StartStopTriggerEdge As UShort, ByRef SequenceNo As UShort, ByRef BorderValue As Single) As Integer
    Declare Function LoggerSetAnalogRangeTrigger Lib "clogger_api.dll" (ByVal AppId As Short, ByVal StartStopTrigger As UShort, ByVal SequenceNo As UShort, ByVal Upper_BorderValue As Single, ByVal Lower_BorderValue As Single, ByVal Start_Times As UInteger) As Integer
    Declare Function LoggerGetAnalogRangeTrigger Lib "clogger_api.dll" (ByVal AppId As Short, ByVal StartStopTrigger As UShort, ByRef SequenceNo As UShort, ByRef Upper_BorderValue As Single, ByRef Lower_BorderValue As Single, ByRef Start_Times As UInteger) As Integer
    Declare Function LoggerSetTimeTrigger Lib "clogger_api.dll" (ByVal AppId As Short, ByVal StartStopTrigger As UShort, ByVal TimeType As UShort, ByVal Time1 As UInteger, ByVal Time2 As UInteger, ByVal Time3 As UInteger) As Integer
    Declare Function LoggerGetTimeTrigger Lib "clogger_api.dll" (ByVal AppId As Short, ByVal StartStopTrigger As UShort, ByRef TimeType As UShort, ByRef Time1 As UInteger, ByRef Time2 As UInteger, ByRef Time3 As UInteger) As Integer
    Declare Function LoggerSetAutoSave Lib "clogger_api.dll" (ByVal AppId As Short, ByVal ExcelEnable As UShort, ByVal AutosaveType As UShort, ByVal FilePath As String) As Integer
    Declare Function LoggerGetAutoSave Lib "clogger_api.dll" (ByVal AppId As Short, ByRef ExcelEnable As UShort, ByRef AutosaveType As UShort, ByVal FilePath As StringBuilder) As Integer
    Declare Function LoggerCaptureScreen Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal ImageArea As UShort, ByVal FilePath As String) As Integer
    Declare Function LoggerSetGraphZoom Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal Axis As UShort, ByVal Zoom As UShort) As Integer
    Declare Function LoggerGetGraphZoom Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal Axis As UShort, ByRef Zoom As UShort) As Integer
    Declare Function LoggerSetGraphChannel Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal SequenceNo As UShort, ByVal ChannelEnable As UShort, ByVal Activate As UShort, ByVal DisplayDot As UShort) As Integer
    Declare Function LoggerGetGraphChannel Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal SequenceNo As UShort, ByRef ChannelEnable As UShort, ByRef Activate As UShort, ByRef DisplayDot As UShort) As Integer
    Declare Function LoggerSetGraph Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal TimeUnit As UShort, ByVal Digit As UShort, ByVal Area2Enable As UShort, ByVal YaxisMagnificationEnable As UShort, ByVal ChannelDispEnable As UShort, ByVal AutoScrollEnable As UShort) As Integer
    Declare Function LoggerGetGraph Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByRef TimeUnit As UShort, ByRef Digit As UShort, ByRef Area2Enable As UShort, ByRef YaxisMagnificationEnable As UShort, ByRef ChannelDispEnable As UShort, ByRef AutoScrollEnable As UShort) As Integer
    Declare Function LoggerSetGraphLabelText Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal TargetItem As UShort, ByVal TitleEnable As UShort, ByVal TitleText As String) As Integer
    Declare Function LoggerGetGraphLabelText Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal TargetItem As UShort, ByRef TitleEnable As UShort, ByVal TitleText As StringBuilder) As Integer
    Declare Function LoggerSetMemoryOption Lib "clogger_api.dll" (ByVal AppId As Short, ByVal MemorySize As UShort) As Integer
    Declare Function LoggerGetMemoryOption Lib "clogger_api.dll" (ByVal AppId As Short, ByRef MemorySize As UShort) As Integer
    Declare Function LoggerGraphWindowOperation Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowOperation As UShort, ByVal Target As UShort, ByVal WindowNo As UShort) As Integer
    Declare Function LoggerSetNotifyEvent Lib "clogger_api.dll" (ByVal AppId As Short, ByVal PLOGGEREVENTCALLBACK As IntPtr, ByVal [Event] As UInteger, ByVal Param As IntPtr) As Integer
    Declare Function LoggerGetNotifyEvent Lib "clogger_api.dll" (ByVal AppId As Short, ByRef [Event] As UInteger) As Integer
    Declare Function LoggerGetErrorString Lib "clogger_api.dll" (ByVal ErrorCode As Integer, ByVal ErrorString As StringBuilder) As Integer
    Declare Function LoggerGetSamplingData Lib "clogger_api.dll" (ByVal AppId As Short, ByRef SamplingTimes As UInteger, <MarshalAs(UnmanagedType.LPArray)> ByVal Data() As Single) As Integer
    Declare Function LoggerGetSamplingDataBin Lib "clogger_api.dll" (ByVal AppId As Short, ByRef SamplingTimes As UInteger, <MarshalAs(UnmanagedType.LPArray)> ByVal Data() As UInteger) As Integer
    Declare Function LoggerSetEventSamplingTimes Lib "clogger_api.dll" (ByVal AppId As Short, ByVal SamplingData As UInteger) As Integer
    Declare Function LoggerGetEventSamplingTimes Lib "clogger_api.dll" (ByVal AppId As Short, ByRef SamplingData As UInteger) As Integer
    Declare Function LoggerGetStoredSamplingCount Lib "clogger_api.dll" (ByVal AppId As Short, ByRef StoredSamplingCount As UInteger) As Integer
    Declare Function LoggerGetTotalSamplingCount Lib "clogger_api.dll" (ByVal AppId As Short, ByRef SamplingCount As ULong) As Integer
    Declare Function LoggerSetAcquiredMode Lib "clogger_api.dll" (ByVal AppId As Short, ByVal Mode As UShort) As Integer
    Declare Function LoggerGetAcquiredMode Lib "clogger_api.dll" (ByVal AppId As Short, ByRef Mode As UShort) As Integer
    Declare Function LoggerMoveGraphPos Lib "clogger_api.dll" (ByVal AppId As Short, ByVal WindowNo As UShort, ByVal Axis As UShort, ByVal Distance As Integer, ByRef Status As UInteger) As Integer


    '================================================================
    ' Parameters
    '================================================================
    '----------------------------------------
    ' App size
    '----------------------------------------

    Public Const LOGGER_PARAM_WINDOW_OFF As Short = 0       ' Minimize
    Public Const LOGGER_PARAM_WINDOW_NORMAL As Short = 1    ' Normal
    Public Const LOGGER_PARAM_WINDOW_MAX As Short = 2       ' Maximize

    '----------------------------------------
    ' Termination processing status
    '----------------------------------------
    Public Const LOGGER_STATUS_SUCCESS As Short = 0         ' Normal completed
    Public Const LOGGER_STATUS_FAILURE As Short = 1         ' C-LOGGER completed error
    Public Const LOGGER_STATUS_EXCEL As Short = 1           ' Excel error
    Public Const LOGGER_STATUS_OVER As Short = 1            ' Excel error

    '----------------------------------------
    ' Operation status
    '----------------------------------------
    Public Const LOGGER_STATUS_STOP As Short = 0        ' Stop
    Public Const LOGGER_STATUS_BUSY As Short = 1        ' Busy
    Public Const LOGGER_STATUS_START_TRG As Short = 2       ' Start trigger

    '----------------------------------------
    ' Enable/Disable
    '----------------------------------------
    Public Const LOGGER_PARAM_DISABLE As Short = 0      ' disable
    Public Const LOGGER_PARAM_ENABLE As Short = 1       ' enable

    '----------------------------------------
    ' Input Type
    '----------------------------------------
    Public Const LOGGER_PARAM_SINGLEENDED As Short = 0      ' SingleEnded
    Public Const LOGGER_PARAM_DIFFERENTIAL As Short = 1     ' Differential

    '----------------------------------------
    ' Clock Type
    '----------------------------------------
    Public Const LOGGER_PARAM_CLOCK_INTERNAL As Short = 0       ' internal
    Public Const LOGGER_PARAM_CLOCK_EXTERNAL_FALLING As Short = 1       ' external
    Public Const LOGGER_PARAM_CLOCK_EXTERNAL_RISING As Short = 2        ' external

    '----------------------------------------
    ' Sampling Clock Unit
    '----------------------------------------
    Public Const LOGGER_PARAM_FREQUNIT_USEC As Short = 0        ' usec
    Public Const LOGGER_PARAM_FREQUNIT_MSEC As Short = 1        ' msec
    Public Const LOGGER_PARAM_FREQUNIT_SEC As Short = 2     ' sec
    Public Const LOGGER_PARAM_FREQUNIT_HZ As Short = 3      ' Hz
    Public Const LOGGER_PARAM_FREQUNIT_KHZ As Short = 4     ' kHz
    Public Const LOGGER_PARAM_FREQUNIT_MHZ As Short = 5     ' MHz

    '----------------------------------------
    ' TRIGGER TYPE
    '----------------------------------------
    Public Const LOGGER_PARAM_TRIGGER_NONE As Short = 0     ' none
    Public Const LOGGER_PARAM_TRIGGER_DIGITAL_RISING As Short = 1       ' digital edge rising
    Public Const LOGGER_PARAM_TRIGGER_DIGITAL_FALLING As Short = 2      ' digital edge falling
    Public Const LOGGER_PARAM_TRIGGER_LEVEL As Short = 3        ' level
    Public Const LOGGER_PARAM_TRIGGER_INRANGE As Short = 4      ' inrange
    Public Const LOGGER_PARAM_TRIGGER_OUTRANGE As Short = 5     ' outrange
    Public Const LOGGER_PARAM_TRIGGER_ELAPSED_TIME As Short = 6       ' elapsed
    Public Const LOGGER_PARAM_TRIGGER_CURRENT_TIME As Short = 7        ' current

    '----------------------------------------
    ' TRIGGER
    '----------------------------------------
    Public Const LOGGER_PARAM_STARTTRIGGER As Short = 0     ' start trigger
    Public Const LOGGER_PARAM_STOPTRIGGER As Short = 1      ' Stop trigger

    '----------------------------------------
    ' TRIGGER EDGE
    '----------------------------------------
    Public Const LOGGER_PARAM_EDGE_RISING As Short = 0      ' rising
    Public Const LOGGER_PARAM_EDGE_FALLING As Short = 1     ' falling
    Public Const LOGGER_PARAM_EDGE_BOTH As Short = 2        ' both

    '----------------------------------------
    ' TIMETYPE
    '----------------------------------------
    Public Const LOGGER_PARAM_TIMETYPE_ELAPSED As Short = 0     ' elapsed
    Public Const LOGGER_PARAM_TIMETYPE_CURRENT As Short = 1     ' current

    '----------------------------------------
    ' AUTOSAVETYPE
    '----------------------------------------
    Public Const LOGGER_PARAM_SAVE_NONE As Short = 0        ' none
    Public Const LOGGER_PARAM_SAVE_CLB As Short = 1     ' binary file(clb)
    Public Const LOGGER_PARAM_SAVE_CSV As Short = 2     ' text file(csv)

    '----------------------------------------
    ' IMAGE AREA
    '----------------------------------------
    Public Const LOGGER_PARAM_AREA_ENTIRE As Short = 0      ' entire(save image entire)
    Public Const LOGGER_PARAM_AREA_GRAPH As Short = 1       ' YT Graph(save image YT Graph)

    '----------------------------------------
    ' AXIS
    '----------------------------------------
    Public Const LOGGER_PARAM_AXIS_X As Short = 0       ' x axis
    Public Const LOGGER_PARAM_AXIS_Y As Short = 1       ' y axis
    Public Const LOGGER_PARAM_AXIS_TITLE_GRAPH As Short = 2     ' graph title

    '----------------------------------------
    ' AXIS
    '----------------------------------------
    Public Const LOGGER_PARAM_ZOOM_IN As Short = 0       ' zoomin
    Public Const LOGGER_PARAM_ZOOM_OUT As Short = 1      ' zoomout

    '----------------------------------------
    ' TIMEUNIT
    '----------------------------------------
    Public Const LOGGER_PARAM_AXISTYPE_ABSOLUTE As Short = 0        ' absolute
    Public Const LOGGER_PARAM_AXISTYPE_RELATIVE As Short = 1        ' relative

    '----------------------------------------
    ' GRAPH
    '----------------------------------------
    Public Const LOGGER_PARAM_GRAPH_OPEN As Short = 0       ' open
    Public Const LOGGER_PARAM_GRAPH_CLOSE As Short = 1      ' close

    '----------------------------------------
    ' TARGET
    '----------------------------------------
    Public Const LOGGER_PARAM_FILE As Short = 0     ' file + graph
    Public Const LOGGER_PARAM_GRAPH As Short = 1        ' graph

    '----------------------------------------
    ' EVENT
    '----------------------------------------
    Public Const LOGGER_PARAM_EVENT_NONE As Short = 0       ' none
    Public Const LOGGER_PARAM_EVENT_START As Short = &H2    ' Event that start
    Public Const LOGGER_PARAM_EVENT_RPTEND As Short = &H10  ' Event that repeat End
    Public Const LOGGER_PARAM_EVENT_END As Short = &H20 ' Event that End
    Public Const LOGGER_PARAM_EVENT_DATANUM As Short = &H80 ' Event that device operation End
    Public Const LOGGER_PARAM_EVENT_OFERR As Integer = &H10000    ' Event that overflow
    Public Const LOGGER_PARAM_EVENT_SCERR As Integer = &H20000    ' Event that sampling clock period Error

    '----------------------------------------
    ' DATA TYPE
    '----------------------------------------
    Public Const LOGGER_PARAM_DATA_BINARY As Short = 0      ' binary
    Public Const LOGGER_PARAM_DATA_VOLTAGE As Short = 1     ' voltage

    '----------------------------------------
    ' BUFFER MODE
    '----------------------------------------
    Public Const LOGGER_PARAM_MODE_BASIC As Short = 0       ' basic mode
    Public Const LOGGER_PARAM_MODE_API As Short = 1     ' basic mode + API mode

    '----------------------------------------
    ' CHANNEL NAME
    '----------------------------------------
    Public Const LOGGER_PARAM_MAX_CHANNEL_NAME As Short = 256       ' channel name (Char[channels][CLOGGER_PARAM_MAX_CHANNEL_NAME])

    '----------------------------------------
    ' RANGE
    '----------------------------------------
    Public Const PM10 As Short = 0  ' ±10V
    Public Const PM5 As Short = 1   ' ±5V
    Public Const PM25 As Short = 2  ' ±2.5V
    Public Const PM125 As Short = 3 ' ±1.25V
    Public Const P10 As Short = 50  ' 0～10V
    Public Const P5 As Short = 51   ' 0～5V
    Public Const P25 As Short = 53  ' 0～2.5V
    Public Const P125 As Short = 54 ' 0～1.25V
    Public Const P20MA As Short = 100   ' 0～20mA
    Public Const P4TO20MA As Short = 101    ' 4～20mA
    Public Const PM20MA As Short = 102 ' ±20mA
    Public Const P1TO5 As Short = 150   ' 1～5V

End Module