﻿Imports System.Text

Public Class frmCondition
    Inherits System.Windows.Forms.Form

#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    ' Form は dispose をオーバーライドしてコンポーネント一覧を消去します。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Windows フォーム デザイナで必要です。
    Private components As System.ComponentModel.IContainer

    ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。
    ' Windows フォーム デザイナを使って変更してください。  
    ' コード エディタは使用しないでください。
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents cboStartTrg As System.Windows.Forms.ComboBox
    Friend WithEvents cboClockTrg As System.Windows.Forms.ComboBox
    Friend WithEvents cboStopTrg As System.Windows.Forms.ComboBox
    Friend WithEvents txtCompStart As System.Windows.Forms.TextBox
    Friend WithEvents txtInternalClock As System.Windows.Forms.TextBox
    Friend WithEvents rdoStartCntNotwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents rdoStartCntwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents rdoStopCntwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents rdoStopCntNotwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents txtNumEvent As System.Windows.Forms.TextBox
    Friend WithEvents txtStopNum As System.Windows.Forms.TextBox
    Friend WithEvents txtCompStop As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Label10 = New System.Windows.Forms.Label()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.txtStopNum = New System.Windows.Forms.TextBox()
        Me.txtCompStop = New System.Windows.Forms.TextBox()
        Me.txtInternalClock = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.txtCompStart = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.cboStopTrg = New System.Windows.Forms.ComboBox()
        Me.cboClockTrg = New System.Windows.Forms.ComboBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.cboStartTrg = New System.Windows.Forms.ComboBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.rdoStartCntwithSamp = New System.Windows.Forms.RadioButton()
        Me.rdoStartCntNotwithSamp = New System.Windows.Forms.RadioButton()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.rdoStopCntwithSamp = New System.Windows.Forms.RadioButton()
        Me.rdoStopCntNotwithSamp = New System.Windows.Forms.RadioButton()
        Me.GroupBox4 = New System.Windows.Forms.GroupBox()
        Me.Label11 = New System.Windows.Forms.Label()
        Me.txtNumEvent = New System.Windows.Forms.TextBox()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label10, Me.Label9, Me.Label8, Me.Label7, Me.Label6, Me.Label5, Me.txtStopNum, Me.txtCompStop, Me.txtInternalClock, Me.Label4, Me.txtCompStart, Me.Label3, Me.Label2, Me.cboStopTrg, Me.cboClockTrg, Me.Label1, Me.cboStartTrg})
        Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(480, 136)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "サンプリング条件"
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(451, 86)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(24, 20)
        Me.Label10.TabIndex = 16
        Me.Label10.Text = "Hex"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(451, 58)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(24, 20)
        Me.Label9.TabIndex = 15
        Me.Label9.Text = "ns"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(451, 30)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(24, 20)
        Me.Label8.TabIndex = 14
        Me.Label8.Text = "Hex"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(279, 106)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(80, 20)
        Me.Label7.TabIndex = 13
        Me.Label7.Text = "停止個数："
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(279, 79)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(80, 20)
        Me.Label6.TabIndex = 12
        Me.Label6.Text = "比較値："
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(279, 52)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(79, 20)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "内部クロック："
        '
        'txtStopNum
        '
        Me.txtStopNum.Location = New System.Drawing.Point(362, 106)
        Me.txtStopNum.Name = "txtStopNum"
        Me.txtStopNum.Size = New System.Drawing.Size(88, 19)
        Me.txtStopNum.TabIndex = 10
        Me.txtStopNum.Text = "TextBox4"
        '
        'txtCompStop
        '
        Me.txtCompStop.Location = New System.Drawing.Point(362, 79)
        Me.txtCompStop.Name = "txtCompStop"
        Me.txtCompStop.Size = New System.Drawing.Size(88, 19)
        Me.txtCompStop.TabIndex = 9
        Me.txtCompStop.Text = "TextBox3"
        '
        'txtInternalClock
        '
        Me.txtInternalClock.Location = New System.Drawing.Point(362, 52)
        Me.txtInternalClock.Name = "txtInternalClock"
        Me.txtInternalClock.Size = New System.Drawing.Size(88, 19)
        Me.txtInternalClock.TabIndex = 8
        Me.txtInternalClock.Text = "TextBox2"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(279, 24)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(80, 20)
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "比較値："
        '
        'txtCompStart
        '
        Me.txtCompStart.Location = New System.Drawing.Point(362, 24)
        Me.txtCompStart.Name = "txtCompStart"
        Me.txtCompStart.Size = New System.Drawing.Size(88, 19)
        Me.txtCompStart.TabIndex = 6
        Me.txtCompStart.Text = "TextBox1"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 79)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(72, 20)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "ストップ条件："
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 52)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 20)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "クロック条件："
        '
        'cboStopTrg
        '
        Me.cboStopTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStopTrg.Location = New System.Drawing.Point(88, 79)
        Me.cboStopTrg.Name = "cboStopTrg"
        Me.cboStopTrg.Size = New System.Drawing.Size(184, 20)
        Me.cboStopTrg.TabIndex = 3
        '
        'cboClockTrg
        '
        Me.cboClockTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboClockTrg.Location = New System.Drawing.Point(88, 52)
        Me.cboClockTrg.Name = "cboClockTrg"
        Me.cboClockTrg.Size = New System.Drawing.Size(184, 20)
        Me.cboClockTrg.TabIndex = 2
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 20)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "スタート条件："
        '
        'cboStartTrg
        '
        Me.cboStartTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStartTrg.Location = New System.Drawing.Point(88, 24)
        Me.cboStartTrg.Name = "cboStartTrg"
        Me.cboStartTrg.Size = New System.Drawing.Size(184, 20)
        Me.cboStartTrg.TabIndex = 0
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdoStartCntwithSamp, Me.rdoStartCntNotwithSamp})
        Me.GroupBox2.Location = New System.Drawing.Point(8, 152)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(480, 64)
        Me.GroupBox2.TabIndex = 1
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "カウンタスタート モード"
        '
        'rdoStartCntwithSamp
        '
        Me.rdoStartCntwithSamp.Location = New System.Drawing.Point(16, 40)
        Me.rdoStartCntwithSamp.Name = "rdoStartCntwithSamp"
        Me.rdoStartCntwithSamp.Size = New System.Drawing.Size(200, 16)
        Me.rdoStartCntwithSamp.TabIndex = 1
        Me.rdoStartCntwithSamp.Text = "サンプリングと同時にカウンタスタート"
        '
        'rdoStartCntNotwithSamp
        '
        Me.rdoStartCntNotwithSamp.Location = New System.Drawing.Point(16, 16)
        Me.rdoStartCntNotwithSamp.Name = "rdoStartCntNotwithSamp"
        Me.rdoStartCntNotwithSamp.Size = New System.Drawing.Size(232, 24)
        Me.rdoStartCntNotwithSamp.TabIndex = 0
        Me.rdoStartCntNotwithSamp.Text = "サンプリングとは無関係にカウンタスタート"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdoStopCntwithSamp, Me.rdoStopCntNotwithSamp})
        Me.GroupBox3.Location = New System.Drawing.Point(8, 224)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(480, 64)
        Me.GroupBox3.TabIndex = 2
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "カウンタストップ モード"
        '
        'rdoStopCntwithSamp
        '
        Me.rdoStopCntwithSamp.Location = New System.Drawing.Point(16, 40)
        Me.rdoStopCntwithSamp.Name = "rdoStopCntwithSamp"
        Me.rdoStopCntwithSamp.Size = New System.Drawing.Size(200, 16)
        Me.rdoStopCntwithSamp.TabIndex = 1
        Me.rdoStopCntwithSamp.Text = "サンプリングと同時にカウンタストップ"
        '
        'rdoStopCntNotwithSamp
        '
        Me.rdoStopCntNotwithSamp.Location = New System.Drawing.Point(16, 16)
        Me.rdoStopCntNotwithSamp.Name = "rdoStopCntNotwithSamp"
        Me.rdoStopCntNotwithSamp.Size = New System.Drawing.Size(232, 24)
        Me.rdoStopCntNotwithSamp.TabIndex = 0
        Me.rdoStopCntNotwithSamp.Text = "サンプリングとは無関係にカウンタストップ"
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label11, Me.txtNumEvent})
        Me.GroupBox4.Location = New System.Drawing.Point(8, 296)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(480, 48)
        Me.GroupBox4.TabIndex = 3
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "転送個数イベント通知"
        '
        'Label11
        '
        Me.Label11.Location = New System.Drawing.Point(168, 24)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(112, 20)
        Me.Label11.TabIndex = 1
        Me.Label11.Text = "データ毎に通知"
        '
        'txtNumEvent
        '
        Me.txtNumEvent.Location = New System.Drawing.Point(32, 19)
        Me.txtNumEvent.Name = "txtNumEvent"
        Me.txtNumEvent.Size = New System.Drawing.Size(112, 19)
        Me.txtNumEvent.TabIndex = 0
        Me.txtNumEvent.Text = "TextBox5"
        '
        'btnCancel
        '
        Me.btnCancel.Location = New System.Drawing.Point(376, 352)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(104, 26)
        Me.btnCancel.TabIndex = 7
        Me.btnCancel.Text = "ｷｬﾝｾﾙ"
        '
        'btnOK
        '
        Me.btnOK.Location = New System.Drawing.Point(256, 352)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(104, 26)
        Me.btnOK.TabIndex = 6
        Me.btnOK.Text = "OK"
        '
        'frmCondition
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(496, 390)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.GroupBox4, Me.GroupBox3, Me.GroupBox2, Me.GroupBox1})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmCondition"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "無限サンプリング条件設定"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region


    Dim Id As Short

    Dim StartComp As Integer
    Dim StopComp As Integer

    Dim InternalClock As Integer
    Dim StopNumber As Integer
    Public Shared NumberOfData As Integer

    Dim StartCountMode As Short
    Dim StopCountMode As Short
    '===================================================
    '	ダイアログ初期化
    '===================================================
    Private Sub frmCondition_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '--------------------------------
        ' 表示初期化
        '--------------------------------

        With cboStartTrg
            .Items.Clear()
            .Items.Insert(0, "ソフトウェアスタート")
            .Items.Insert(1, "外部信号立ち上がり")
            .Items.Insert(2, "外部信号立ち下がり")
            .Items.Insert(3, "カウント一致CH0 比較レジスタ0")
            .Items.Insert(4, "カウント一致CH1 比較レジスタ0")
            .Items.Insert(5, "カウント一致CH2 比較レジスタ0")
            .Items.Insert(6, "カウント一致CH3 比較レジスタ0")
            .Items.Insert(7, "カウント一致CH0 比較レジスタ1")
            .Items.Insert(8, "カウント一致CH1 比較レジスタ1")
            .Items.Insert(9, "カウント一致CH2 比較レジスタ1")
            .Items.Insert(10, "カウント一致CH3 比較レジスタ1")
        End With

        With cboClockTrg
            .Items.Clear()
            .Items.Insert(0, "内部クロック")
            .Items.Insert(1, "外部クロック")
        End With

        With cboStopTrg
            .Items.Clear()
            .Items.Insert(0, "ソフトウェアストップ")
            .Items.Insert(1, "外部信号立ち上がり")
            .Items.Insert(2, "外部信号立ち下がり")
            .Items.Insert(3, "指定個数転送完了")
            .Items.Insert(4, "カウント一致CH0 比較レジスタ0")
            .Items.Insert(5, "カウント一致CH1 比較レジスタ0")
            .Items.Insert(6, "カウント一致CH2 比較レジスタ0")
            .Items.Insert(7, "カウント一致CH3 比較レジスタ0")
            .Items.Insert(8, "カウント一致CH0 比較レジスタ1")
            .Items.Insert(9, "カウント一致CH1 比較レジスタ1")
            .Items.Insert(10, "カウント一致CH2 比較レジスタ1")
            .Items.Insert(11, "カウント一致CH3 比較レジスタ1")
        End With

        cboStartTrg.SelectedIndex = 0
        cboClockTrg.SelectedIndex = 0
        cboStopTrg.SelectedIndex = 0

        StartComp = &H100S
        InternalClock = 100000
        StopComp = &H200S
        StopNumber = 1000
        NumberOfData = 500

        txtCompStart.Text = Hex(StartComp)
        ' 内部クロック値を符号無しで表示するため、一度16進文字例変換を経由
        txtInternalClock.Text = Convert.ToUInt32(Hex(InternalClock), 16)
        txtCompStop.Text = Hex(StopComp)
        ' 停止個数を符号無しで表示するため、一度16進文字例変換を経由
        txtStopNum.Text = Convert.ToUInt32(Hex(StopNumber), 16)
        ' 通知を行うサンプリング回数を符号無しで表示するため、一度16進文字例変換を経由
        txtNumEvent.Text = Convert.ToUInt32(Hex(NumberOfData), 16)

        StartCountMode = CNTS_START_CNT_WITH_SAMP
        StopCountMode = CNTS_STOP_CNT_WITH_SAMP


        If StartCountMode = CNTS_START_CNT_NOT_WITH_SAMP Then
            rdoStartCntNotwithSamp.Checked = True
            rdoStartCntwithSamp.Checked = False
        Else
            rdoStartCntNotwithSamp.Checked = False
            rdoStartCntwithSamp.Checked = True
        End If
        If StopCountMode = CNTS_STOP_CNT_NOT_WITH_SAMP Then
            rdoStopCntNotwithSamp.Checked = True
            rdoStopCntwithSamp.Checked = False
        Else
            rdoStopCntNotwithSamp.Checked = False
            rdoStopCntwithSamp.Checked = True
        End If

        Id = Infinite.Id

        cboStartTrg_SelectedIndexChanged(cboStartTrg, New System.EventArgs())
        cboClockTrg_SelectedIndexChanged(cboClockTrg, New System.EventArgs())
        cboStopTrg_SelectedIndexChanged(cboStopTrg, New System.EventArgs())
    End Sub

    '===================================================
    '	スタート条件設定変更
    '===================================================
    Private Sub cboStartTrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboStartTrg.SelectedIndexChanged

        Dim szBuf As New String("", 100)

        szBuf = cboStartTrg.Text
        If InStr(szBuf, "カウント一致") > 0 Then
            txtCompStart.Enabled = True
        Else
            txtCompStart.Enabled = False
        End If

    End Sub

    '===================================================
    '	クロック条件設定変更
    '===================================================
    Private Sub cboClockTrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboClockTrg.SelectedIndexChanged
        Dim szBuf As New String("", 100)

        '--------------------------------
        ' 内部クロック値の有効/無効を切り替え
        '--------------------------------
        szBuf = cboClockTrg.Text

        If StrComp(szBuf, "内部クロック") = 0 Then
            txtInternalClock.Enabled = True
        Else
            txtInternalClock.Enabled = False
        End If

    End Sub

    '===================================================
    '	ストップ条件設定変更
    '===================================================
    Private Sub cboStopTrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboStopTrg.SelectedIndexChanged
        Dim szBuf As New String("", 100)
        '--------------------------------
        ' 停止個数の有効/無効を切り替え
        '--------------------------------
        szBuf = cboStopTrg.Text
        If InStr(szBuf, "カウント一致") > 0 Then
            txtCompStop.Enabled = True
        Else
            txtCompStop.Enabled = False
        End If
        If StrComp(szBuf, "指定個数転送完了") = 0 Then
            txtStopNum.Enabled = True
        Else
            txtStopNum.Enabled = False
        End If

    End Sub

    '===================================================
    '	OKボタン処理
    '===================================================
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim error_string As New Stringbuilder("", 256)
        Dim StartTrg As Short
        Dim ClockTrg As Short
        Dim StopTrg As Short
        Dim ret As Integer
        Dim strMsg As String
        Dim CompChNo As Short
        Dim CompRegNo As Short

        '--------------------------------
        ' 表示データを取得
        '--------------------------------
        StartTrg = 0
        Select Case cboStartTrg.SelectedIndex
            Case 0
                StartTrg = CNTS_START_SOFT
            Case 1
                StartTrg = CNTS_START_EXT_RISE
            Case 2
                StartTrg = CNTS_START_EXT_FALL
            Case 3
                StartTrg = CNTS_START_CNTMATCH_CH0_REG0
            Case 4
                StartTrg = CNTS_START_CNTMATCH_CH1_REG0
            Case 5
                StartTrg = CNTS_START_CNTMATCH_CH2_REG0
            Case 6
                StartTrg = CNTS_START_CNTMATCH_CH3_REG0
            Case 7
                StartTrg = CNTS_START_CNTMATCH_CH0_REG1
            Case 8
                StartTrg = CNTS_START_CNTMATCH_CH1_REG1
            Case 9
                StartTrg = CNTS_START_CNTMATCH_CH2_REG1
            Case 10
                StartTrg = CNTS_START_CNTMATCH_CH3_REG1
        End Select
        ClockTrg = 0
        Select Case cboClockTrg.SelectedIndex
            Case 0
                ClockTrg = CNTS_CLOCK_CLOCK
            Case 1
                ClockTrg = CNTS_CLOCK_EXT_TRG
        End Select

        StopTrg = 0
        Select Case cboStopTrg.SelectedIndex
            Case 0
                StopTrg = CNTS_STOP_SOFT
            Case 1
                StopTrg = CNTS_STOP_EXT_RISE
            Case 2
                StopTrg = CNTS_STOP_EXT_FALL
            Case 3
                StopTrg = CNTS_STOP_NUM
            Case 4
                StopTrg = CNTS_STOP_CNTMATCH_CH0_REG0
            Case 5
                StopTrg = CNTS_STOP_CNTMATCH_CH1_REG0
            Case 6
                StopTrg = CNTS_STOP_CNTMATCH_CH2_REG0
            Case 7
                StopTrg = CNTS_STOP_CNTMATCH_CH3_REG0
            Case 8
                StopTrg = CNTS_STOP_CNTMATCH_CH0_REG1
            Case 9
                StopTrg = CNTS_STOP_CNTMATCH_CH1_REG1
            Case 10
                StopTrg = CNTS_STOP_CNTMATCH_CH2_REG1
            Case 11
                StopTrg = CNTS_STOP_CNTMATCH_CH3_REG1
        End Select

        If (rdoStartCntNotwithSamp.Checked = True) Then
            StartCountMode = CNTS_START_CNT_NOT_WITH_SAMP
        Else
            StartCountMode = CNTS_START_CNT_WITH_SAMP
        End If
        If (rdoStopCntNotwithSamp.Checked = True) Then
            StopCountMode = CNTS_STOP_CNT_NOT_WITH_SAMP
        Else
            StopCountMode = CNTS_STOP_CNT_WITH_SAMP
        End If
        StartComp = Val("&H" & txtCompStart.Text)
        ' 内部クロック値を符号ありで設定するため、一度16進文字例変換を経由
        InternalClock = Convert.ToInt32(Hex(Val(txtInternalClock.Text)), 16)
        StopComp = Val("&H" & txtCompStart.Text)
        ' 停止個数を符号ありで設定するため、一度16進文字例変換を経由
        StopNumber = Convert.ToInt32(Hex(Val(txtStopNum.Text)), 16)
        ' 通知を行うサンプリング回数を符号ありで設定するため、一度16進文字例変換を経由
        NumberOfData = Convert.ToInt32(Hex(Val(txtNumEvent.Text)), 16)

        '--------------------------------
        ' サンプリング条件を設定
        '--------------------------------
        ' スタンドアローン
        ret = CntSetStandAlone(Id)
        If ret <> CNT_ERR_SUCCESS Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetStandAlone : ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
            Exit Sub
        End If
        ' スタート条件設定
        ret = CntSetSamplingStartTrigger(Id, StartTrg, StartCountMode, CHANNEL_NUM)
        If ret <> CNT_ERR_SUCCESS Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetSamplingStartTrigger : ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
            Exit Sub
        End If
        CompChNo = &HFFFS
        CompRegNo = &HFFFS
        Select Case StartTrg
            Case CNTS_START_CNTMATCH_CH0_REG0
                CompChNo = 0
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH1_REG0
                CompChNo = 1
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH2_REG0
                CompChNo = 2
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH3_REG0
                CompChNo = 3
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH4_REG0
                CompChNo = 4
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH5_REG0
                CompChNo = 5
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH6_REG0
                CompChNo = 6
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH7_REG0
                CompChNo = 7
                CompRegNo = 0
            Case CNTS_START_CNTMATCH_CH0_REG1
                CompChNo = 0
                CompRegNo = 1
            Case CNTS_START_CNTMATCH_CH1_REG1
                CompChNo = 1
                CompRegNo = 1
            Case CNTS_START_CNTMATCH_CH2_REG1
                CompChNo = 2
                CompRegNo = 1
            Case CNTS_START_CNTMATCH_CH3_REG1
                CompChNo = 3
                CompRegNo = 1
            Case CNTS_START_CNTMATCH_CH4_REG1
                CompChNo = 4
                CompRegNo = 1
            Case CNTS_START_CNTMATCH_CH5_REG1
                CompChNo = 5
                CompRegNo = 1
            Case CNTS_START_CNTMATCH_CH6_REG1
                CompChNo = 6
                CompRegNo = 1
            Case CNTS_START_CNTMATCH_CH7_REG1
                CompChNo = 7
                CompRegNo = 1
        End Select
        If (CompChNo <> &HFFFS) And (CompRegNo <> &HFFFS) Then
            ret = CntNotifyCountUp(Id, CompChNo, CompRegNo, StartComp, 0)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                strMsg = String.Format("CntNotifyCountUp : ret = {0:d}: {1}", ret, error_string)
                MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
            End If
        End If

        ' クロック条件設定
        ret = CntSetSamplingClockTrigger(Id, ClockTrg)
        If ret <> CNT_ERR_SUCCESS Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntNotifyCountUp : ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
            Exit Sub
        End If
        ' 内部クロック値設定
        If ClockTrg = CNTS_CLOCK_CLOCK Then
            ret = CntSetSamplingInternalClock(Id, InternalClock, 4)
            If ret <> CNT_ERR_SUCCESS Then
                CntGetErrorString(ret, error_string)
                strMsg = String.Format("CntSetSamplingInternalClock : ret = {0:d}: {1}", ret, error_string)
                MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
                Exit Sub
            End If
        End If

        ' ストップ条件設定
        ret = CntSetSamplingStopTrigger(Id, StopTrg, StopCountMode, CHANNEL_NUM)
        If ret <> CNT_ERR_SUCCESS Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetSamplingStopTrigger : ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
            Exit Sub
        End If

        CompChNo = &HFFFS
        CompRegNo = &HFFFS
        Select Case StopTrg
            Case CNTS_STOP_CNTMATCH_CH0_REG0
                CompChNo = 0
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH1_REG0
                CompChNo = 1
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH2_REG0
                CompChNo = 2
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH3_REG0
                CompChNo = 3
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH4_REG0
                CompChNo = 4
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH5_REG0
                CompChNo = 5
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH6_REG0
                CompChNo = 6
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH7_REG0
                CompChNo = 7
                CompRegNo = 0
            Case CNTS_STOP_CNTMATCH_CH0_REG1
                CompChNo = 0
                CompRegNo = 1
            Case CNTS_STOP_CNTMATCH_CH1_REG1
                CompChNo = 1
                CompRegNo = 1
            Case CNTS_STOP_CNTMATCH_CH2_REG1
                CompChNo = 2
                CompRegNo = 1
            Case CNTS_STOP_CNTMATCH_CH3_REG1
                CompChNo = 3
                CompRegNo = 1
            Case CNTS_STOP_CNTMATCH_CH4_REG1
                CompChNo = 4
                CompRegNo = 1
            Case CNTS_STOP_CNTMATCH_CH5_REG1
                CompChNo = 5
                CompRegNo = 1
            Case CNTS_STOP_CNTMATCH_CH6_REG1
                CompChNo = 6
                CompRegNo = 1
            Case CNTS_STOP_CNTMATCH_CH7_REG1
                CompChNo = 7
                CompRegNo = 1
        End Select
        If (CompChNo <> &HFFFS) And (CompRegNo <> &HFFFS) Then
            ret = CntNotifyCountUp(Id, CompChNo, CompRegNo, StopComp, 0)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                strMsg = String.Format("CntNotifyCountUp : ret = {0:d}: {1}", ret, error_string)
                MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
            End If
        End If
        ' 停止個数設定
        If StopTrg = CNTS_STOP_NUM Then
            ret = CntSetSamplingStopNumber(Id, StopNumber)
            If ret <> CNT_ERR_SUCCESS Then
                CntGetErrorString(ret, error_string)
                strMsg = String.Format("CntSetSamplingInternalClock : ret = {0:d}: {1}", ret, error_string)
                MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
                Exit Sub
            End If
        End If
        Me.Hide()
    End Sub

    '===================================================
    '	ｷｬﾝｾﾙボタン処理
    '===================================================
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Hide()
    End Sub

    Private Sub frmCondition_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        e.Cancel = True
        Me.Hide()
    End Sub
End Class
