﻿Imports System.IO
Imports System.Text

Public Class Condition
    '----------------------------------------
    ' グローバル変数の宣言
    '----------------------------------------
    Dim g_start_trigger() As Short = {0,    ' ソフトウェア
                                      1,    ' 外部トリガ立ち上がり
                                      2,    ' 外部トリガ立ち下がり
                                      3,    ' レベル比較
                                      4,    ' インレンジ比較
                                      5}    ' アウトレンジ比較
    Dim g_clock_type() As Short = {0,       ' 内部クロック
                                   1}       ' 外部クロック
    Dim g_clock_edge() As Short = {0,       ' 立ち下がりエッジ
                                   1}       ' 立ち上がりエッジ
    Dim g_stop_trigger() As Short = {1,     ' 外部トリガ立ち上がり
                                     2,     ' 外部トリガ立ち下がり
                                     3,     ' レベル比較
                                     4,     ' コマンド（AioStopAi）
                                     5,     ' インレンジ比較
                                     6}     ' アウトレンジ比較

    Private Sub Condition_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim error_string As New StringBuilder("", 256)    ' エラーコード文字列
        Dim message_string As String = ""                 ' メッセージ表示用
        Dim ret As Integer                                ' 戻り値取得用
        Dim index As Short                                ' コンボボックスのインデックス
        Dim ai_start_trigger As Short                     ' 変換開始条件
        Dim ai_stop_trigger As Short                      ' 変換停止条件
        Dim ai_level As Single                            ' レベル比較データ
        Dim ai_direction As Short                         ' レベル比較の方向
        Dim ai_range_level1 As Single                     ' インレンジ/アウトレンジ比較データの上限値
        Dim ai_range_level2 As Single                     ' インレンジ/アウトレンジ比較データの下限値
        Dim ai_state_times As Integer                     ' 状態保持サンプリング回数
        Dim ai_clock_type As Short                        ' クロックの種類
        Dim ai_sampling_clock As Single                   ' サンプリングクロック
        Dim ai_clock_edge As Short                        ' 外部クロックの入力タイミング
        Dim ai_auto_mode As Short                         ' 転送サイズの設定モード
        Dim ai_transfer_size As Integer                   ' 転送サイズ
        Dim ai_scan_clock As Single                       ' 変換速度
        Dim err_flag As Short                             ' 関数の実行エラーフラグ

        '----------------------------------------
        ' パラメータの初期化
        '----------------------------------------
        err_flag = 0
        '----------------------------------------
        ' アナログ入力変換開始条件用コンボボックスの作成
        '----------------------------------------
        ComboBox_StartCondition.Items.Add("ソフトウェア")
        ComboBox_StartCondition.Items.Add("外部トリガ立ち上がり")
        ComboBox_StartCondition.Items.Add("外部トリガ立ち下がり")
        ComboBox_StartCondition.Items.Add("レベル比較")
        ComboBox_StartCondition.Items.Add("インレンジ比較")
        ComboBox_StartCondition.Items.Add("アウトレンジ比較")
        '----------------------------------------
        ' アナログ入力変換開始条件を取得
        '----------------------------------------
        ret = AioGetAiStartTrigger(Form1.g_id, ai_start_trigger)
        '----------------------------------------
        ' 異常終了の処理
        '----------------------------------------
        If (ret <> 0) Then
            If (ret <> 20001) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' エラーメッセージ生成
                '--------------------
                message_string = String.Format("AioGetAiStartTrigger = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                err_flag = 1
            Else
                '--------------------
                ' コントロールを無効に設定
                '--------------------
                ComboBox_StartCondition.Enabled = False
            End If
            '--------------------
            ' アナログ入力変換開始条件用コンボボックスの選択を0番に変更
            '--------------------
            ComboBox_StartCondition.SelectedIndex = 0
            ComboBox_StartCondition_SelectedIndexChanged(New Object(), New EventArgs())
        '----------------------------------------
        ' 正常終了の処理
        '----------------------------------------
        Else
            '--------------------
            ' 変換開始条件からインデックスに変換
            '--------------------
            index = 0
            Select Case ai_start_trigger
                Case 0
                    index = 0
                Case 1
                    index = 1
                Case 2
                    index = 2
                Case 3
                    index = 3
                Case 4
                    index = 4
                Case 5
                    index = 5
                Case Else
                    index = 0
            End Select
            '--------------------
            ' アナログ入力変換開始条件用コンボボックスの選択を変更
            '--------------------
            ComboBox_StartCondition.SelectedIndex = index
            ComboBox_StartCondition_SelectedIndexChanged(New Object(), New EventArgs())
        End If
        '----------------------------------------
        ' チャネル番号の初期表示を更新
        '----------------------------------------
        TextBox_StartLevelChNo.Text = "0"
        '----------------------------------------
        ' レベル比較方向用コンボボックスの作成
        '----------------------------------------
        ComboBox_StartLevelComprionDriection.Items.Add("両方")
        ComboBox_StartLevelComprionDriection.Items.Add("立ち上がり")
        ComboBox_StartLevelComprionDriection.Items.Add("立ち下がり")
        '----------------------------------------
        ' レベル比較の場合
        '----------------------------------------
        If (ai_start_trigger = 3) Then
            '----------------------------------------
            ' レベル比較開始時のレベルを取得
            '----------------------------------------
            ret = AioGetAiStartLevelEx(Form1.g_id, 0, ai_level, ai_direction)
            '----------------------------------------
            ' 異常終了の処理
            '----------------------------------------
            If (ret <> 0) Then
                If (ret <> 20001) Then
                    '--------------------
                    ' エラー文字列取得
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' メッセージ表示
                    '--------------------
                    message_string = String.Format("AioGetAiStartLevelEx = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                    err_flag = 1
                Else
                    '--------------------
                    ' コントロールを無効に設定
                    '--------------------
                    TextBox_StartLevelChNo.Enabled = FALSE
                    TextBox_StartLevelComprionValue.Enabled = FALSE
                    ComboBox_StartLevelComprionDriection.Enabled = FALSE
                End If
                '--------------------
                ' 比較値の初期表示を更新
                '--------------------
                TextBox_StartLevelComprionValue.Text = "1.0"
                '--------------------
                ' レベル比較方向用コンボボックスの選択を0番に変更
                '--------------------
                ComboBox_StartLevelComprionDriection.SelectedIndex = 0
            '----------------------------------------
            ' 正常終了の処理
            '----------------------------------------
            Else
                '--------------------
                ' 比較値を更新
                '--------------------
                TextBox_StartLevelComprionValue.Text = ai_level.ToString("F1")
                '--------------------
                ' レベル比較方向からインデックスに変換
                '--------------------
                index = 0
                Select Case ai_direction
                    Case 0
                        index = 0
                    Case 1
                        index = 1
                    Case 2
                        index = 2
                    Case Else
                        index = 0
                End Select
                '--------------------
                ' レベル比較方向用コンボボックスの選択を変更
                '--------------------
                ComboBox_StartLevelComprionDriection.SelectedIndex = index
            End If
        '----------------------------------------
        ' レベル比較以外の場合
        '----------------------------------------
        Else
            '--------------------
            ' 比較値の初期表示を更新
            '--------------------
            TextBox_StartLevelComprionValue.Text = "1.0"
            '--------------------
            ' レベル比較方向用コンボボックスの選択を0番に変更
            '--------------------
            ComboBox_StartLevelComprionDriection.SelectedIndex = 0
        End If
        '----------------------------------------
        ' チャネル番号の初期表示を更新
        '----------------------------------------
        TextBox_StartRangeChNo.Text = "0"
        '----------------------------------------
        ' インレンジ比較の場合
        '----------------------------------------
        If (ai_start_trigger = 4) Then
            '----------------------------------------
            ' インレンジ比較開始条件の設定値を取得
            '----------------------------------------
            ret = AioGetAiStartInRangeEx(Form1.g_id, 0, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' 異常終了の処理
            '----------------------------------------
            If (ret <> 0) Then
                If (ret <> 20001) Then
                    '--------------------
                    ' エラー文字列取得
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' メッセージ表示
                    '--------------------
                    message_string = String.Format("AioGetAiStartInRangeEx = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                    err_flag = 1
                Else
                    '--------------------
                    ' コントロールを無効に設定
                    '--------------------
                    TextBox_StartRangeChNo.Enabled = FALSE
                    TextBox_StartRangeUpperLimitValue.Enabled = FALSE
                    TextBox_StartRangeLowerLimitValue.Enabled = FALSE
                    TextBox_StartRangeStateTimes.Enabled = FALSE
                End If
                '--------------------
                ' 上限値の初期表示を更新
                '--------------------
                TextBox_StartRangeUpperLimitValue.Text = "10.0"
                '--------------------
                ' 下限値の初期表示を更新
                '--------------------
                TextBox_StartRangeLowerLimitValue.Text = "1.0"
                '--------------------
                ' 保持回数の初期表示を更新
                '--------------------
                TextBox_StartRangeStateTimes.Text = "1"
            '----------------------------------------
            ' 正常終了の処理
            '----------------------------------------
            Else
                '--------------------
                ' 上限値を更新
                '--------------------
                TextBox_StartRangeUpperLimitValue.Text = ai_range_level1.ToString("F1")
                '--------------------
                ' 下限値を更新
                '--------------------
                TextBox_StartRangeLowerLimitValue.Text = ai_range_level2.ToString("F1")
                '--------------------
                ' 保持回数を更新
                '--------------------
                TextBox_StartRangeStateTimes.Text = ai_state_times.ToString()
            End If
        '----------------------------------------
        ' アウトレンジ比較の場合
        '----------------------------------------
        ElseIf (ai_start_trigger = 5) Then
            '----------------------------------------
            ' アウトレンジ比較開始条件の設定値を取得
            '----------------------------------------
            ret = AioGetAiStartOutRangeEx(Form1.g_id, 0, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' 異常終了の処理
            '----------------------------------------
            If (ret <> 0) Then
                If (ret <> 20001) Then
                    '--------------------
                    ' エラー文字列取得
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' メッセージ表示
                    '--------------------
                    message_string = String.Format("AioGetAiStartOutRangeEx = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                    err_flag = 1
                Else
                    '--------------------
                    ' コントロールを無効に設定
                    '--------------------
                    TextBox_StartRangeChNo.Enabled = FALSE
                    TextBox_StartRangeUpperLimitValue.Enabled = FALSE
                    TextBox_StartRangeLowerLimitValue.Enabled = FALSE
                    TextBox_StartRangeStateTimes.Enabled = FALSE
                End If
                '--------------------
                ' 上限値の初期表示を更新
                '--------------------
                TextBox_StartRangeUpperLimitValue.Text = "10.0"
                '--------------------
                ' 下限値の初期表示を更新
                '--------------------
                TextBox_StartRangeLowerLimitValue.Text = "1.0"
                '--------------------
                ' 保持回数の初期表示を更新
                '--------------------
                TextBox_StartRangeStateTimes.Text = "1"
            '----------------------------------------
            ' 正常終了の処理
            '----------------------------------------
            Else
                '--------------------
                ' 上限値を更新
                '--------------------
                TextBox_StartRangeUpperLimitValue.Text = ai_range_level1.ToString("F1")
                '--------------------
                ' 下限値を更新
                '--------------------
                TextBox_StartRangeLowerLimitValue.Text = ai_range_level2.ToString("F1")
                '--------------------
                ' 保持回数を更新
                '--------------------
                TextBox_StartRangeStateTimes.Text = ai_state_times.ToString()
            End If
        '----------------------------------------
        ' インレンジ比較/アウトレンジ比較以外の場合
        '----------------------------------------
        Else
            '--------------------
            ' 上限値の初期表示を更新
            '--------------------
            TextBox_StartRangeUpperLimitValue.Text = "10.0"
            '--------------------
            ' 下限値の初期表示を更新
            '--------------------
            TextBox_StartRangeLowerLimitValue.Text = "1.0"
            '--------------------
            ' 保持回数の初期表示を更新
            '--------------------
            TextBox_StartRangeStateTimes.Text = "1"
        End If
        '----------------------------------------
        ' アナログ入力クロック種類用コンボボックスの作成
        '----------------------------------------
        ComboBox_ClockType.Items.Add("内部クロック")
        ComboBox_ClockType.Items.Add("外部クロック")
        '----------------------------------------
        ' クロックの種類を取得
        '----------------------------------------
        ret = AioGetAiClockType(Form1.g_id, ai_clock_type)
        '----------------------------------------
        ' 異常終了の処理
        '----------------------------------------
        If (ret <> 0) Then
            If (ret <> 20001) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                message_string = String.Format("AioGetAiClockType = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                err_flag = 1
            Else
                '--------------------
                ' コントロールを無効に設定
                '--------------------
                ComboBox_ClockType.Enabled = FALSE
            End If
            '--------------------
            ' アナログ入力クロック種類用コンボボックスの選択を0番に変更
            '--------------------
            ComboBox_ClockType.SelectedIndex = 0
            ComboBox_ClockType_SelectedIndexChanged(New Object(), New EventArgs())
        '----------------------------------------
        ' 正常終了の処理
        '----------------------------------------
        Else
            '--------------------
            ' クロック種類からインデックスに変換
            '--------------------
            index = 0
            Select Case ai_clock_type
                Case 0
                    index = 0
                Case 1
                    index = 1
                Case Else
                    index = 0
            End Select
            '--------------------
            ' アナログ入力クロック種類用コンボボックスの選択を変更
            '--------------------
            ComboBox_ClockType.SelectedIndex = index
            ComboBox_ClockType_SelectedIndexChanged(New Object(), New EventArgs())
        End If
        '----------------------------------------
        ' サンプリングクロックを取得
        '----------------------------------------
        ret = AioGetAiSamplingClock(Form1.g_id, ai_sampling_clock)
        '----------------------------------------
        ' 異常終了の処理
        '----------------------------------------
        If (ret <> 0) Then
            If (ret <> 20001) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                message_string = String.Format("AioGetAiSamplingClock = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                err_flag = 1
            Else
                '--------------------
                ' コントロールを無効に設定
                '--------------------
                TextBox_SamplingClock.Enabled = FALSE
            End If
            '--------------------
            ' サンプリングクロックの初期表示を更新
            '--------------------
            TextBox_SamplingClock.Text = "1000"
        '----------------------------------------
        ' 正常終了の処理
        '----------------------------------------
        Else
            '--------------------
            ' サンプリングクロックを更新
            '--------------------
            TextBox_SamplingClock.Text = Convert.ToDouble(ai_sampling_clock).ToString("F6")
        End If
        '----------------------------------------
        ' アナログ入力外部クロック入力タイミング用コンボボックスの作成
        '----------------------------------------
        ComboBox_ExternalClockInputTiming.Items.Add("立ち下がりエッジ")
        ComboBox_ExternalClockInputTiming.Items.Add("立ち上がりエッジ")
        '----------------------------------------
        ' 外部クロックの場合
        '----------------------------------------
        If (ai_clock_type = 1) Then
            '----------------------------------------
            ' 外部クロックの入力タイミングを取得
            '----------------------------------------
            ret = AioGetAiClockEdge(Form1.g_id, ai_clock_edge)
            '----------------------------------------
            ' 異常終了の処理
            '----------------------------------------
            If (ret <> 0) Then
                If (ret <> 20001) Then
                    '--------------------
                    ' エラー文字列取得
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' メッセージ表示
                    '--------------------
                    message_string = String.Format("AioGetAiClockEdge = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                    err_flag = 1
                Else
                    '--------------------
                    ' コントロールを無効に設定
                    '--------------------
                    ComboBox_ExternalClockInputTiming.Enabled = FALSE
                End If
                '----------------------------------------
                ' アナログ入力外部クロック入力タイミング用コンボボックスの選択を0番に変更
                '----------------------------------------
                ComboBox_ExternalClockInputTiming.SelectedIndex = 0
            '----------------------------------------
            ' 正常終了の処理
            '----------------------------------------
            Else
                '--------------------
                ' 入力タイミングからインデックスに変換
                '--------------------
                index = 0
                Select Case ai_clock_edge
                    Case 0
                        index = 0
                    Case 1
                        index = 1
                    Case Else
                        index = 0
                End Select
                '----------------------------------------
                ' アナログ入力外部クロック入力タイミング用コンボボックスの選択を変更
                '----------------------------------------
                ComboBox_ExternalClockInputTiming.SelectedIndex = index
            End If
        '----------------------------------------
        ' 外部クロック以外の場合
        '----------------------------------------
        Else
            '----------------------------------------
            ' アナログ入力外部クロック入力タイミング用コンボボックスの選択を0番に変更
            '----------------------------------------
            ComboBox_ExternalClockInputTiming.SelectedIndex = 0
        End If
        '----------------------------------------
        ' 転送サイズを取得
        '----------------------------------------
        ret = AioGetAiTransferSize(Form1.g_id, ai_auto_mode, ai_transfer_size)
        '----------------------------------------
        ' 異常終了の処理
        '----------------------------------------
        If (ret <> 0) Then
            If (ret <> 20001) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                message_string = String.Format("AioGetAiTransferSize = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                err_flag = 1
            Else
                '--------------------
                ' コントロールを無効に設定
                '--------------------
                TextBox_TransferSize.Enabled = FALSE
            End If
            '--------------------
            ' 転送サイズの初期表示を更新
            '--------------------
            TextBox_TransferSize.Text = "0"
        '----------------------------------------
        ' 正常終了の処理
        '----------------------------------------
        Else
            '--------------------
            ' 転送サイズを更新
            '--------------------
            TextBox_TransferSize.Text = ai_transfer_size.ToString()
        End If
        '----------------------------------------
        ' 変換速度を取得
        '----------------------------------------
        ret = AioGetAiScanClock(Form1.g_id, ai_scan_clock)
        '----------------------------------------
        ' 異常終了の処理
        '----------------------------------------
        If (ret <> 0) Then
            If (ret <> 20001) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                message_string = String.Format("AioGetAiScanClock = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                err_flag = 1
            Else
                '--------------------
                ' コントロールを無効に設定
                '--------------------
                TextBox_ScanClock.Enabled = FALSE
            End If
            '--------------------
            ' 変換速度の初期表示を更新
            '--------------------
            TextBox_ScanClock.Text = "10"
        '----------------------------------------
        ' 正常終了の処理
        '----------------------------------------
        Else
            '--------------------
            ' 変換速度の初期表示を更新
            '--------------------
            TextBox_ScanClock.Text = ai_scan_clock.ToString()
        End If
        '----------------------------------------
        ' アナログ入力変換停止条件用コンボボックスの作成
        '----------------------------------------
        ComboBox_StopCondition.Items.Add("外部トリガ立ち上がり")
        ComboBox_StopCondition.Items.Add("外部トリガ立ち下がり")
        ComboBox_StopCondition.Items.Add("レベル比較")
        ComboBox_StopCondition.Items.Add("コマンド（AioStopAi）")
        ComboBox_StopCondition.Items.Add("インレンジ比較")
        ComboBox_StopCondition.Items.Add("アウトレンジ比較")
        '----------------------------------------
        ' アナログ入力変換停止条件を取得
        '----------------------------------------
        ret = AioGetAiStopTrigger(Form1.g_id, ai_stop_trigger)
        '----------------------------------------
        ' 異常終了の処理
        '----------------------------------------
        If (ret <> 0) Then
            If (ret <> 20001) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                message_string = String.Format("AioGetAiStopTrigger = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                err_flag = 1
            Else
                '--------------------
                ' コントロールを無効に設定
                '--------------------
                ComboBox_StopCondition.Enabled = FALSE
            End If
            '--------------------
            ' アナログ入力変換停止条件用コンボボックスの選択を3番に変更
            '--------------------
            ComboBox_StopCondition.SelectedIndex = 3
            ComboBox_StopCondition_SelectedIndexChanged(New Object(), New EventArgs())
        '----------------------------------------
        ' 正常終了の処理
        '----------------------------------------
        Else
            '--------------------
            ' 変換停止条件からインデックスに変換
            '--------------------
            index = 0
            Select Case ai_stop_trigger
                Case 0
                    index = 3
                Case 1
                    index = 0
                Case 2
                    index = 1
                Case 3
                    index = 2
                Case 4
                    index = 3
                Case 5
                    index = 4
                Case 6
                    index = 5
                Case Else
                    index = 3
            End Select
            '--------------------
            ' アナログ入力変換停止条件用コンボボックスの選択を変更
            '--------------------
            ComboBox_StopCondition.SelectedIndex = index
            ComboBox_StopCondition_SelectedIndexChanged(New Object(), New EventArgs())
        End If
        '----------------------------------------
        ' チャネル番号の初期表示を更新
        '----------------------------------------
        TextBox_StopLevelChNo.Text = "0"
        '----------------------------------------
        ' レベル比較方向用コンボボックスの作成
        '----------------------------------------
        ComboBox_StopLevelComprionDriection.Items.Add("両方")
        ComboBox_StopLevelComprionDriection.Items.Add("立ち上がり")
        ComboBox_StopLevelComprionDriection.Items.Add("立ち下がり")
        '----------------------------------------
        ' レベル比較の場合
        '----------------------------------------
        If (ai_stop_trigger = 3) Then
            '----------------------------------------
            ' レベル比較停止時のレベルを取得
            '----------------------------------------
            ret = AioGetAiStopLevelEx(Form1.g_id, 0, ai_level, ai_direction)
            '----------------------------------------
            ' 異常終了の処理
            '----------------------------------------
            If (ret <> 0) Then
                If (ret <> 20001) Then
                    '--------------------
                    ' エラー文字列取得
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' メッセージ表示
                    '--------------------
                    message_string = String.Format("AioGetAiStopLevelEx = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                    err_flag = 1
                Else
                    '--------------------
                    ' コントロールを無効に設定
                    '--------------------
                    TextBox_StopLevelChNo.Enabled = FALSE
                    TextBox_StopLevelComprionValue.Enabled = FALSE
                    ComboBox_StopLevelComprionDriection.Enabled = FALSE
                End If
                '--------------------
                ' 比較値の初期表示を更新
                '--------------------
                TextBox_StopLevelComprionValue.Text = "1.0"
                '--------------------
                ' レベル比較方向用コンボボックスの選択を0番に変更
                '--------------------
                ComboBox_StopLevelComprionDriection.SelectedIndex = 0
            '----------------------------------------
            ' 正常終了の処理
            '----------------------------------------
            Else
                '--------------------
                ' 比較値を更新
                '--------------------
                TextBox_StopLevelComprionValue.Text = ai_level.ToString("F1")
                '--------------------
                ' レベル比較方向からインデックスに変換
                '--------------------
                index = 0
                Select Case ai_direction
                    Case 0
                        index = 0
                    Case 1
                        index = 1
                    Case 2
                        index = 2
                    Case Else
                        index = 0
                End Select
                '--------------------
                ' レベル比較方向用コンボボックスの選択を変更
                '--------------------
                ComboBox_StopLevelComprionDriection.SelectedIndex = index
            End If
        '----------------------------------------
        ' レベル比較以外の場合
        '----------------------------------------
        Else
            '--------------------
            ' 比較値の初期表示を更新
            '--------------------
            TextBox_StopLevelComprionValue.Text = "1.0"
            '--------------------
            ' レベル比較方向用コンボボックスの選択を0番に変更
            '--------------------
            ComboBox_StopLevelComprionDriection.SelectedIndex = 0
        End If
        '----------------------------------------
        ' チャネル番号の初期表示を更新
        '----------------------------------------
        TextBox_StopRangeChNo.Text = "0"
        '----------------------------------------
        ' インレンジ比較の場合
        '----------------------------------------
        If (ai_stop_trigger = 5) Then
            '----------------------------------------
            ' インレンジ比較停止条件の設定値を取得
            '----------------------------------------
            ret = AioGetAiStopInRangeEx(Form1.g_id, 0, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' 異常終了の処理
            '----------------------------------------
            If (ret <> 0) Then
                If (ret <> 20001) Then
                    '--------------------
                    ' エラー文字列取得
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' メッセージ表示
                    '--------------------
                    message_string = String.Format("AioGetAiStopInRangeEx = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                    err_flag = 1
                Else
                    '--------------------
                    ' コントロールを無効に設定
                    '--------------------
                    TextBox_StopRangeChNo.Enabled = FALSE
                    TextBox_StopRangeUpperLimitValue.Enabled = FALSE
                    TextBox_StopRangeLowerLimitValue.Enabled = FALSE
                    TextBox_StopRangeStateTimes.Enabled = FALSE
                End If
                '--------------------
                ' 上限値の初期表示を更新
                '--------------------
                TextBox_StopRangeUpperLimitValue.Text = "10.0"
                '--------------------
                ' 下限値の初期表示を更新
                '--------------------
                TextBox_StopRangeLowerLimitValue.Text = "1.0"
                '--------------------
                ' 保持回数の初期表示を更新
                '--------------------
                TextBox_StopRangeStateTimes.Text = "1"
            '----------------------------------------
            ' 正常終了の処理
            '----------------------------------------
            Else
                '--------------------
                ' 上限値を更新
                '--------------------
                TextBox_StopRangeUpperLimitValue.Text = ai_range_level1.ToString("F1")
                '--------------------
                ' 下限値を更新
                '--------------------
                TextBox_StopRangeLowerLimitValue.Text = ai_range_level2.ToString("F1")
                '--------------------
                ' 保持回数を更新
                '--------------------
                TextBox_StopRangeStateTimes.Text = ai_state_times.ToString()
            End If
        '----------------------------------------
        ' アウトレンジ比較の場合
        '----------------------------------------
        ElseIf (ai_stop_trigger = 6) Then
            '----------------------------------------
            ' アウトレンジ比較停止条件の設定値を取得
            '----------------------------------------
            ret = AioGetAiStopOutRangeEx(Form1.g_id, 0, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' 異常終了の処理
            '----------------------------------------
            If (ret <> 0) Then
                If (ret <> 20001) Then
                    '--------------------
                    ' エラー文字列取得
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' メッセージ表示
                    '--------------------
                    message_string = String.Format("AioGetAiStopOutRangeEx = {0:D} : {1}{2}{3}※エラーが発生したため表示を更新できませんでした。", ret, error_string, vbCrLf, vbCrLf)
                    err_flag = 1
                Else
                    '--------------------
                    ' コントロールを無効に設定
                    '--------------------
                    TextBox_StopRangeChNo.Enabled = FALSE
                    TextBox_StopRangeUpperLimitValue.Enabled = FALSE
                    TextBox_StopRangeLowerLimitValue.Enabled = FALSE
                    TextBox_StopRangeStateTimes.Enabled = FALSE
                End If
                '--------------------
                ' 上限値の初期表示を更新
                '--------------------
                TextBox_StopRangeUpperLimitValue.Text = "10.0"
                '--------------------
                ' 下限値の初期表示を更新
                '--------------------
                TextBox_StopRangeLowerLimitValue.Text = "1.0"
                '--------------------
                ' 保持回数の初期表示を更新
                '--------------------
                TextBox_StopRangeStateTimes.Text = "1"
            '----------------------------------------
            ' 正常終了の処理
            '----------------------------------------
            Else
                '--------------------
                ' 上限値を更新
                '--------------------
                TextBox_StopRangeUpperLimitValue.Text = ai_range_level1.ToString("F1")
                '--------------------
                ' 下限値を更新
                '--------------------
                TextBox_StopRangeLowerLimitValue.Text = ai_range_level2.ToString("F1")
                '--------------------
                ' 保持回数を更新
                '--------------------
                TextBox_StopRangeStateTimes.Text = ai_state_times.ToString()
            End If
        '----------------------------------------
        ' インレンジ比較/アウトレンジ比較以外の場合
        '----------------------------------------
        Else
            '--------------------
            ' 上限値の初期表示を更新
            '--------------------
            TextBox_StopRangeUpperLimitValue.Text = "10.0"
            '--------------------
            ' 下限値の初期表示を更新
            '--------------------
            TextBox_StopRangeLowerLimitValue.Text = "1.0"
            '--------------------
            ' 保持回数の初期表示を更新
            '--------------------
            TextBox_StopRangeStateTimes.Text = "1"
        End If
        '----------------------------------------
        ' エラーが発生していた場合メッセージを表示
        '----------------------------------------
        If (err_flag <> 0) Then
            MessageBox.Show(message_string, "エラー", MessageBoxButtons.OK)
        End If
    End Sub

    '================================================================================
    ' 開始条件コンボボックスのインデックスが変更された際の処理になります
    ' 使用可能コントロールを更新します
    '================================================================================
    Private Sub ComboBox_StartCondition_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_StartCondition.SelectedIndexChanged
        Dim index As Integer    ' コンボボックスのインデックス

        '----------------------------------------
        ' コンボボックスから開始条件のインデックスを取得
        '----------------------------------------
        index = ComboBox_StartCondition.SelectedIndex
        '----------------------------------------
        ' 開始条件による分岐処理
        '----------------------------------------
        Select Case g_start_trigger(index)
            Case 0, 1, 2    ' ソフトウェア, 外部トリガ立ち上がり, 外部トリガ立ち下がり
                TextBox_StartLevelChNo.Enabled = False
                TextBox_StartLevelComprionValue.Enabled = False
                ComboBox_StartLevelComprionDriection.Enabled = False
                TextBox_StartRangeChNo.Enabled = False
                TextBox_StartRangeUpperLimitValue.Enabled = False
                TextBox_StartRangeLowerLimitValue.Enabled = False
                TextBox_StartRangeStateTimes.Enabled = False
            Case 3    ' レベル比較
                TextBox_StartLevelChNo.Enabled = True
                TextBox_StartLevelComprionValue.Enabled = True
                ComboBox_StartLevelComprionDriection.Enabled = True
                TextBox_StartRangeChNo.Enabled = False
                TextBox_StartRangeUpperLimitValue.Enabled = False
                TextBox_StartRangeLowerLimitValue.Enabled = False
                TextBox_StartRangeStateTimes.Enabled = False
            Case 4, 5    ' インレンジ比較, アウトレンジ比較
                TextBox_StartLevelChNo.Enabled = False
                TextBox_StartLevelComprionValue.Enabled = False
                ComboBox_StartLevelComprionDriection.Enabled = False
                TextBox_StartRangeChNo.Enabled = True
                TextBox_StartRangeUpperLimitValue.Enabled = True
                TextBox_StartRangeLowerLimitValue.Enabled = True
                TextBox_StartRangeStateTimes.Enabled = True
            Case Else
                TextBox_StartLevelChNo.Enabled = False
                TextBox_StartLevelComprionValue.Enabled = False
                ComboBox_StartLevelComprionDriection.Enabled = False
                TextBox_StartRangeChNo.Enabled = False
                TextBox_StartRangeUpperLimitValue.Enabled = False
                TextBox_StartRangeLowerLimitValue.Enabled = False
                TextBox_StartRangeStateTimes.Enabled = False
        End Select
    End Sub

    '================================================================================
    ' クロック種類コンボボックスのインデックスが変更された際の処理になります
    ' 使用可能コントロールを更新します
    '================================================================================
    Private Sub ComboBox_ClockType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_ClockType.SelectedIndexChanged
        Dim index As Integer            ' コンボボックスのインデックス
        Dim ret As Integer              ' 戻り値
        Dim auto_mode As Integer        ' 転送サイズの設定モード
        Dim transfer_size As Integer    ' 転送サイズ

        '----------------------------------------
        ' コンボボックスからクロック種類のインデックスを取得
        '----------------------------------------
        index = ComboBox_ClockType.SelectedIndex
        '----------------------------------------
        ' クロック種類による分岐処理
        '----------------------------------------
        Select Case g_clock_type(index)
            Case 0    ' 内部クロック
                TextBox_SamplingClock.Enabled = True
                ComboBox_ExternalClockInputTiming.Enabled = False
                TextBox_TransferSize.Enabled = False
            Case 1    ' 外部クロック
                TextBox_SamplingClock.Enabled = False
                ComboBox_ExternalClockInputTiming.Enabled = True
                '----------------------------------------
                ' 転送サイズを取得
                '----------------------------------------
                ret = AioGetAiTransferSize(Form1.g_id, auto_mode, transfer_size)
                '----------------------------------------
                ' 異常終了の処理
                '----------------------------------------
                If (ret <> 0) Then
                    TextBox_TransferSize.Enabled = False
                '----------------------------------------
                ' 正常終了の処理
                '----------------------------------------
                Else
                    TextBox_TransferSize.Enabled = True
                End If
            Case Else
                TextBox_SamplingClock.Enabled = True
                ComboBox_ExternalClockInputTiming.Enabled = False
                TextBox_TransferSize.Enabled = False
        End Select
    End Sub

    '================================================================================
    ' 停止条件コンボボックスのインデックスが変更された際の処理になります
    ' 使用可能コントロールを更新します
    '================================================================================
    Private Sub ComboBox_StopCondition_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_StopCondition.SelectedIndexChanged
        Dim index As Integer    ' コンボボックスのインデックス

        '----------------------------------------
        ' コンボボックスから停止条件のインデックスを取得
        '----------------------------------------
        index = ComboBox_StopCondition.SelectedIndex
        '----------------------------------------
        ' 停止条件による分岐処理
        '----------------------------------------
        Select Case g_stop_trigger(index)
            Case 1, 2, 4    ' 外部トリガ立ち上がり, 外部トリガ立ち下がり, コマンド（AioStopAi）
                TextBox_StopLevelChNo.Enabled = False
                TextBox_StopLevelComprionValue.Enabled = False
                ComboBox_StopLevelComprionDriection.Enabled = False
                TextBox_StopRangeChNo.Enabled = False
                TextBox_StopRangeUpperLimitValue.Enabled = False
                TextBox_StopRangeLowerLimitValue.Enabled = False
                TextBox_StopRangeStateTimes.Enabled = False
            Case 3    ' レベル比較
                TextBox_StopLevelChNo.Enabled = True
                TextBox_StopLevelComprionValue.Enabled = True
                ComboBox_StopLevelComprionDriection.Enabled = True
                TextBox_StopRangeChNo.Enabled = False
                TextBox_StopRangeUpperLimitValue.Enabled = False
                TextBox_StopRangeLowerLimitValue.Enabled = False
                TextBox_StopRangeStateTimes.Enabled = False
            Case 5, 6    ' インレンジ比較, アウトレンジ比較
                TextBox_StopLevelChNo.Enabled = False
                TextBox_StopLevelComprionValue.Enabled = False
                ComboBox_StopLevelComprionDriection.Enabled = False
                TextBox_StopRangeChNo.Enabled = True
                TextBox_StopRangeUpperLimitValue.Enabled = True
                TextBox_StopRangeLowerLimitValue.Enabled = True
                TextBox_StopRangeStateTimes.Enabled = True
            Case Else
                TextBox_StopLevelChNo.Enabled = False
                TextBox_StopLevelComprionValue.Enabled = False
                ComboBox_StopLevelComprionDriection.Enabled = False
                TextBox_StopRangeChNo.Enabled = False
                TextBox_StopRangeUpperLimitValue.Enabled = False
                TextBox_StopRangeLowerLimitValue.Enabled = False
                TextBox_StopRangeStateTimes.Enabled = False
        End Select
    End Sub

    '================================================================================
    ' OKボタンをクリックした際の処理になります
    ' サンプリング条件の設定を行います
    '================================================================================
    Private Sub Button_Ok_Click(sender As Object, e As EventArgs) Handles Button_Ok.Click
        Dim error_string As New StringBuilder("", 256)    ' エラーコード文字列
        Dim text_string As String                         ' テキストボックス更新用
        Dim ret As Integer                                ' 戻り値取得用
        Dim index As Integer                              ' コンボボックスのインデックス
        Dim ai_level_channel As Short                     ' レベル比較チャネル
        Dim ai_level As Single                            ' レベル比較データ
        Dim ai_direction As Short                         ' レベル比較の方向
        Dim ai_range_channel As Short                     ' インレンジ/アウトレンジ比較チャネル
        Dim ai_range_level1 As Single                     ' インレンジ/アウトレンジ比較データの上限値
        Dim ai_range_level2 As Single                     ' インレンジ/アウトレンジ比較データの下限値
        Dim ai_state_times As Integer                     ' 状態保持サンプリング回数
        Dim ai_sampling_clock As Single                   ' サンプリングクロック
        Dim ai_scan_clock As Single                       ' 変換速度
        Dim ai_transfer_size As Integer                   ' 転送サイズ

        '----------------------------------------
        ' データ格納用メモリ形式をメモリへの上書きありに設定
        ' 変更要注意関数(変更するとアプリが動作しなくなる可能性があります)
        '----------------------------------------
        ret = AioSetAiMemoryType(Form1.g_id, 1)
        '----------------------------------------
        ' エラー処理
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' エラー文字列取得
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' メッセージ表示
            '--------------------
            text_string = String.Format("AioSetAiMemoryType = {0:D} : {1}", ret, error_string)
            MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
            Exit Sub
        End If
        '----------------------------------------
        ' コンボボックスから変換開始条件設定値のインデックスを取得
        '----------------------------------------
        index = ComboBox_StartCondition.SelectedIndex
        '----------------------------------------
        ' アナログ入力変換開始条件の設定
        '----------------------------------------
        ret = AioSetAiStartTrigger(Form1.g_id, g_start_trigger(index))
        '----------------------------------------
        ' エラー処理
        '----------------------------------------
        '--------------------
        ' 正常終了でなければ処理を抜ける
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' エラー文字列取得
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' メッセージ表示
            '--------------------
            text_string = String.Format("AioSetAiStartTrigger = {0:D} : {1}", ret, error_string)
            MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
            Exit Sub
        End If
        '----------------------------------------
        ' レベル比較の場合
        '----------------------------------------
        If (g_start_trigger(index) = 3) Then
            '----------------------------------------
            ' テキストボックスからレベル比較チャネルを取得
            '----------------------------------------
            If (Short.TryParse(TextBox_StartLevelChNo.Text, ai_level_channel) = False) Then
                ai_level_channel = 0
            End If
            '----------------------------------------
            ' テキストボックスからレベル比較データを取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StartLevelComprionValue.Text, ai_level) = False) Then
                ai_level = -10
            End If
            '----------------------------------------
            ' コンボボックスからレベル比較の方向を取得
            '----------------------------------------
            ai_direction = ComboBox_StartLevelComprionDriection.SelectedIndex
            '----------------------------------------
            ' レベル比較開始時のレベルを設定
            '----------------------------------------
            ret = AioSetAiStartLevelEx(Form1.g_id, ai_level_channel, ai_level, ai_direction)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiStartLevelEx = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        '----------------------------------------
        ' インレンジ比較の場合
        '----------------------------------------
        ElseIf (g_start_trigger(index) = 4) Then
            '----------------------------------------
            ' テキストボックスからインレンジ比較チャネルを取得
            '----------------------------------------
            If (Short.TryParse(TextBox_StartRangeChNo.Text, ai_range_channel) = False) Then
                ai_range_channel = 0
            End If
            '----------------------------------------
            ' テキストボックスから上限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StartRangeUpperLimitValue.Text, ai_range_level1) = False) Then
                ai_range_level1 = 10
            End If
            '----------------------------------------
            ' テキストボックスから下限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StartRangeLowerLimitValue.Text, ai_range_level2) = False) Then
                ai_range_level2 = 1
            End If
            '----------------------------------------
            ' テキストボックスから保持回数を取得
            '----------------------------------------
            If (Integer.TryParse(TextBox_StartRangeStateTimes.Text, ai_state_times) = False) Then
                ai_state_times = 1
            End If
            '----------------------------------------
            ' インレンジ比較開始条件の設定を行う
            '----------------------------------------
            ret = AioSetAiStartInRangeEx(Form1.g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiStartInRangeEx = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        '----------------------------------------
        ' アウトレンジ比較の場合
        '----------------------------------------
        ElseIf (g_start_trigger(index) = 5) Then
            '----------------------------------------
            ' テキストボックスからアウトレンジ比較チャネルを取得
            '----------------------------------------
            If (Short.TryParse(TextBox_StartRangeChNo.Text, ai_range_channel) = False) Then
                ai_range_channel = 0
            End If
            '----------------------------------------
            ' テキストボックスから上限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StartRangeUpperLimitValue.Text, ai_range_level1) = False) Then
                ai_range_level1 = 10
            End If
            '----------------------------------------
            ' テキストボックスから下限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StartRangeLowerLimitValue.Text, ai_range_level2) = False) Then
                ai_range_level2 = 1
            End If
            '----------------------------------------
            ' テキストボックスから保持回数を取得
            '----------------------------------------
            If (Integer.TryParse(TextBox_StartRangeStateTimes.Text, ai_state_times) = False) Then
                ai_state_times = 1
            End If
            '----------------------------------------
            ' アウトレンジ比較開始条件の設定を行う
            '----------------------------------------
            ret = AioSetAiStartOutRangeEx(Form1.g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiStartOutRangeEx = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        End If
        '----------------------------------------
        ' コンボボックスからクロック種類設定値のインデックスを取得
        '----------------------------------------
        index = ComboBox_ClockType.SelectedIndex
        '----------------------------------------
        ' アナログ入力クロック種類の設定
        '----------------------------------------
        ret = AioSetAiClockType(Form1.g_id, g_clock_type(index))
        '----------------------------------------
        ' エラー処理
        '----------------------------------------
        '--------------------
        ' 正常終了でなければ処理を抜ける
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' エラー文字列取得
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' メッセージ表示
            '--------------------
            text_string = String.Format("AioSetAiClockType = {0:D} : {1}", ret, error_string)
            MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
            Exit Sub
        End If
        '----------------------------------------
        ' 内部クロックの場合
        '----------------------------------------
        If (g_clock_type(index) = 0) Then
            '----------------------------------------
            ' テキストボックスからサンプリングクロックを取得
            '----------------------------------------
            If (Single.TryParse(TextBox_SamplingClock.Text, ai_sampling_clock) = False) Then
                ai_sampling_clock = 1000
            End If
            '----------------------------------------
            ' アナログ入力サンプリングクロックの設定
            '----------------------------------------
            ret = AioSetAiSamplingClock(Form1.g_id, ai_sampling_clock)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiSamplingClock = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
            '----------------------------------------
            ' アナログ入力転送サイズの設定
            '----------------------------------------
            ret = AioSetAiTransferSize(Form1.g_id, AI_TRANSFERSIZE_AUTO, 0)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなくかつ使用不可でもなければ処理を抜ける
            '--------------------
            If ((ret <> 0) And (ret <> 20001)) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiTransferSize = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        '----------------------------------------
        ' 外部クロックの場合
        '----------------------------------------
        ElseIf (g_clock_type(index) = 1) Then
            '----------------------------------------
            ' コンボボックスから外部クロック入力タイミング設定値のインデックスを取得
            '----------------------------------------
            index = ComboBox_ExternalClockInputTiming.SelectedIndex
            '----------------------------------------
            ' 外部クロックの入力タイミングの設定
            '----------------------------------------
            ret = AioSetAiClockEdge(Form1.g_id, g_clock_edge(index))
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなくかつ使用不可でもなければ処理を抜ける
            '--------------------
            If ((ret <> 0) And (ret <> 20001)) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiClockEdge = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
            '----------------------------------------
            ' テキストボックスから転送サイズを取得
            '----------------------------------------
            If (Integer.TryParse(TextBox_TransferSize.Text, ai_transfer_size) = False) Then
                ai_transfer_size = 1
            End If
            '----------------------------------------
            ' アナログ入力転送サイズの設定
            '----------------------------------------
            ret = AioSetAiTransferSize(Form1.g_id, AI_TRANSFERSIZE_MANUAL, ai_transfer_size)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなくかつ使用不可でもなければ処理を抜ける
            '--------------------
            If ((ret <> 0) And (ret <> 20001)) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiTransferSize = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        End If
        '----------------------------------------
        ' 変換速度機能が使用可能な場合
        '----------------------------------------
        If (TextBox_ScanClock.Enabled <> False) Then
            '----------------------------------------
            ' テキストボックスから変換速度を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_ScanClock.Text, ai_scan_clock) = False) Then
                ai_scan_clock = 2
            End If
            '----------------------------------------
            ' アナログ入力変換速度の設定
            '----------------------------------------
            ret = AioSetAiScanClock(Form1.g_id, ai_scan_clock)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiScanClock = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        End If
        '----------------------------------------
        ' コンボボックスから変換停止条件設定値のインデックスを取得
        '----------------------------------------
        index = ComboBox_StopCondition.SelectedIndex
        '----------------------------------------
        ' アナログ入力変換停止条件の設定
        '----------------------------------------
        ret = AioSetAiStopTrigger(Form1.g_id, g_stop_trigger(index))
        '----------------------------------------
        ' エラー処理
        '----------------------------------------
        '--------------------
        ' 正常終了でなければ処理を抜ける
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' エラー文字列取得
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' メッセージ表示
            '--------------------
            text_string = String.Format("AioSetAiStopTrigger = {0:D} : {1}", ret, error_string)
            MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
            Exit Sub
        End If
        '----------------------------------------
        ' レベル比較の場合
        '----------------------------------------
        If (g_stop_trigger(index) = 3) Then
            '----------------------------------------
            ' テキストボックスからレベル比較チャネルを取得
            '----------------------------------------
            If (Short.TryParse(TextBox_StopLevelChNo.Text, ai_level_channel) = False) Then
                ai_level_channel = 0
            End If
            '----------------------------------------
            ' テキストボックスからレベル比較データを取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StopLevelComprionValue.Text, ai_level) = False) Then
                ai_level = -10
            End If
            '----------------------------------------
            ' コンボボックスからレベル比較の方向を取得
            '----------------------------------------
            ai_direction = ComboBox_StopLevelComprionDriection.SelectedIndex
            '----------------------------------------
            ' レベル比較停止時のレベルを設定
            '----------------------------------------
            ret = AioSetAiStopLevelEx(Form1.g_id, ai_level_channel, ai_level, ai_direction)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiStopLevelEx = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        '----------------------------------------
        ' インレンジ比較の場合
        '----------------------------------------
        ElseIf (g_stop_trigger(index) = 5) Then
            '----------------------------------------
            ' テキストボックスからインレンジ比較チャネルを取得
            '----------------------------------------
            If (Short.TryParse(TextBox_StopRangeChNo.Text, ai_range_channel) = False) Then
                ai_range_channel = 0
            End If
            '----------------------------------------
            ' テキストボックスから上限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StopRangeUpperLimitValue.Text, ai_range_level1) = False) Then
                ai_range_level1 = 10
            End If
            '----------------------------------------
            ' テキストボックスから下限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StopRangeLowerLimitValue.Text, ai_range_level2) = False) Then
                ai_range_level2 = 1
            End If
            '----------------------------------------
            ' テキストボックスから保持回数を取得
            '----------------------------------------
            If (Integer.TryParse(TextBox_StopRangeStateTimes.Text, ai_state_times) = False) Then
                ai_state_times = 1
            End If
            '----------------------------------------
            ' インレンジ比較停止条件の設定を行う
            '----------------------------------------
            ret = AioSetAiStopInRangeEx(Form1.g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiStopInRangeEx = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        '----------------------------------------
        ' アウトレンジ比較の場合
        '----------------------------------------
        ElseIf (g_stop_trigger(index) = 6) Then
            '----------------------------------------
            ' テキストボックスからアウトレンジ比較チャネルを取得
            '----------------------------------------
            If (Short.TryParse(TextBox_StopRangeChNo.Text, ai_range_channel) = False) Then
                ai_range_channel = 0
            End If
            '----------------------------------------
            ' テキストボックスから上限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StopRangeUpperLimitValue.Text, ai_range_level1) = False) Then
                ai_range_level1 = 10
            End If
            '----------------------------------------
            ' テキストボックスから下限値を取得
            '----------------------------------------
            If (Single.TryParse(TextBox_StopRangeLowerLimitValue.Text, ai_range_level2) = False) Then
                ai_range_level2 = 1
            End If
            '----------------------------------------
            ' テキストボックスから保持回数を取得
            '----------------------------------------
            If (Integer.TryParse(TextBox_StopRangeStateTimes.Text, ai_state_times) = False) Then
                ai_state_times = 1
            End If
            '----------------------------------------
            ' アウトレンジ比較停止条件の設定を行う
            '----------------------------------------
            ret = AioSetAiStopOutRangeEx(Form1.g_id, ai_range_channel, ai_range_level1, ai_range_level2, ai_state_times)
            '----------------------------------------
            ' エラー処理
            '----------------------------------------
            '--------------------
            ' 正常終了でなければ処理を抜ける
            '--------------------
            If (ret <> 0) Then
                '--------------------
                ' エラー文字列取得
                '--------------------
                AioGetErrorString(ret, error_string)
                '--------------------
                ' メッセージ表示
                '--------------------
                text_string = String.Format("AioSetAiStopOutRangeEx = {0:D} : {1}", ret, error_string)
                MessageBox.Show(text_string, "エラー", MessageBoxButtons.OK)
                Exit Sub
            End If
        End If
        '----------------------------------------
        ' OK処理
        '----------------------------------------
        Me.Close()
    End Sub

    '================================================================================
    ' Cancelボタンをクリックした際の処理になります
    ' ダイアログを終了します
    '================================================================================
    Private Sub Button_Cancel_Click(sender As Object, e As EventArgs) Handles Button_Cancel.Click
        '----------------------------------------
        ' Cancel処理
        '----------------------------------------
        Me.Close()
    End Sub
End Class