﻿Public Class ClockSetting
    '----------------------------------------
    ' Declaration of global variables
    '----------------------------------------
    Public m_clock_type As UShort
    Public m_sampling_clock_unit As UShort
    Public m_sampling_clock As Double
    Public m_external_clock As Double
    Public m_sampling_times As UInteger
    Public m_scan_clock As Single
    Public m_repeat_times As UInteger
    Public m_start_trigger_type As UShort
    Public m_stop_trigger_type As UShort
    Public m_delay_time As UInteger
    Public m_start_level_trigger_edge As UShort
    Public m_start_level_sequence_no As UShort
    Public m_start_level_border_value As Single
    Public m_start_range_sequence_no As UShort
    Public m_start_range_upper_border_value As Single
    Public m_start_range_lower_border_value As Single
    Public m_start_range_state_times As UInteger
    Public m_start_time_time As UInteger
    Public m_start_time_hour As UInteger
    Public m_start_time_minute As UInteger
    Public m_start_time_second As UInteger
    Public m_stop_level_trigger_edge As UShort
    Public m_stop_level_sequence_no As UShort
    Public m_stop_level_border_value As Single
    Public m_stop_range_sequence_no As UShort
    Public m_stop_range_upper_border_value As Single
    Public m_stop_range_lower_border_value As Single
    Public m_stop_range_state_times As UInteger
    Public m_stop_time_time As UInteger
    Public m_stop_time_hour As UInteger
    Public m_stop_time_minute As UInteger
    Public m_stop_time_second As UInteger
    '----------------------------------------
    ' Pass the data (Set)
    '----------------------------------------
    Public Sub clock_data_set(clock_type As UShort,
                       sampling_clock_unit As UShort,
                       sampling_clock As Double,
                       external_clock As Double,
                       sampling_times As UInteger,
                       scan_clock As Single,
                       repeat_times As UInteger,
                       start_trigger_type As UShort,
                       stop_trigger_type As UShort,
                       delay_time As UInteger,
                       start_level_trigger_edge As UShort,
                       start_level_sequence_no As UShort,
                       start_level_border_value As Single,
                       start_range_sequence_no As UShort,
                       start_range_upper_border_value As Single,
                       start_range_lower_border_value As Single,
                       start_range_state_times As UInteger,
                       start_time_time As UInteger,
                       start_time_hour As UInteger,
                       start_time_minute As UInteger,
                       start_time_second As UInteger,
                       stop_level_trigger_edge As UShort,
                       stop_level_sequence_no As UShort,
                       stop_level_border_value As Single,
                       stop_range_sequence_no As UShort,
                       stop_range_upper_border_value As Single,
                       stop_range_lower_border_value As Single,
                       stop_range_state_times As UInteger,
                       stop_time_time As UInteger,
                       stop_time_hour As UInteger,
                       stop_time_minute As UInteger,
                       stop_time_second As UInteger)
        m_clock_type = clock_type
        m_sampling_clock_unit = sampling_clock_unit
        m_sampling_clock = sampling_clock
        m_external_clock = external_clock
        m_sampling_times = sampling_times
        m_scan_clock = scan_clock
        m_repeat_times = repeat_times
        m_start_trigger_type = start_trigger_type
        m_stop_trigger_type = stop_trigger_type
        m_delay_time = delay_time
        m_start_level_trigger_edge = start_level_trigger_edge
        m_start_level_sequence_no = start_level_sequence_no
        m_start_level_border_value = start_level_border_value
        m_start_range_sequence_no = start_range_sequence_no
        m_start_range_upper_border_value = start_range_upper_border_value
        m_start_range_lower_border_value = start_range_lower_border_value
        m_start_range_state_times = start_range_state_times
        m_start_time_time = start_time_time
        m_start_time_hour = start_time_hour
        m_start_time_minute = start_time_minute
        m_start_time_second = start_time_second
        m_stop_level_trigger_edge = stop_level_trigger_edge
        m_stop_level_sequence_no = stop_level_sequence_no
        m_stop_level_border_value = stop_level_border_value
        m_stop_range_sequence_no = stop_range_sequence_no
        m_stop_range_upper_border_value = stop_range_upper_border_value
        m_stop_range_lower_border_value = stop_range_lower_border_value
        m_stop_range_state_times = stop_range_state_times
        m_stop_time_time = stop_time_time
        m_stop_time_hour = stop_time_hour
        m_stop_time_minute = stop_time_minute
        m_stop_time_second = stop_time_second
    End Sub
    '----------------------------------------
    ' Pass the data (Get)
    '----------------------------------------
    Public Sub clock_data_get(ByRef clock_type As UShort,
                       ByRef sampling_clock_unit As UShort,
                       ByRef sampling_clock As Double,
                       ByRef external_clock As Double,
                       ByRef sampling_times As UInteger,
                       ByRef scan_clock As Single,
                       ByRef repeat_times As UInteger,
                       ByRef start_trigger_type As UShort,
                       ByRef stop_trigger_type As UShort,
                       ByRef delay_time As UInteger,
                       ByRef start_level_trigger_edge As UShort,
                       ByRef start_level_sequence_no As UShort,
                       ByRef start_level_border_value As Single,
                       ByRef start_range_sequence_no As UShort,
                       ByRef start_range_upper_border_value As Single,
                       ByRef start_range_lower_border_value As Single,
                       ByRef start_range_state_times As UInteger,
                       ByRef start_time_time As UInteger,
                       ByRef start_time_hour As UInteger,
                       ByRef start_time_minute As UInteger,
                       ByRef start_time_second As UInteger,
                       ByRef stop_level_trigger_edge As UShort,
                       ByRef stop_level_sequence_no As UShort,
                       ByRef stop_level_border_value As Single,
                       ByRef stop_range_sequence_no As UShort,
                       ByRef stop_range_upper_border_value As Single,
                       ByRef stop_range_lower_border_value As Single,
                       ByRef stop_range_state_times As UInteger,
                       ByRef stop_time_time As UInteger,
                       ByRef stop_time_hour As UInteger,
                       ByRef stop_time_minute As UInteger,
                       ByRef stop_time_second As UInteger)
        clock_type = m_clock_type
        sampling_clock_unit = m_sampling_clock_unit
        sampling_clock = m_sampling_clock
        external_clock = m_external_clock
        sampling_times = m_sampling_times
        scan_clock = m_scan_clock
        repeat_times = m_repeat_times
        start_trigger_type = m_start_trigger_type
        stop_trigger_type = m_stop_trigger_type
        delay_time = m_delay_time
        start_level_trigger_edge = m_start_level_trigger_edge
        start_level_sequence_no = m_start_level_sequence_no
        start_level_border_value = m_start_level_border_value
        start_range_sequence_no = m_start_range_sequence_no
        start_range_upper_border_value = m_start_range_upper_border_value
        start_range_lower_border_value = m_start_range_lower_border_value
        start_range_state_times = m_start_range_state_times
        start_time_time = m_start_time_time
        start_time_hour = m_start_time_hour
        start_time_minute = m_start_time_minute
        start_time_second = m_start_time_second
        stop_level_trigger_edge = m_stop_level_trigger_edge
        stop_level_sequence_no = m_stop_level_sequence_no
        stop_level_border_value = m_stop_level_border_value
        stop_range_sequence_no = m_stop_range_sequence_no
        stop_range_upper_border_value = m_stop_range_upper_border_value
        stop_range_lower_border_value = m_stop_range_lower_border_value
        stop_range_state_times = m_stop_range_state_times
        stop_time_time = m_stop_time_time
        stop_time_hour = m_stop_time_hour
        stop_time_minute = m_stop_time_minute
        stop_time_second = m_stop_time_second
    End Sub

    Private Sub ClockSetting_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '----------------------------------------
        ' Create the combobox for clock type
        '----------------------------------------
        ComboBox_ClockType.Items.Add("Internal clock")
        ComboBox_ClockType.Items.Add("External clock(Falling edge)")
        ComboBox_ClockType.Items.Add("External clock(Rising edge)")
        '----------------------------------------
        ' Update the selection of clock type combobox
        '----------------------------------------
        ComboBox_ClockType.SelectedIndex = m_clock_type
        Call ComboBox_ClockType_SelectedIndexChanged(Nothing, Nothing)
        '----------------------------------------
        ' Update the display of sampling clock period(frequency)
        '----------------------------------------
        TextBox_SamplingClock.Text = m_sampling_clock.ToString()
        '----------------------------------------
        ' Update the display of external clock update interval
        '----------------------------------------
        TextBox_ExternalClockInputTiming.Text = m_external_clock.ToString()
        '----------------------------------------
        ' Create the combobox for sampling clock unit
        '----------------------------------------
        ComboBox_SamplingClockUnit.Items.Add("usec")
        ComboBox_SamplingClockUnit.Items.Add("msec")
        ComboBox_SamplingClockUnit.Items.Add("sec")
        ComboBox_SamplingClockUnit.Items.Add("Hz")
        ComboBox_SamplingClockUnit.Items.Add("kHz")
        ComboBox_SamplingClockUnit.Items.Add("MHz")
        '----------------------------------------
        ' Update the selection of sampling clock unit combobox
        '----------------------------------------
        ComboBox_SamplingClockUnit.SelectedIndex = m_sampling_clock_unit
        '----------------------------------------
        ' Create the combobox for sampling condition
        '----------------------------------------
        ComboBox_SamplingCondition.Items.Add("Infinite")
        ComboBox_SamplingCondition.Items.Add("Finite")
        '----------------------------------------
        ' Update the selection of sampling condition combobox
        '----------------------------------------
        If m_sampling_times = 0 Then
            ComboBox_SamplingCondition.SelectedIndex = 0
        Else
            ComboBox_SamplingCondition.SelectedIndex = 1
        End If
        '----------------------------------------
        ' Perform the processing when the value of the sampling condition combobox is changed
        '----------------------------------------
        Call ComboBox_SamplingCondition_SelectedIndexChanged(Nothing, Nothing)
        '----------------------------------------
        ' Update the display of sampling times
        '----------------------------------------
        TextBox_SamplingTimes.Text = m_sampling_times.ToString()
        '----------------------------------------
        ' Update the display of scan clock
        '----------------------------------------
        TextBox_ScanClock.Text = m_scan_clock.ToString()
        '----------------------------------------
        ' Update the display of repeat times
        '----------------------------------------
        TextBox_RepeatTimes.Text = m_repeat_times.ToString()
        '----------------------------------------
        ' Create the combobox for delay condition
        '----------------------------------------
        ComboBox_DelayCondition.Items.Add("Disable")
        ComboBox_DelayCondition.Items.Add("Enable")
        '----------------------------------------
        ' Update the selection of delay condition combobox
        '----------------------------------------
        If m_delay_time = 0 Then
            ComboBox_DelayCondition.SelectedIndex = LOGGER_PARAM_DISABLE
        Else
            ComboBox_DelayCondition.SelectedIndex = LOGGER_PARAM_ENABLE
        End If
        '----------------------------------------
        ' Perform the processing when the value of the delay condition combobox is changed
        '----------------------------------------
        Call ComboBox_DelayCondition_SelectedIndexChanged(Nothing, Nothing)
        '----------------------------------------
        ' Update the display of delay times
        '----------------------------------------
        TextBox_DelayTimes.Text = m_delay_time.ToString()
        '----------------------------------------
        ' Create the combobox for start condition
        '----------------------------------------
        ComboBox_StartCondition.Items.Add("None")
        ComboBox_StartCondition.Items.Add("External trigger rising edge")
        ComboBox_StartCondition.Items.Add("External trigger falling edge")
        ComboBox_StartCondition.Items.Add("Level comparison")
        ComboBox_StartCondition.Items.Add("In range")
        ComboBox_StartCondition.Items.Add("Out range")
        ComboBox_StartCondition.Items.Add("Time (Time(sec))")
        ComboBox_StartCondition.Items.Add("Time (Moment)")
        '----------------------------------------
        ' Update the selection of start condition combobox
        '----------------------------------------
        ComboBox_StartCondition.SelectedIndex = m_start_trigger_type
        '----------------------------------------
        ' Perform the processing when the value of the start condition combobox is changed
        '----------------------------------------
        Call ComboBox_StartCondition_SelectedIndexChanged(Nothing, Nothing)
        '----------------------------------------
        ' Start condition -> Level comparison -> Update the display of channel number
        '----------------------------------------
        TextBox_StartLevelChNo.Text = m_start_level_sequence_no.ToString()
        '----------------------------------------
        ' Start condition -> Level comparison -> Update the display of comparison level
        '----------------------------------------
        TextBox_StartLevelComaprisonValue.Text = m_start_level_border_value.ToString()
        '----------------------------------------
        ' Start condition -> Level comparison -> Create the combobox for comparison direction
        '----------------------------------------
        ComboBox_StartLevelComparisonDirection.Items.Add("Rising edge")
        ComboBox_StartLevelComparisonDirection.Items.Add("Falling edge")
        ComboBox_StartLevelComparisonDirection.Items.Add("Both edges")
        '----------------------------------------
        ' Start condition -> Level comparison -> Update the selection of comparison direction combobox
        '----------------------------------------
        ComboBox_StartLevelComparisonDirection.SelectedIndex = m_start_level_trigger_edge
        '----------------------------------------
        ' Start condition -> In range/out range comparison -> Update the display of channel number
        '----------------------------------------
        TextBox_StartRangeChNo.Text = m_start_range_sequence_no.ToString()
        '----------------------------------------
        ' Start condition -> In range/out range comparison -> Update the display of lower limit value
        '----------------------------------------
        TextBox_StartRangeLowerLimitValue.Text = m_start_range_lower_border_value.ToString()
        '----------------------------------------
        ' Start condition -> In range/out range comparison -> Update the display of upper limit value
        '----------------------------------------
        TextBox_StartRangeUpperLimitValue.Text = m_start_range_upper_border_value.ToString()
        '----------------------------------------
        ' Start condition -> In range/out range comparison -> Update the display of state times
        '----------------------------------------
        TextBox_StartRangeStateTimes.Text = m_start_range_state_times.ToString()
        '----------------------------------------
        ' Start condition -> Time/Moment -> Update Time display
        '----------------------------------------
        TextBox_StartTime_Time.Text = m_start_time_time.ToString()
        '----------------------------------------
        ' Start condition -> Time/Moment -> Update Moment(H) display
        '----------------------------------------
        TextBox_StartTime_Hour.Text = m_start_time_hour.ToString()
        '----------------------------------------
        ' Start condition -> Time/Moment -> Update Moment(M) display
        '----------------------------------------
        TextBox_StartTime_Minute.Text = m_start_time_minute.ToString()
        '----------------------------------------
        ' Start condition -> Time/Moment -> Update Moment(S) display
        '----------------------------------------
        TextBox_StartTime_Second.Text = m_start_time_second.ToString()
        '----------------------------------------
        ' Create the combobox for stop condition
        '----------------------------------------
        ComboBox_StopCondition.Items.Add("None")
        ComboBox_StopCondition.Items.Add("External trigger rising edge")
        ComboBox_StopCondition.Items.Add("External trigger falling edge")
        ComboBox_StopCondition.Items.Add("Level comparison")
        ComboBox_StopCondition.Items.Add("In range")
        ComboBox_StopCondition.Items.Add("Out range")
        ComboBox_StopCondition.Items.Add("Time (Time(sec))")
        ComboBox_StopCondition.Items.Add("Time (Moment)")
        '----------------------------------------
        ' Update the selection of stop condition combobox
        '----------------------------------------
        ComboBox_StopCondition.SelectedIndex = m_stop_trigger_type
        '----------------------------------------
        ' Perform the processing when the value of the stop condition combobox is changed
        '----------------------------------------
        Call ComboBox_StopCondition_SelectedIndexChanged(Nothing, Nothing)
        '----------------------------------------
        ' Stop condition -> Level comparison -> Update the display of channel number
        '----------------------------------------
        TextBox_StopLevelChNo.Text = m_stop_level_sequence_no.ToString()
        '----------------------------------------
        ' Stop condition -> Level comparison -> Update the display of comparison level
        '----------------------------------------
        TextBox_StopLevelComparisonValue.Text = m_stop_level_border_value.ToString()
        '----------------------------------------
        ' Stop condition -> Level comparison -> Create the combobox for comparison direction
        '----------------------------------------
        ComboBox_StopLevelComparisonDirection.Items.Add("Rising edge")
        ComboBox_StopLevelComparisonDirection.Items.Add("Falling edge")
        ComboBox_StopLevelComparisonDirection.Items.Add("Both edges")
        '----------------------------------------
        ' Stop condition -> Level comparison -> Update the selection of comparison direction combobox
        '----------------------------------------
        ComboBox_StopLevelComparisonDirection.SelectedIndex = m_stop_level_trigger_edge
        '----------------------------------------
        ' Stop condition -> In range/out range comparison -> Update the display of channel number
        '----------------------------------------
        TextBox_StopRangeChNo.Text = m_stop_range_sequence_no.ToString()
        '----------------------------------------
        ' Stop condition -> In range/out range comparison -> Update the display of lower limit value
        '----------------------------------------
        TextBox_StopRangeLowerLimitValue.Text = m_stop_range_lower_border_value.ToString()
        '----------------------------------------
        ' Stop condition -> In range/out range comparison -> Update the display of upper limit value
        '----------------------------------------
        TextBox_StopRangeUpperLimitValue.Text = m_stop_range_upper_border_value.ToString()
        '----------------------------------------
        ' Stop condition -> In range/out range comparison -> Update the display of state times
        '----------------------------------------
        TextBox_StopRangeStateTimes.Text = m_stop_range_state_times.ToString()
        '----------------------------------------
        ' Stop condition -> Time/Moment -> Update Time display
        '----------------------------------------
        TextBox_StopTime_Time.Text = m_stop_time_time.ToString()
        '----------------------------------------
        ' Stop condition -> Time/Moment -> Update Moment(H) display
        '----------------------------------------
        TextBox_StopTime_Hour.Text = m_stop_time_hour.ToString()
        '----------------------------------------
        ' Stop condition -> Time/Moment -> Update Moment(M) display
        '----------------------------------------
        TextBox_StopTime_Minute.Text = m_stop_time_minute.ToString()
        '----------------------------------------
        ' Stop condition -> Time/Moment -> Update Moment(S) display
        '----------------------------------------
        TextBox_StopTime_Second.Text = m_stop_time_second.ToString()
    End Sub

    '================================================================================
    ' It is the process when the value of clock type combobox is changed
    ' Check the setting value and enable/disable the sampling clock period and the external clock update interval
    '================================================================================
    Private Sub ComboBox_ClockType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_ClockType.SelectedIndexChanged
        '----------------------------------------
        ' Get the clock type from combobox
        '----------------------------------------
        Dim select_clocktype As Integer = ComboBox_ClockType.SelectedIndex
        '----------------------------------------
        ' For internal clock
        '----------------------------------------
        If select_clocktype = LOGGER_PARAM_CLOCK_INTERNAL Then
            '----------------------------------------
            ' Enable the sampling clock period
            '----------------------------------------
            TextBox_SamplingClock.Enabled = True
            ComboBox_SamplingClockUnit.Enabled = True
            '----------------------------------------
            ' Disable the external clock update interval
            '----------------------------------------
            TextBox_ExternalClockInputTiming.Enabled = False
            '----------------------------------------
            ' For external clock
            '----------------------------------------
        Else
            '----------------------------------------
            ' Disable the sampling clock period
            '----------------------------------------
            TextBox_SamplingClock.Enabled = False
            ComboBox_SamplingClockUnit.Enabled = False
            '----------------------------------------
            ' Enable the external clock update interval
            '----------------------------------------
            TextBox_ExternalClockInputTiming.Enabled = True
        End If
    End Sub

    '================================================================================
    ' It is the process when the value of sampling condition combobox is changed
    ' Check the setting value and enable/disable the sampling times
    '================================================================================
    Private Sub ComboBox_SamplingCondition_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_SamplingCondition.SelectedIndexChanged
        '----------------------------------------
        ' Get the sampling condition from combobox
        '----------------------------------------
        Dim sampling_condition As Integer = ComboBox_SamplingCondition.SelectedIndex
        '----------------------------------------
        ' For infinite
        '----------------------------------------
        If sampling_condition = 0 Then
            '----------------------------------------
            ' Disable the sampling times
            '----------------------------------------
            TextBox_SamplingTimes.Enabled = False
            '----------------------------------------
            ' For finite
            '----------------------------------------
        Else
            '----------------------------------------
            ' Enable the sampling times
            '----------------------------------------
            TextBox_SamplingTimes.Enabled = True
        End If
    End Sub

    '================================================================================
    ' It is the process when the value of delay condition combobox is changed
    ' Check the setting value and enable/disable the delay times
    '================================================================================
    Private Sub ComboBox_DelayCondition_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_DelayCondition.SelectedIndexChanged
        '----------------------------------------
        ' Get the delay condition from combobox
        '----------------------------------------
        Dim delay_condition As Integer = ComboBox_DelayCondition.SelectedIndex
        '----------------------------------------
        ' For disable
        '----------------------------------------
        If delay_condition = LOGGER_PARAM_DISABLE Then
            '----------------------------------------
            ' Disable the delay times
            '----------------------------------------
            TextBox_DelayTimes.Enabled = False
            '----------------------------------------
            ' For enable
            '----------------------------------------
        Else
            '----------------------------------------
            ' Enable the delay times
            '----------------------------------------
            TextBox_DelayTimes.Enabled = True
        End If
    End Sub

    '================================================================================
    ' It is the process when the value of start condition combobox is changed
    ' Check the setting value and enable/disable the level comparison and the in range/out range comparison
    '================================================================================
    Private Sub ComboBox_StartCondition_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_StartCondition.SelectedIndexChanged
        '----------------------------------------
        ' Get the start condition from combobox
        '----------------------------------------
        Dim select_trigger_type As Integer = ComboBox_StartCondition.SelectedIndex
        '----------------------------------------
        ' For level comparison
        '----------------------------------------
        If select_trigger_type = LOGGER_PARAM_TRIGGER_LEVEL Then
            '----------------------------------------
            ' Enable the level comparison
            '----------------------------------------
            TextBox_StartLevelChNo.Enabled = True
            TextBox_StartLevelComaprisonValue.Enabled = True
            ComboBox_StartLevelComparisonDirection.Enabled = True
            '----------------------------------------
            ' Disable the in range/out range comparison
            '----------------------------------------
            TextBox_StartRangeChNo.Enabled = False
            TextBox_StartRangeLowerLimitValue.Enabled = False
            TextBox_StartRangeUpperLimitValue.Enabled = False
            TextBox_StartRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StartTime_Time.Enabled = False
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StartTime_Hour.Enabled = False
            TextBox_StartTime_Minute.Enabled = False
            TextBox_StartTime_Second.Enabled = False
            '----------------------------------------
            ' For in range/out range comparison
            '----------------------------------------
        ElseIf select_trigger_type = LOGGER_PARAM_TRIGGER_INRANGE OrElse
               select_trigger_type = LOGGER_PARAM_TRIGGER_OUTRANGE Then
            '----------------------------------------
            ' Disable the level comparison
            '----------------------------------------
            TextBox_StartLevelChNo.Enabled = False
            TextBox_StartLevelComaprisonValue.Enabled = False
            ComboBox_StartLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Enable the in range/out range comparison
            '----------------------------------------
            TextBox_StartRangeChNo.Enabled = True
            TextBox_StartRangeLowerLimitValue.Enabled = True
            TextBox_StartRangeUpperLimitValue.Enabled = True
            TextBox_StartRangeStateTimes.Enabled = True
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StartTime_Time.Enabled = False
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StartTime_Hour.Enabled = False
            TextBox_StartTime_Minute.Enabled = False
            TextBox_StartTime_Second.Enabled = False
            '----------------------------------------
            ' For Time (Time(sec))
            '----------------------------------------
        ElseIf select_trigger_type = LOGGER_PARAM_TRIGGER_ELAPSED_TIME Then
            '----------------------------------------
            ' Disable level comparison
            '----------------------------------------
            TextBox_StartLevelChNo.Enabled = False
            TextBox_StartLevelComaprisonValue.Enabled = False
            ComboBox_StartLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Disable in range/out range comparison
            '----------------------------------------
            TextBox_StartRangeChNo.Enabled = False
            TextBox_StartRangeLowerLimitValue.Enabled = False
            TextBox_StartRangeUpperLimitValue.Enabled = False
            TextBox_StartRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Enable Time
            '----------------------------------------
            TextBox_StartTime_Time.Enabled = True
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StartTime_Hour.Enabled = False
            TextBox_StartTime_Minute.Enabled = False
            TextBox_StartTime_Second.Enabled = False
            '----------------------------------------
            ' For Time (Moment)
            '----------------------------------------
        ElseIf select_trigger_type = LOGGER_PARAM_TRIGGER_CURRENT_TIME Then
            '----------------------------------------
            ' Disable level comparison
            '----------------------------------------
            TextBox_StartLevelChNo.Enabled = False
            TextBox_StartLevelComaprisonValue.Enabled = False
            ComboBox_StartLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Disable in range/out range comparison
            '----------------------------------------
            TextBox_StartRangeChNo.Enabled = False
            TextBox_StartRangeLowerLimitValue.Enabled = False
            TextBox_StartRangeUpperLimitValue.Enabled = False
            TextBox_StartRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StartTime_Time.Enabled = False
            '----------------------------------------
            ' Enable Moment
            '----------------------------------------
            TextBox_StartTime_Hour.Enabled = True
            TextBox_StartTime_Minute.Enabled = True
            TextBox_StartTime_Second.Enabled = True
            '----------------------------------------
            ' Other than level, range comparison, Time, Moment
            '----------------------------------------
        Else
            '----------------------------------------
            ' Disable the level comparison
            '----------------------------------------
            TextBox_StartLevelChNo.Enabled = False
            TextBox_StartLevelComaprisonValue.Enabled = False
            ComboBox_StartLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Disable the in range/out range comparison
            '----------------------------------------
            TextBox_StartRangeChNo.Enabled = False
            TextBox_StartRangeLowerLimitValue.Enabled = False
            TextBox_StartRangeUpperLimitValue.Enabled = False
            TextBox_StartRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StartTime_Time.Enabled = False
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StartTime_Hour.Enabled = False
            TextBox_StartTime_Minute.Enabled = False
            TextBox_StartTime_Second.Enabled = False
        End If
    End Sub

    '================================================================================
    ' It is the process when the value of stop condition combobox is changed
    ' Check the setting value and enable/disable the level comparison and the in range/out range comparison
    '================================================================================
    Private Sub ComboBox_StopCondition_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_StopCondition.SelectedIndexChanged
        '----------------------------------------
        ' Get the stop condition from combobox
        '----------------------------------------
        Dim select_trigger_type As Integer = ComboBox_StopCondition.SelectedIndex
        '----------------------------------------
        ' For level comparison
        '----------------------------------------
        If select_trigger_type = LOGGER_PARAM_TRIGGER_LEVEL Then
            '----------------------------------------
            ' Enable the level comparison
            '----------------------------------------
            TextBox_StopLevelChNo.Enabled = True
            TextBox_StopLevelComparisonValue.Enabled = True
            ComboBox_StopLevelComparisonDirection.Enabled = True
            '----------------------------------------
            ' Disable the in range/out range comparison
            '----------------------------------------
            TextBox_StopRangeChNo.Enabled = False
            TextBox_StopRangeLowerLimitValue.Enabled = False
            TextBox_StopRangeUpperLimitValue.Enabled = False
            TextBox_StopRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StopTime_Time.Enabled = False
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StopTime_Hour.Enabled = False
            TextBox_StopTime_Minute.Enabled = False
            TextBox_StopTime_Second.Enabled = False
            '----------------------------------------
            ' For in range/out range comparison
            '----------------------------------------
        ElseIf select_trigger_type = LOGGER_PARAM_TRIGGER_INRANGE OrElse
               select_trigger_type = LOGGER_PARAM_TRIGGER_OUTRANGE Then
            '----------------------------------------
            ' Disable the level comparison
            '----------------------------------------
            TextBox_StopLevelChNo.Enabled = False
            TextBox_StopLevelComparisonValue.Enabled = False
            ComboBox_StopLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Enable the in range/out range comparison
            '----------------------------------------
            TextBox_StopRangeChNo.Enabled = True
            TextBox_StopRangeLowerLimitValue.Enabled = True
            TextBox_StopRangeUpperLimitValue.Enabled = True
            TextBox_StopRangeStateTimes.Enabled = True
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StopTime_Time.Enabled = False
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StopTime_Hour.Enabled = False
            TextBox_StopTime_Minute.Enabled = False
            TextBox_StopTime_Second.Enabled = False
            '----------------------------------------
            ' For Time (Time(sec))
            '----------------------------------------
        ElseIf select_trigger_type = LOGGER_PARAM_TRIGGER_ELAPSED_TIME Then
            '----------------------------------------
            ' Disable level comparison
            '----------------------------------------
            TextBox_StopLevelChNo.Enabled = False
            TextBox_StopLevelComparisonValue.Enabled = False
            ComboBox_StopLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Disable in range/out range comparison
            '----------------------------------------
            TextBox_StopRangeChNo.Enabled = False
            TextBox_StopRangeLowerLimitValue.Enabled = False
            TextBox_StopRangeUpperLimitValue.Enabled = False
            TextBox_StopRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Enable Time
            '----------------------------------------
            TextBox_StopTime_Time.Enabled = True
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StopTime_Hour.Enabled = False
            TextBox_StopTime_Minute.Enabled = False
            TextBox_StopTime_Second.Enabled = False
            '----------------------------------------
            ' For Time (Moment)
            '----------------------------------------
        ElseIf select_trigger_type = LOGGER_PARAM_TRIGGER_CURRENT_TIME Then
            '----------------------------------------
            ' Disable level comparison
            '----------------------------------------
            TextBox_StopLevelChNo.Enabled = False
            TextBox_StopLevelComparisonValue.Enabled = False
            ComboBox_StopLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Disable in range/out range comparison
            '----------------------------------------
            TextBox_StopRangeChNo.Enabled = False
            TextBox_StopRangeLowerLimitValue.Enabled = False
            TextBox_StopRangeUpperLimitValue.Enabled = False
            TextBox_StopRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StopTime_Time.Enabled = False
            '----------------------------------------
            ' Enable Moment
            '----------------------------------------
            TextBox_StopTime_Hour.Enabled = True
            TextBox_StopTime_Minute.Enabled = True
            TextBox_StopTime_Second.Enabled = True
            '----------------------------------------
            ' Other than level, range comparison, Time, Moment
            '----------------------------------------
        Else
            '----------------------------------------
            ' Disable the level comparison
            '----------------------------------------
            TextBox_StopLevelChNo.Enabled = False
            TextBox_StopLevelComparisonValue.Enabled = False
            ComboBox_StopLevelComparisonDirection.Enabled = False
            '----------------------------------------
            ' Disable the in range/out range comparison
            '----------------------------------------
            TextBox_StopRangeChNo.Enabled = False
            TextBox_StopRangeLowerLimitValue.Enabled = False
            TextBox_StopRangeUpperLimitValue.Enabled = False
            TextBox_StopRangeStateTimes.Enabled = False
            '----------------------------------------
            ' Disable Time
            '----------------------------------------
            TextBox_StopTime_Time.Enabled = False
            '----------------------------------------
            ' Disable Moment
            '----------------------------------------
            TextBox_StopTime_Hour.Enabled = False
            TextBox_StopTime_Minute.Enabled = False
            TextBox_StopTime_Second.Enabled = False
        End If
    End Sub

    '================================================================================
    ' It is the process when the Apply button is clicked
    ' Confirm the setting value
    '================================================================================
    Private Sub Button_Ok_Click(sender As Object, e As EventArgs) Handles Button_Ok.Click
        Dim pre_clock_type As UShort                        ' For temporary storage  Clock type
        Dim pre_sampling_clock_unit As UShort               ' For temporary storage  Sampling clock unit
        Dim pre_sampling_clock As Double                    ' For temporary storage  Sampling clock
        Dim pre_external_clock As Double                    ' For temporary storage  External clock
        Dim pre_sampling_times As UInteger                  ' For temporary storage  Sampling times condition
        Dim pre_scan_clock As Single                        ' For temporary storage  Scan clock
        Dim pre_repeat_times As UInteger                    ' For temporary storage  Repeat times condition
        Dim pre_start_trigger_type As UShort                ' For temporary storage  Start condition
        Dim pre_stop_trigger_type As UShort                 ' For temporary storage  Stop condition
        Dim pre_delay_time As UInteger                      ' For temporary storage  Delay sampling condition
        Dim pre_start_level_trigger_edge As UShort          ' For temporary storage  Start trigger  Level comparison  Comparison direction
        Dim pre_start_level_sequence_no As UShort           ' For temporary storage  Start trigger  Level comparison  Sequence number
        Dim pre_start_level_border_value As Single          ' For temporary storage  Start trigger  Level comparison  Comparison value
        Dim pre_start_range_sequence_no As UShort           ' For temporary storage  Start trigger  In range/out range comparison  Sequence number
        Dim pre_start_range_upper_border_value As Single    ' For temporary storage  Start trigger  In range/out range comparison  Upper limit value
        Dim pre_start_range_lower_border_value As Single    ' For temporary storage  Start trigger  In range/out range comparison  Lower limit value
        Dim pre_start_range_state_times As UInteger         ' For temporary storage  Start trigger  In range/out range comparison  State times
        Dim pre_start_time_time As UInteger                 ' For temporary storage  Start trigger  Time/Moment  Time
        Dim pre_start_time_hour As UInteger                 ' For temporary storage  Start trigger  Time/Moment  Moment(H)
        Dim pre_start_time_minute As UInteger               ' For temporary storage  Start trigger  Time/Moment  Moment(M)
        Dim pre_start_time_second As UInteger               ' For temporary storage  Start trigger  Time/Moment  Moment(S)
        Dim pre_stop_level_trigger_edge As UShort           ' For temporary storage  Stop trigger  Level comparison  Comparison direction
        Dim pre_stop_level_sequence_no As UShort            ' For temporary storage  Stop trigger  Level comparison  Sequence number
        Dim pre_stop_level_border_value As Single           ' For temporary storage  Stop trigger  Level comparison  Comparison value
        Dim pre_stop_range_sequence_no As UShort            ' For temporary storage  Stop trigger  In range/out range comparison  Sequence number
        Dim pre_stop_range_upper_border_value As Single     ' For temporary storage  Stop trigger  In range/out range comparison  Upper limit value
        Dim pre_stop_range_lower_border_value As Single     ' For temporary storage  Stop trigger  In range/out range comparison  Lower limit value
        Dim pre_stop_range_state_times As UInteger          ' For temporary storage  Stop trigger  In range/out range comparison  State times
        Dim pre_stop_time_time As UInteger                  ' For temporary storage  Stop trigger  Time/Moment  Time
        Dim pre_stop_time_hour As UInteger                  ' For temporary storage  Stop trigger  Time/Moment  Moment(H)
        Dim pre_stop_time_minute As UInteger                ' For temporary storage  Stop trigger  Time/Moment  Moment(M)
        Dim pre_stop_time_second As UInteger                ' For temporary storage  Stop trigger  Time/Moment  Moment(S)

        '----------------------------------------
        ' Get the clock type from combobox
        '----------------------------------------
        pre_clock_type = CUShort(ComboBox_ClockType.SelectedIndex)
        '----------------------------------------
        ' Get the sampling clock unit from combobox
        '----------------------------------------
        pre_sampling_clock_unit = CUShort(ComboBox_SamplingClockUnit.SelectedIndex)
        '----------------------------------------
        ' Get the sampling clock period from textbox
        '----------------------------------------
        If Double.TryParse(TextBox_SamplingClock.Text, pre_sampling_clock) = False Then
            pre_sampling_clock = 0.0
        End If
        '----------------------------------------
        ' Get the external clock update interval from textbox
        '----------------------------------------
        If Double.TryParse(TextBox_ExternalClockInputTiming.Text, pre_external_clock) = False Then
            pre_external_clock = 0.0
        End If
        '----------------------------------------
        ' Get the sampling condition from combobox
        '----------------------------------------
        If ComboBox_SamplingCondition.SelectedIndex = 0 Then
            '----------------------------------------
            ' If infinite, set to 0
            '----------------------------------------
            pre_sampling_times = 0
        Else
            '----------------------------------------
            ' If finite, get the sampling times from textbox
            '----------------------------------------
            If UInteger.TryParse(TextBox_SamplingTimes.Text, pre_sampling_times) = False Then
                pre_sampling_times = 0
            End If
        End If
        '----------------------------------------
        ' Get the conversion speed from textbox
        '----------------------------------------
        If Single.TryParse(TextBox_ScanClock.Text, pre_scan_clock) = False Then
            pre_scan_clock = 0.0F
        End If
        '----------------------------------------
        ' Get the repeat times from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_RepeatTimes.Text, pre_repeat_times) = False Then
            pre_repeat_times = 0
        End If
        '----------------------------------------
        ' Get the delay condition from combobox
        '----------------------------------------
        If ComboBox_DelayCondition.SelectedIndex = LOGGER_PARAM_DISABLE Then
            '----------------------------------------
            ' If disable, set to 0
            '----------------------------------------
            pre_delay_time = 0
        Else
            '----------------------------------------
            ' If enable, get the delay times from textbox
            '----------------------------------------
            If UInteger.TryParse(TextBox_DelayTimes.Text, pre_delay_time) = False Then
                pre_delay_time = 0
            End If
        End If
        '----------------------------------------
        ' Get the start condition from combobox
        '----------------------------------------
        pre_start_trigger_type = CUShort(ComboBox_StartCondition.SelectedIndex)
        '----------------------------------------
        ' Start condition - Level comparison - Get the channel number from textbox
        '----------------------------------------
        If UShort.TryParse(TextBox_StartLevelChNo.Text, pre_start_level_sequence_no) = False Then
            pre_start_level_sequence_no = 0
        End If
        '----------------------------------------
        ' Start condition - Level comparison - Get the comparison level from textbox
        '----------------------------------------
        If Single.TryParse(TextBox_StartLevelComaprisonValue.Text, pre_start_level_border_value) = False Then
            pre_start_level_border_value = 0.0F
        End If
        '----------------------------------------
        ' Start condition - Level comparison - Get the comparison direction from combobox
        '----------------------------------------
        pre_start_level_trigger_edge = CUShort(ComboBox_StartLevelComparisonDirection.SelectedIndex)
        '----------------------------------------
        ' Start condition - In range/out range comparison - Get the channel number from textbox
        '----------------------------------------
        If UShort.TryParse(TextBox_StartRangeChNo.Text, pre_start_range_sequence_no) = False Then
            pre_start_range_sequence_no = 0
        End If
        '----------------------------------------
        ' Start condition - In range/out range comparison - Get the upper limit value from textbox
        '----------------------------------------
        If Single.TryParse(TextBox_StartRangeUpperLimitValue.Text, pre_start_range_upper_border_value) = False Then
            pre_start_range_upper_border_value = 0.0F
        End If
        '----------------------------------------
        ' Start condition - In range/out range comparison - Get the lower limit value from textbox
        '----------------------------------------
        If Single.TryParse(TextBox_StartRangeLowerLimitValue.Text, pre_start_range_lower_border_value) = False Then
            pre_start_range_lower_border_value = 0.0F
        End If
        '----------------------------------------
        ' Start condition - In range/out range comparison - Get the state times from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StartRangeStateTimes.Text, pre_start_range_state_times) = False Then
            pre_start_range_state_times = 0
        End If
        '----------------------------------------
        ' Start condition - Time/Moment - Get the Time from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StartTime_Time.Text, pre_start_time_time) = False Then
            pre_start_time_time = 0
        End If
        '----------------------------------------
        ' Start condition - Time/Moment - Get the Moment(H) from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StartTime_Hour.Text, pre_start_time_hour) = False Then
            pre_start_time_hour = 0
        End If
        '----------------------------------------
        ' Start condition - Time/Moment - Get the Moment(M) from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StartTime_Minute.Text, pre_start_time_minute) = False Then
            pre_start_time_minute = 0
        End If
        '----------------------------------------
        ' Start condition - Time/Moment - Get the Moment(S) from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StartTime_Second.Text, pre_start_time_second) = False Then
            pre_start_time_second = 0
        End If
        '----------------------------------------
        ' Get the stop condition from combobox
        '----------------------------------------
        pre_stop_trigger_type = CUShort(ComboBox_StopCondition.SelectedIndex)
        '----------------------------------------
        ' Stop condition - Level comparison - Get the channel number from textbox
        '----------------------------------------
        If UShort.TryParse(TextBox_StopLevelChNo.Text, pre_stop_level_sequence_no) = False Then
            pre_stop_level_sequence_no = 0
        End If
        '----------------------------------------
        ' Stop condition - Level comparison - Get the comparison level from textbox
        '----------------------------------------
        If Single.TryParse(TextBox_StopLevelComparisonValue.Text, pre_stop_level_border_value) = False Then
            pre_stop_level_border_value = 0.0F
        End If
        '----------------------------------------
        ' Stop condition - Level comparison - Get the comparison direction from combobox
        '----------------------------------------
        pre_stop_level_trigger_edge = CUShort(ComboBox_StopLevelComparisonDirection.SelectedIndex)
        '----------------------------------------
        ' Stop condition - In range/out range comparison - Get the channel number from textbox
        '----------------------------------------
        If UShort.TryParse(TextBox_StopRangeChNo.Text, pre_stop_range_sequence_no) = False Then
            pre_stop_range_sequence_no = 0
        End If
        '----------------------------------------
        ' Stop condition - In range/out range comparison - Get the upper limit value from textbox
        '----------------------------------------
        If Single.TryParse(TextBox_StopRangeUpperLimitValue.Text, pre_stop_range_upper_border_value) = False Then
            pre_stop_range_upper_border_value = 0.0F
        End If
        '----------------------------------------
        ' Stop condition - In range/out range comparison - Get the lower limit value from textbox
        '----------------------------------------
        If Single.TryParse(TextBox_StopRangeLowerLimitValue.Text, pre_stop_range_lower_border_value) = False Then
            pre_stop_range_lower_border_value = 0.0F
        End If
        '----------------------------------------
        ' Stop condition - In range/out range comparison - Get the state times from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StopRangeStateTimes.Text, pre_stop_range_state_times) = False Then
            pre_stop_range_state_times = 0
        End If
        '----------------------------------------
        ' Stop condition - Time/Moment - Get the Time from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StopTime_Time.Text, pre_stop_time_time) = False Then
            pre_stop_time_time = 0
        End If
        '----------------------------------------
        ' Stop condition - Time/Moment - Get the Moment(H) from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StopTime_Hour.Text, pre_stop_time_hour) = False Then
            pre_stop_time_hour = 0
        End If
        '----------------------------------------
        ' Stop condition - Time/Moment - Get the Moment(M) from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StopTime_Minute.Text, pre_stop_time_minute) = False Then
            pre_stop_time_minute = 0
        End If
        '----------------------------------------
        ' Stop condition - Time/Moment - Get the Moment(S) from textbox
        '----------------------------------------
        If UInteger.TryParse(TextBox_StopTime_Second.Text, pre_stop_time_second) = False Then
            pre_stop_time_second = 0
        End If
        '----------------------------------------
        ' Copy from temporary storage to member variable
        '----------------------------------------
        m_clock_type = pre_clock_type
        m_sampling_clock_unit = pre_sampling_clock_unit
        m_sampling_clock = pre_sampling_clock
        m_external_clock = pre_external_clock
        m_sampling_times = pre_sampling_times
        m_scan_clock = pre_scan_clock
        m_repeat_times = pre_repeat_times
        m_start_trigger_type = pre_start_trigger_type
        m_stop_trigger_type = pre_stop_trigger_type
        m_delay_time = pre_delay_time
        m_start_level_trigger_edge = pre_start_level_trigger_edge
        m_start_level_sequence_no = pre_start_level_sequence_no
        m_start_level_border_value = pre_start_level_border_value
        m_start_range_sequence_no = pre_start_range_sequence_no
        m_start_range_upper_border_value = pre_start_range_upper_border_value
        m_start_range_lower_border_value = pre_start_range_lower_border_value
        m_start_range_state_times = pre_start_range_state_times
        m_start_time_time = pre_start_time_time
        m_start_time_hour = pre_start_time_hour
        m_start_time_minute = pre_start_time_minute
        m_start_time_second = pre_start_time_second
        m_stop_level_trigger_edge = pre_stop_level_trigger_edge
        m_stop_level_sequence_no = pre_stop_level_sequence_no
        m_stop_level_border_value = pre_stop_level_border_value
        m_stop_range_sequence_no = pre_stop_range_sequence_no
        m_stop_range_upper_border_value = pre_stop_range_upper_border_value
        m_stop_range_lower_border_value = pre_stop_range_lower_border_value
        m_stop_range_state_times = pre_stop_range_state_times
        m_stop_time_time = pre_stop_time_time
        m_stop_time_hour = pre_stop_time_hour
        m_stop_time_minute = pre_stop_time_minute
        m_stop_time_second = pre_stop_time_second

        Me.DialogResult = DialogResult.OK
        Me.Close()
    End Sub

    '================================================================================
    ' It is the process when the Cancel button is clicked
    '================================================================================
    Private Sub Button_Cancel_Click(sender As Object, e As EventArgs) Handles Button_Cancel.Click
        Me.Close()
    End Sub
End Class