﻿Imports System.Runtime.InteropServices
Imports System.Text

Public Class CollectionConditions
    '----------------------------------------
    ' Declaration of global variables
    '----------------------------------------
    Public Shared g_appid As Short                                 ' ID for application access
    Dim pdelegate_func As PLOGGEREVENTCALLBACK                     ' Delegate for event notification
    Dim pfunc As IntPtr                                            ' IntPtr for callback routine

    Private Sub CollectionConditions_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '----------------------------------------
        ' Set the default button
        '----------------------------------------
        AcceptButton = Button_Close
        '----------------------------------------
        ' Update the initial display of device name
        '----------------------------------------
        TextBox_DeviceName.Text = "AIO000"
        '----------------------------------------
        ' Create the combobox for screen size
        '----------------------------------------
        ComboBox_OpenMode.Items.Add("Minimize")
        ComboBox_OpenMode.Items.Add("Normal")
        ComboBox_OpenMode.Items.Add("Maximize")
        '----------------------------------------
        ' Change the selection of screen size combobox to Minimize
        '----------------------------------------
        ComboBox_OpenMode.SelectedIndex = 0
        '----------------------------------------
        ' Update the initial display of memory size
        '----------------------------------------
        TextBox_MemorySize.Text = "10"
        '----------------------------------------
        ' Create the combobox for file type
        '----------------------------------------
        ComboBox_FileType.Items.Add("None")
        ComboBox_FileType.Items.Add("clb")
        ComboBox_FileType.Items.Add("csv")
        '----------------------------------------
        ' Change the selection of file type combobox to None
        '----------------------------------------
        ComboBox_FileType.SelectedIndex = 0
        '----------------------------------------
        ' Initialize the delegate for event notification
        '----------------------------------------
        pdelegate_func = New PLOGGEREVENTCALLBACK(AddressOf CallBackProc)
    End Sub

    '================================================================================
    ' It is the process when the LoggerOpenApplication button is clicked
    ' Launch the app and enable access
    '================================================================================
    Private Sub Button_LoggerOpenApplication_Click(sender As Object, e As EventArgs) Handles Button_LoggerOpenApplication.Click
        Dim device_name As String                         ' Device name
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim openmode As UShort                            ' Screen size
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get the device name from textbox
        '----------------------------------------
        device_name = TextBox_DeviceName.Text
        '----------------------------------------
        ' Get the screen size from combobox
        '----------------------------------------
        openmode = ComboBox_OpenMode.SelectedIndex
        '----------------------------------------
        ' Initialize the application
        '----------------------------------------
        ret = LoggerOpenApplication(device_name, g_appid, openmode)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerOpenApplication = {0} : {1}", ret, error_string)
    End Sub

    '================================================================================
    ' It is the process when the LoggerSetDeviceName button is clicked
    ' Set the device name
    '================================================================================
    Private Sub Button_LoggerSetDeviceName_Click(sender As Object, e As EventArgs) Handles Button_LoggerSetDeviceName.Click
        Dim device_name As String                         ' Device name
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Get the device name from textbox
        '----------------------------------------
        device_name = TextBox_DeviceName.Text
        '----------------------------------------
        ' Set the device name
        '----------------------------------------
        ret = LoggerSetDeviceName(g_appid, device_name)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerSetDeviceName = {0} : {1}", ret, error_string)
    End Sub

    '================================================================================
    ' It is the process when the LoggerGetDeviceName button is clicked
    ' Get the device name
    '================================================================================
    Private Sub Button_LoggerGetDeviceName_Click(sender As Object, e As EventArgs) Handles Button_LoggerGetDeviceName.Click
        Dim device_name As New StringBuilder("", 256)     ' Device name
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Get the device name
        '----------------------------------------
        ret = LoggerGetDeviceName(g_appid, device_name)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerGetDeviceName = {0} : {1}", ret, error_string)
        '----------------------------------------
        ' If the device name acquisition function is completed successfully
        '----------------------------------------
        If ret = 0 Then
            '----------------------------------------
            ' Display the device name
            '----------------------------------------
            TextBox_DeviceName.Text = device_name.ToString()
        End If
    End Sub

    '================================================================================
    ' It is the process when the Channel Settings... button is clicked
    ' Display the channel setting dialog
    '================================================================================
    Private Sub Button_Channel_Click(sender As Object, e As EventArgs) Handles Button_Channel.Click
        Dim channelsettingdlg As New ChannelSetting                      ' Channel setting dialog
        Dim error_string As New StringBuilder("", 256)                   ' Error code string
        Dim ret As Integer                                               ' For return code
        Dim sequence_num As UShort = ChannelSetting.SEQUENCE_NUM         ' Number of sequences
        Dim InputType As UShort = 0                                      ' Input method
        Dim AiChannels As UShort = 0                                     ' Number of channels
        Dim ChannelNo As UShort() = New UShort(sequence_num - 1) {}      ' Channel number
        Dim ChName As Byte() = New Byte(sequence_num * 256 - 1) {}       ' Channel name
        Dim Range As UShort() = New UShort(sequence_num - 1) {}          ' Range
        Dim ScaleEnable As UShort() = New UShort(sequence_num - 1) {}    ' Scale conversion enable/disable
        Dim MinData As Single() = New Single(sequence_num - 1) {}        ' Minimum data
        Dim MaxData As Single() = New Single(sequence_num - 1) {}        ' Maximum data
        Dim MinScale As Single() = New Single(sequence_num - 1) {}       ' Minimum scale
        Dim MaxScale As Single() = New Single(sequence_num - 1) {}       ' Maximum scale
        Dim i As Integer                                                 ' Loop count

        '----------------------------------------
        ' Set the initial value
        '----------------------------------------
        InputType = LOGGER_PARAM_SINGLEENDED
        AiChannels = sequence_num
        For i = 0 To sequence_num - 1
            ChannelNo(i) = 0
            ChName(i * 256) = 0
            Range(i) = PM10
            ScaleEnable(i) = LOGGER_PARAM_DISABLE
            MinData(i) = -10.0F
            MaxData(i) = 10.0F
            MinScale(i) = -10.0F
            MaxScale(i) = 10.0F
        Next
        '----------------------------------------
        ' Get the channel settings
        '----------------------------------------
        ret = LoggerGetChannelSetting(g_appid, InputType, AiChannels, ChannelNo, ChName, Range)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetChannelSetting = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get the scale conversion settings
        '----------------------------------------
        For i = 0 To sequence_num - 1
            If AiChannels < i + 1 Then
                Exit For
            End If
            ret = LoggerGetScaleConversion(g_appid, i, ScaleEnable(i), MinData(i), MaxData(i), MinScale(i), MaxScale(i))
            If ret <> 0 Then
                Exit For
            End If
        Next
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetScaleConversion = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Set the date to channel setting dialog
        '----------------------------------------
        channelsettingdlg.channel_data_set(InputType, AiChannels, ChannelNo, ChName, Range, ScaleEnable, MinData, MaxData, MinScale, MaxScale)
        '----------------------------------------
        ' If OK is pressed, the process is performed
        '----------------------------------------
        If channelsettingdlg.ShowDialog() = DialogResult.OK Then
            '----------------------------------------
            ' Get the date from channel setting dialog
            '----------------------------------------
            channelsettingdlg.channel_data_get(InputType, AiChannels, ChannelNo, ChName, Range, ScaleEnable, MinData, MaxData, MinScale, MaxScale)
            '----------------------------------------
            ' Set the channel
            '----------------------------------------
            ret = LoggerSetChannelSetting(g_appid, InputType, AiChannels, ChannelNo, ChName, Range)
            If ret <> 0 Then
                '----------------------------------------
                ' Get the error string
                '----------------------------------------
                LoggerGetErrorString(ret, error_string)
                '----------------------------------------
                ' Display the error code and the message
                '----------------------------------------
                TextBox_ReturnNum.Text = String.Format("LoggerSetChannelSetting = {0} : {1}", ret, error_string)
                Return
            End If
            '----------------------------------------
            ' Set the scale conversion
            '----------------------------------------
            For i = 0 To AiChannels - 1
                ret = LoggerSetScaleConversion(g_appid, i, ScaleEnable(i), MinData(i), MaxData(i), MinScale(i), MaxScale(i))
                If ret <> 0 Then
                    Exit For
                End If
            Next
            If ret <> 0 Then
                '----------------------------------------
                ' Get the error string
                '----------------------------------------
                LoggerGetErrorString(ret, error_string)
                '----------------------------------------
                ' Display the error code and the message
                '----------------------------------------
                TextBox_ReturnNum.Text = String.Format("LoggerSetScaleConversion = {0} : {1}", ret, error_string)
                Return
            End If
            '----------------------------------------
            ' Display the message that channel setting is completed
            '----------------------------------------
            TextBox_ReturnNum.Text = "Channel Settings : Successful completion"
        End If
        channelsettingdlg.Dispose()
    End Sub

    '================================================================================
    ' It is the process when the Clock Settings... button is clicked
    ' Display the clock setting dialog
    '================================================================================
    Private Sub Button_Clock_Click(sender As Object, e As EventArgs) Handles Button_Clock.Click
        Dim clocksettingdlg As New ClockSetting()         ' Clock setting dialog
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim value_temp As Double                          ' For temporary storage of setting values
        Dim clock_type As UShort                          ' Clock type
        Dim sampling_clock_unit As UShort                 ' Sampling clock unit
        Dim sampling_clock As Double                      ' Sampling clock
        Dim external_clock As Double                      ' External clock
        Dim sampling_times As UInteger                    ' Sampling times condition
        Dim scan_clock As Single                          ' Scan clock
        Dim repeat_times As UInteger                      ' Repeat times condition
        Dim start_trigger_type As UShort                  ' Start condition
        Dim stop_trigger_type As UShort                   ' Stop condition
        Dim delay_time As UInteger                        ' Delay sampling condition
        Dim start_level_trigger_edge As UShort            ' Start trigger  Level comparison  Comparison direction
        Dim start_level_sequence_no As UShort             ' Start trigger  Level comparison  Sequence number
        Dim start_level_border_value As Single            ' Start trigger  Level comparison  Comparison value
        Dim start_range_sequence_no As UShort             ' Start trigger  In range/out range comparison  Sequence number
        Dim start_range_upper_border_value As Single      ' Start trigger  In range/out range comparison  Upper limit value
        Dim start_range_lower_border_value As Single      ' Start trigger  In range/out range comparison  Lower limit value
        Dim start_range_state_times As UInteger           ' Start trigger  In range/out range comparison  State times
        Dim start_time_time As UInteger                   ' Start trigger  Time/Moment  Time
        Dim start_time_hour As UInteger                   ' Start trigger  Time/Moment  Moment(H)
        Dim start_time_minute As UInteger                 ' Start trigger  Time/Moment  Moment(M)
        Dim start_time_second As UInteger                 ' Start trigger  Time/Moment  Moment(S)
        Dim stop_level_trigger_edge As UShort             ' Stop trigger  Level comparison  Comparison direction
        Dim stop_level_sequence_no As UShort              ' Stop trigger  Level comparison  Sequence number
        Dim stop_level_border_value As Single             ' Stop trigger  Level comparison  Comparison value
        Dim stop_range_sequence_no As UShort              ' Stop trigger  In range/out range comparison  Sequence number
        Dim stop_range_upper_border_value As Single       ' Stop trigger  In range/out range comparison  Upper limit value
        Dim stop_range_lower_border_value As Single       ' Stop trigger  In range/out range comparison  Lower limit value
        Dim stop_range_state_times As UInteger            ' Stop trigger  In range/out range comparison  State times
        Dim stop_time_time As UInteger                    ' Stop trigger  Time/Moment  Time
        Dim stop_time_hour As UInteger                    ' Stop trigger  Time/Moment  Moment(H)
        Dim stop_time_minute As UInteger                  ' Stop trigger  Time/Moment  Moment(M)
        Dim stop_time_second As UInteger                  ' Stop trigger  Time/Moment  Moment(S)
        Dim value_time_type As UShort                     ' For temporary storage of setting values
        Dim value_time1 As UInteger                       ' For temporary storage of setting values
        Dim value_time2 As UInteger                       ' For temporary storage of setting values
        Dim value_time3 As UInteger                       ' For temporary storage of setting values

        '----------------------------------------
        ' Set the initial value
        '----------------------------------------
        sampling_clock_unit = LOGGER_PARAM_FREQUNIT_USEC
        sampling_clock = 0.0
        external_clock = 0.0
        '----------------------------------------
        ' Get the sampling clock condition
        '----------------------------------------
        value_temp = 0.0
        ret = LoggerGetSamplingClock(g_appid, clock_type, sampling_clock_unit, value_temp)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetSamplingClock = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Set the acquired value to the sampling clock in the case of internal clock setting
        '----------------------------------------
        If clock_type = LOGGER_PARAM_CLOCK_INTERNAL Then
            sampling_clock = value_temp
            '----------------------------------------
            ' Set the acquired value to the external clock in the case of external clock setting
            '----------------------------------------
        Else
            external_clock = value_temp
        End If
        '----------------------------------------
        ' Get the sampling times, conversion speed and repeat times
        '----------------------------------------
        ret = LoggerGetSamplingSetting(g_appid, sampling_times, scan_clock, repeat_times, start_trigger_type, stop_trigger_type, delay_time)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetSamplingSetting = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get the start trigger analog level
        '----------------------------------------
        ret = LoggerGetAnalogLevelTrigger(g_appid, LOGGER_PARAM_STARTTRIGGER, start_level_trigger_edge, start_level_sequence_no, start_level_border_value)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetAnalogLevelTrigger = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get the start trigger analog in range/out range
        '----------------------------------------
        ret = LoggerGetAnalogRangeTrigger(g_appid, LOGGER_PARAM_STARTTRIGGER, start_range_sequence_no, start_range_upper_border_value, start_range_lower_border_value, start_range_state_times)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetAnalogRangeTrigger = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get start trigger Time/Moment
        '----------------------------------------
        ret = LoggerGetTimeTrigger(g_appid, LOGGER_PARAM_STARTTRIGGER, value_time_type, value_time1, value_time2, value_time3)
        If ret <> 0 Then
            '----------------------------------------
            ' Get error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display error code and message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetTimeTrigger = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' For Time, assign the acquired value to the time
        '----------------------------------------
        If value_time_type = LOGGER_PARAM_TIMETYPE_ELAPSED Then
            start_time_time = value_time1
            start_time_hour = 0
            start_time_minute = 0
            start_time_second = 0
            '----------------------------------------
            ' For Moment, assign the acquired value to the moment
            '----------------------------------------
        Else
            start_time_time = 60
            start_time_hour = value_time1
            start_time_minute = value_time2
            start_time_second = value_time3
        End If
        '----------------------------------------
        ' Get the stop trigger analog level
        '----------------------------------------
        ret = LoggerGetAnalogLevelTrigger(g_appid, LOGGER_PARAM_STOPTRIGGER, stop_level_trigger_edge, stop_level_sequence_no, stop_level_border_value)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetAnalogLevelTrigger = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get the stop trigger analog in range/out range
        '----------------------------------------
        ret = LoggerGetAnalogRangeTrigger(g_appid, LOGGER_PARAM_STOPTRIGGER, stop_range_sequence_no, stop_range_upper_border_value, stop_range_lower_border_value, stop_range_state_times)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetAnalogRangeTrigger = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get stop trigger Time/Moment
        '----------------------------------------
        ret = LoggerGetTimeTrigger(g_appid, LOGGER_PARAM_STOPTRIGGER, value_time_type, value_time1, value_time2, value_time3)
        If ret <> 0 Then
            '----------------------------------------
            ' Get error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display error code and message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetTimeTrigger = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' For Time, assign the acquired value to the time
        '----------------------------------------
        If value_time_type = LOGGER_PARAM_TIMETYPE_ELAPSED Then
            stop_time_time = value_time1
            stop_time_hour = 0
            stop_time_minute = 0
            stop_time_second = 0
            '----------------------------------------
            ' For Moment, assign the acquired value to the moment
            '----------------------------------------
        Else
            stop_time_time = 60
            stop_time_hour = value_time1
            stop_time_minute = value_time2
            stop_time_second = value_time3
        End If
        '----------------------------------------
        ' Set the date to clock setting dialog
        '----------------------------------------
        clocksettingdlg.clock_data_set(clock_type,
                                        sampling_clock_unit,
                                        sampling_clock,
                                        external_clock,
                                        sampling_times,
                                        scan_clock,
                                        repeat_times,
                                        start_trigger_type,
                                        stop_trigger_type,
                                        delay_time,
                                        start_level_trigger_edge,
                                        start_level_sequence_no,
                                        start_level_border_value,
                                        start_range_sequence_no,
                                        start_range_upper_border_value,
                                        start_range_lower_border_value,
                                        start_range_state_times,
                                        start_time_time,
                                        start_time_hour,
                                        start_time_minute,
                                        start_time_second,
                                        stop_level_trigger_edge,
                                        stop_level_sequence_no,
                                        stop_level_border_value,
                                        stop_range_sequence_no,
                                        stop_range_upper_border_value,
                                        stop_range_lower_border_value,
                                        stop_range_state_times,
                                        stop_time_time,
                                        stop_time_hour,
                                        stop_time_minute,
                                        stop_time_second)
        '----------------------------------------
        ' If OK is pressed, the process is performed
        '----------------------------------------
        If clocksettingdlg.ShowDialog() = DialogResult.OK Then
            '----------------------------------------
            ' Get the date from clock setting dialog
            '----------------------------------------
            clocksettingdlg.clock_data_get(clock_type,
                                            sampling_clock_unit,
                                            sampling_clock,
                                            external_clock,
                                            sampling_times,
                                            scan_clock,
                                            repeat_times,
                                            start_trigger_type,
                                            stop_trigger_type,
                                            delay_time,
                                            start_level_trigger_edge,
                                            start_level_sequence_no,
                                            start_level_border_value,
                                            start_range_sequence_no,
                                            start_range_upper_border_value,
                                            start_range_lower_border_value,
                                            start_range_state_times,
                                            start_time_time,
                                            start_time_hour,
                                            start_time_minute,
                                            start_time_second,
                                            stop_level_trigger_edge,
                                            stop_level_sequence_no,
                                            stop_level_border_value,
                                            stop_range_sequence_no,
                                            stop_range_upper_border_value,
                                            stop_range_lower_border_value,
                                            stop_range_state_times,
                                            stop_time_time,
                                            stop_time_hour,
                                            stop_time_minute,
                                            stop_time_second)
            '----------------------------------------
            ' Specify the sampling clock period (frequency) for internal clock
            '----------------------------------------
            If clock_type = LOGGER_PARAM_CLOCK_INTERNAL Then
                value_temp = sampling_clock
                '----------------------------------------
                ' Specify the external clock update interval for external clock
                '----------------------------------------
            Else
                value_temp = external_clock
            End If
            '----------------------------------------
            ' Set the sampling clock condition
            '----------------------------------------
            ret = LoggerSetSamplingClock(g_appid, clock_type, sampling_clock_unit, value_temp)
            If ret <> 0 Then
                '----------------------------------------
                ' Get the error string
                '----------------------------------------
                LoggerGetErrorString(ret, error_string)
                '----------------------------------------
                ' Display the error code and the message
                '----------------------------------------
                TextBox_ReturnNum.Text = String.Format("LoggerSetSamplingClock = {0} : {1}", ret, error_string)
                Return
            End If
            '----------------------------------------
            ' Set the sampling times, conversion speed and repeat times
            '----------------------------------------
            ret = LoggerSetSamplingSetting(g_appid, sampling_times, scan_clock, repeat_times, start_trigger_type, stop_trigger_type, delay_time)
            If ret <> 0 Then
                '----------------------------------------
                ' Get the error string
                '----------------------------------------
                LoggerGetErrorString(ret, error_string)
                '----------------------------------------
                ' Display the error code and the message
                '----------------------------------------
                TextBox_ReturnNum.Text = String.Format("LoggerSetSamplingSetting = {0} : {1}", ret, error_string)
                Return
            End If
            If start_trigger_type = LOGGER_PARAM_TRIGGER_LEVEL Then
                '----------------------------------------
                ' Set the start trigger analog level
                '----------------------------------------
                ret = LoggerSetAnalogLevelTrigger(g_appid, LOGGER_PARAM_STARTTRIGGER, start_level_trigger_edge, start_level_sequence_no, start_level_border_value)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get the error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display the error code and the message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetAnalogLevelTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            If start_trigger_type = LOGGER_PARAM_TRIGGER_INRANGE OrElse
               start_trigger_type = LOGGER_PARAM_TRIGGER_OUTRANGE Then
                '----------------------------------------
                ' Set the start trigger analog in range/out range
                '----------------------------------------
                ret = LoggerSetAnalogRangeTrigger(g_appid, LOGGER_PARAM_STARTTRIGGER, start_range_sequence_no, start_range_upper_border_value, start_range_lower_border_value, start_range_state_times)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get the error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display the error code and the message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetAnalogRangeTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            If start_trigger_type = LOGGER_PARAM_TRIGGER_ELAPSED_TIME Then
                '----------------------------------------
                ' Set start trigger Time
                '----------------------------------------
                ret = LoggerSetTimeTrigger(g_appid, LOGGER_PARAM_STARTTRIGGER, LOGGER_PARAM_TIMETYPE_ELAPSED, start_time_time, 0, 0)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display error code and message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetTimeTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            If start_trigger_type = LOGGER_PARAM_TRIGGER_CURRENT_TIME Then
                '----------------------------------------
                ' Set start trigger Moment
                '----------------------------------------
                ret = LoggerSetTimeTrigger(g_appid, LOGGER_PARAM_STARTTRIGGER, LOGGER_PARAM_TIMETYPE_CURRENT, start_time_hour, start_time_minute, start_time_second)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display error code and message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetTimeTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            If stop_trigger_type = LOGGER_PARAM_TRIGGER_LEVEL Then
                '----------------------------------------
                ' Set the stop trigger analog level
                '----------------------------------------
                ret = LoggerSetAnalogLevelTrigger(g_appid, LOGGER_PARAM_STOPTRIGGER, stop_level_trigger_edge, stop_level_sequence_no, stop_level_border_value)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get the error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display the error code and the message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetAnalogLevelTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            If stop_trigger_type = LOGGER_PARAM_TRIGGER_INRANGE OrElse
               stop_trigger_type = LOGGER_PARAM_TRIGGER_OUTRANGE Then
                '----------------------------------------
                ' Set the stop trigger analog in range/out range
                '----------------------------------------
                ret = LoggerSetAnalogRangeTrigger(g_appid, LOGGER_PARAM_STOPTRIGGER, stop_range_sequence_no, stop_range_upper_border_value, stop_range_lower_border_value, stop_range_state_times)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get the error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display the error code and the message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetAnalogRangeTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            If stop_trigger_type = LOGGER_PARAM_TRIGGER_ELAPSED_TIME Then
                '----------------------------------------
                ' Set stop trigger Time
                '----------------------------------------
                ret = LoggerSetTimeTrigger(g_appid, LOGGER_PARAM_STOPTRIGGER, LOGGER_PARAM_TIMETYPE_ELAPSED, stop_time_time, 0, 0)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display error code and message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetTimeTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            If stop_trigger_type = LOGGER_PARAM_TRIGGER_CURRENT_TIME Then
                '----------------------------------------
                ' Set stop trigger Moment
                '----------------------------------------
                ret = LoggerSetTimeTrigger(g_appid, LOGGER_PARAM_STOPTRIGGER, LOGGER_PARAM_TIMETYPE_CURRENT, stop_time_hour, stop_time_minute, stop_time_second)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display error code and message
                    '----------------------------------------
                    TextBox_ReturnNum.Text = String.Format("LoggerSetTimeTrigger = {0} : {1}", ret, error_string)
                    Return
                End If
            End If
            '----------------------------------------
            ' Display the message that clock setting is completed
            '----------------------------------------
            TextBox_ReturnNum.Text = "Clock Settings : Successful completion"
        End If
        clocksettingdlg.Dispose()
    End Sub

    '================================================================================
    ' It is the process when the LoggerSetMemoryOption button is clicked
    ' Set the memory option
    '================================================================================
    Private Sub Button_LoggerSetMemoryOption_Click(sender As Object, e As EventArgs) Handles Button_LoggerSetMemoryOption.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim memorysize As UShort                          ' Memory size

        '----------------------------------------
        ' Get the memory size from textbox
        '----------------------------------------
        If UShort.TryParse(TextBox_MemorySize.Text, memorysize) = False Then
            TextBox_ReturnNum.Text = "Memory size acquisition error"
            Exit Sub
        End If
        '----------------------------------------
        ' Set the memory option
        '----------------------------------------
        ret = LoggerSetMemoryOption(g_appid, memorysize)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerSetMemoryOption = {0} : {1}", ret, error_string)
    End Sub

    '================================================================================
    ' It is the process when the ... button is clicked (Data file)
    ' Display the file selection dialog
    '================================================================================
    Private Sub Button_DataSelectFile_Click(sender As Object, e As EventArgs) Handles Button_DataSelectFile.Click
        '----------------------------------------
        ' If the path exists, set the current path to the initial path of dialog
        '----------------------------------------
        If TextBox_DataFile.Text.Length > 0 Then
            FolderBrowserDialog1.SelectedPath = TextBox_DataFile.Text
            '----------------------------------------
            ' If the path does not exist, set the MyDocuments path to the initial path of dialog
            '----------------------------------------
        Else
            FolderBrowserDialog1.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        End If
        '----------------------------------------
        ' Display the selected path
        '----------------------------------------
        If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
            TextBox_DataFile.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    '================================================================================
    ' It is the process when the LoggerSetAutoSave button is clicked
    ' Set the autosave
    '================================================================================
    Private Sub Button_LoggerSetAutoSave_Click(sender As Object, e As EventArgs) Handles Button_LoggerSetAutoSave.Click
        Dim filepath As String                            ' File path
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim auto_save_type As Integer                     ' Autosave type

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get the save file path from textbox
        '----------------------------------------
        filepath = TextBox_DataFile.Text
        '----------------------------------------
        ' Get the autosave type from combobox
        '----------------------------------------
        auto_save_type = ComboBox_FileType.SelectedIndex
        '----------------------------------------
        ' Set the autosave
        '----------------------------------------
        ret = LoggerSetAutoSave(g_appid, 0, auto_save_type, filepath)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerSetAutoSave = {0} : {1}", ret, error_string)
    End Sub

    '================================================================================
    ' It is the process when the ... button is clicked (Collection condition file)
    ' Display the file selection dialog
    '================================================================================
    Private Sub Button_ImportSelectFile_Click(sender As Object, e As EventArgs) Handles Button_ImportSelectFile.Click
        '----------------------------------------
        ' Don't check if file name exists
        '----------------------------------------
        OpenFileDialog1.CheckFileExists = False
        '----------------------------------------
        ' If the path exists, set the current path to the initial path of dialog
        '----------------------------------------
        If TextBox_ImportFile.Text.Length > 0 Then
            OpenFileDialog1.InitialDirectory = TextBox_ImportFile.Text
            OpenFileDialog1.FileName = OpenFileDialog1.SafeFileName
            '----------------------------------------
            ' If the path does not exist, set the MyDocuments path to the initial path of dialog
            '----------------------------------------
        Else
            OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            OpenFileDialog1.FileName = ""
        End If
        '----------------------------------------
        ' Display the selected path
        '----------------------------------------
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            TextBox_ImportFile.Text = System.IO.Path.GetFullPath(OpenFileDialog1.FileName)
        End If
    End Sub

    '================================================================================
    ' It is the process when the LoggerExportSettingFile button is clicked
    ' Export the setting file
    '================================================================================
    Private Sub Button_LoggerExportSettingFile_Click(sender As Object, e As EventArgs) Handles Button_LoggerExportSettingFile.Click
        Dim filepath As String                            ' File path
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Get the setting file path from textbox
        '----------------------------------------
        filepath = TextBox_ImportFile.Text
        '----------------------------------------
        ' Export the setting file
        '----------------------------------------
        ret = LoggerExportSettingFile(g_appid, filepath)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerExportSettingFile= {0} : {1}", ret, error_string)
    End Sub

    '================================================================================
    ' It is the process when the LoggerImportSettingFile button is clicked
    ' Import the setting file
    '================================================================================
    Private Sub Button_LoggerImportSettingFile_Click(sender As Object, e As EventArgs) Handles Button_LoggerImportSettingFile.Click
        Dim filepath As String                            ' File path
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim status As ULong                               ' Status

        '----------------------------------------
        ' Get the setting file path from textbox
        '----------------------------------------
        filepath = TextBox_ImportFile.Text
        '----------------------------------------
        ' Import the setting file
        '----------------------------------------
        ret = LoggerImportSettingFile(g_appid, filepath, status)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerImportSettingFile = {0} : {1}{2}status=0x{3:X16}",
                                   ret, error_string, Environment.NewLine, status)
    End Sub

    '================================================================================
    ' It is the process when the Start Collecting button is clicked
    ' Start the application input and output
    '================================================================================
    Private Sub Button_LoggerStartOperation_Click(sender As Object, e As EventArgs) Handles Button_LoggerStartOperation.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim status As UInteger                            ' Status
        Dim event_setting As UInteger                     ' Event setting

        '----------------------------------------
        ' Close the file
        '----------------------------------------
        ret = LoggerGraphWindowOperation(g_appid,
                                        LOGGER_PARAM_GRAPH_CLOSE,
                                        LOGGER_PARAM_FILE,
                                        0)  ' Reserved
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGraphWindowOperation = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Specify the buffer mode (basic mode)
        '----------------------------------------
        ret = LoggerSetAcquiredMode(g_appid, LOGGER_PARAM_MODE_BASIC)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerSetAcquiredMode = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get the fixed pointer of the delegate for event notification
        '----------------------------------------
        pfunc = Marshal.GetFunctionPointerForDelegate(pdelegate_func)
        '----------------------------------------
        ' Set the event
        '----------------------------------------
        event_setting = LOGGER_PARAM_EVENT_START Or
                        LOGGER_PARAM_EVENT_RPTEND Or
                        LOGGER_PARAM_EVENT_END Or
                        LOGGER_PARAM_EVENT_OFERR Or
                        LOGGER_PARAM_EVENT_SCERR
        ret = LoggerSetNotifyEvent(g_appid, pfunc, event_setting, Nothing)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerSetNotifyEvent = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Start the application input and output
        '----------------------------------------
        ret = LoggerStartOperation(g_appid, status)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerStartOperation = {0} : {1}{2}status={3}",
                                       ret, error_string, Environment.NewLine, status)
            Return
        End If
        '----------------------------------------
        ' Start the timer
        '----------------------------------------
        timer_SamplingCount.Enabled = True
    End Sub

    '================================================================================
    ' It is the process when the LoggerGetApplicationStatus button is clicked
    ' Get the device status
    '================================================================================
    Private Sub Button_LoggerGetApplicationStatus_Click(sender As Object, e As EventArgs) Handles Button_LoggerGetApplicationStatus.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim status As UInteger = LOGGER_STATUS_STOP       ' Status
        Dim status_string As String = ""                  ' Status string

        '----------------------------------------
        ' Get the device status
        '----------------------------------------
        ret = LoggerGetApplicationStatus(g_appid, status)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerGetApplicationStatus = {0} : {1}", ret, error_string)
        '----------------------------------------
        ' If the status acquisition function is completed successfully
        '----------------------------------------
        If ret = 0 Then
            '----------------------------------------
            ' Get the status string
            '----------------------------------------
            Select Case status
                Case LOGGER_STATUS_STOP
                    status_string = "Stop"
                Case LOGGER_STATUS_START_TRG
                    status_string = "Wait the start trigger"
                Case LOGGER_STATUS_BUSY
                    status_string = "Operating"
                Case Else
                    status_string = "Unknown status"
            End Select
            '----------------------------------------
            ' Display the status
            '----------------------------------------
            TextBox_Status.Text = String.Format("{0} ({1})", status, status_string)
        End If
    End Sub

    '================================================================================
    ' It is the process when the Stop Collecting button is clicked
    ' Stop the application input and output
    '================================================================================
    Private Sub Button_LoggerStopOperation_Click(sender As Object, e As EventArgs) Handles Button_LoggerStopOperation.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim total_sampling_count As ULong                 ' Total sampling count

        '----------------------------------------
        ' Stop the timer
        '----------------------------------------
        timer_SamplingCount.Enabled = False
        '----------------------------------------
        ' Stop the application input and output
        '----------------------------------------
        ret = LoggerStopOperation(g_appid)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerStopOperation = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Get the total sampling count
        '----------------------------------------
        total_sampling_count = 0
        ret = LoggerGetTotalSamplingCount(g_appid, total_sampling_count)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetTotalSamplingCount = {0} : {1}", ret, error_string)
            Return
        End If
        '----------------------------------------
        ' Display the total sampling count
        '----------------------------------------
        TextBox_SamplingCount.Text = total_sampling_count.ToString()
    End Sub

    '================================================================================
    ' It is the process when the C-LOGGER Exit button is clicked
    ' Stop the application and disable access
    '================================================================================
    Private Sub Button_LoggerCloseApplication_Click(sender As Object, e As EventArgs) Handles Button_LoggerCloseApplication.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim status As UInteger = LOGGER_STATUS_SUCCESS    ' Status
        Dim status_string As String = ""                  ' Status string

        '----------------------------------------
        ' Close the file(Considering that C-LOGGER may have exited, do not check the result)
        '----------------------------------------
        LoggerGraphWindowOperation(g_appid,
                                        LOGGER_PARAM_GRAPH_CLOSE,
                                        LOGGER_PARAM_FILE,
                                        0)  ' Reserved
        '----------------------------------------
        ' Stop the application and disable access
        '----------------------------------------
        ret = LoggerCloseApplication(g_appid, status)
        '----------------------------------------
        ' Get the error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        If ret <> 0 Then
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerCloseApplication = {0} : {1}", ret, error_string)
        End If
        '----------------------------------------
        ' Get the status string
        '----------------------------------------
        Select Case status
            Case LOGGER_STATUS_SUCCESS
                status_string = "Successful completion"
            Case LOGGER_STATUS_FAILURE
                status_string = "C-LOGGER exit error"
            Case Else
                status_string = "Unknown status"
        End Select
        '----------------------------------------
        ' Display the error code and the message
        '----------------------------------------
        TextBox_ReturnNum.Text = String.Format("LoggerCloseApplication = {0} : {1}{2}status={3} : {4}",
                                   ret, error_string, Environment.NewLine, status, status_string)
    End Sub

    '================================================================================
    ' It is the process when the Close button is clicked
    ' 
    '================================================================================
    Private Sub Button_Close_Click(sender As Object, e As EventArgs) Handles Button_Close.Click
        Dim status As UInteger = 0                        ' For status storage

        '----------------------------------------
        ' Close the file(Considering that C-LOGGER may have exited, do not check the result)
        '----------------------------------------
        LoggerGraphWindowOperation(g_appid, CType(LOGGER_PARAM_GRAPH_CLOSE, UShort), CType(LOGGER_PARAM_FILE, UShort), 0)
        '----------------------------------------
        ' Stop the application and disable access
        '----------------------------------------
        LoggerCloseApplication(g_appid, status)
        '----------------------------------------
        ' Close the dialog
        '----------------------------------------
        Me.Close()
    End Sub

    '================================================================================
    ' Callback routine
    ' 
    '================================================================================
    Protected Sub CallBackProc(ByVal Id As Short, ByVal AiEvent As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr, ByVal Param As Object)
        Dim text_string As String                         ' For updating the textbox
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim total_sampling_count As ULong                 ' Total sampling count

        Select Case AiEvent
            Case LOGGER_PARAM_EVENT_START
                text_string = "Event that start"
            Case LOGGER_PARAM_EVENT_RPTEND
                text_string = "Event that repeat end"
            Case LOGGER_PARAM_EVENT_END, LOGGER_PARAM_EVENT_OFERR, LOGGER_PARAM_EVENT_SCERR
                text_string = ""
                If AiEvent = LOGGER_PARAM_EVENT_END Then
                    text_string = "Event that device operation end"
                ElseIf AiEvent = LOGGER_PARAM_EVENT_OFERR Then
                    text_string = "Event that overflow"
                ElseIf AiEvent = LOGGER_PARAM_EVENT_OFERR Then
                    text_string = "Event that sampling clock period error"
                End If
                '----------------------------------------
                ' Stop the timer
                '----------------------------------------
                timer_SamplingCount.Enabled = False
                '----------------------------------------
                ' Get the total sampling count
                '----------------------------------------
                total_sampling_count = 0
                ret = LoggerGetTotalSamplingCount(g_appid, total_sampling_count)
                If ret <> 0 Then
                    '----------------------------------------
                    ' Get the error string
                    '----------------------------------------
                    LoggerGetErrorString(ret, error_string)
                    '----------------------------------------
                    ' Display the error code and the message
                    '----------------------------------------
                    text_string = String.Format("LoggerGetTotalSamplingCount = {0} : {1}", ret, error_string)
                End If
                '----------------------------------------
                ' Display the total sampling count
                '----------------------------------------
                Me.Invoke(New Action(Sub() TextBox_SamplingCount.Text = total_sampling_count.ToString()))
            Case LOGGER_PARAM_EVENT_DATANUM
                text_string = "Event that the specified number of data are stored"
            Case Else
                text_string = "Unknown event"
        End Select

        Me.Invoke(New Action(Sub() TextBox_ReturnNum.Text = text_string))
    End Sub

    '================================================================================
    ' Timer event
    ' 
    '================================================================================
    Private Sub timer_SamplingCount_Tick(sender As Object, e As EventArgs) Handles timer_SamplingCount.Tick
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim total_sampling_count As ULong                 ' Total sampling count

        '----------------------------------------
        ' Get the total sampling count
        '----------------------------------------
        total_sampling_count = 0
        ret = LoggerGetTotalSamplingCount(g_appid, total_sampling_count)
        If ret <> 0 Then
            '----------------------------------------
            ' Get the error string
            '----------------------------------------
            LoggerGetErrorString(ret, error_string)
            '----------------------------------------
            ' Display the error code and the message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerGetTotalSamplingCount = {0} : {1}", ret, error_string)
        End If
        '----------------------------------------
        ' Display the total sampling count
        '----------------------------------------
        TextBox_SamplingCount.Text = total_sampling_count.ToString()
    End Sub
End Class
