﻿Imports System.Text

Public Class frmCondition
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents rdoStopCntwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents rdoStopCntNotwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtStopNum As System.Windows.Forms.TextBox
    Friend WithEvents txtCompStop As System.Windows.Forms.TextBox
    Friend WithEvents txtInternalClock As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtCompStart As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents cboStopTrg As System.Windows.Forms.ComboBox
    Friend WithEvents cboClockTrg As System.Windows.Forms.ComboBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents cboStartTrg As System.Windows.Forms.ComboBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents txtNumEvent As System.Windows.Forms.TextBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents rdoStartCntwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents rdoStartCntNotwithSamp As System.Windows.Forms.RadioButton
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.rdoStopCntwithSamp = New System.Windows.Forms.RadioButton()
        Me.rdoStopCntNotwithSamp = New System.Windows.Forms.RadioButton()
        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.btnOK = New System.Windows.Forms.Button()
        Me.GroupBox4 = New System.Windows.Forms.GroupBox()
        Me.Label11 = New System.Windows.Forms.Label()
        Me.txtNumEvent = New System.Windows.Forms.TextBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.rdoStartCntwithSamp = New System.Windows.Forms.RadioButton()
        Me.rdoStartCntNotwithSamp = New System.Windows.Forms.RadioButton()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdoStopCntwithSamp, Me.rdoStopCntNotwithSamp})
        Me.GroupBox3.Location = New System.Drawing.Point(8, 263)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(528, 74)
        Me.GroupBox3.TabIndex = 10
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Counter Stop Mode"
        '
        'rdoStopCntwithSamp
        '
        Me.rdoStopCntwithSamp.Location = New System.Drawing.Point(16, 47)
        Me.rdoStopCntwithSamp.Name = "rdoStopCntwithSamp"
        Me.rdoStopCntwithSamp.Size = New System.Drawing.Size(200, 18)
        Me.rdoStopCntwithSamp.TabIndex = 1
        Me.rdoStopCntwithSamp.Text = "Stop counter when sampling stops"
        '
        'rdoStopCntNotwithSamp
        '
        Me.rdoStopCntNotwithSamp.Location = New System.Drawing.Point(16, 19)
        Me.rdoStopCntNotwithSamp.Name = "rdoStopCntNotwithSamp"
        Me.rdoStopCntNotwithSamp.Size = New System.Drawing.Size(232, 28)
        Me.rdoStopCntNotwithSamp.TabIndex = 0
        Me.rdoStopCntNotwithSamp.Text = "Stop counter regardless of sampling"
        '
        '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, 11)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(528, 159)
        Me.GroupBox1.TabIndex = 8
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Sampling Condition"
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(497, 100)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(24, 23)
        Me.Label10.TabIndex = 16
        Me.Label10.Text = "Hex"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(497, 67)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(24, 24)
        Me.Label9.TabIndex = 15
        Me.Label9.Text = "ns"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(497, 35)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(24, 23)
        Me.Label8.TabIndex = 14
        Me.Label8.Text = "Hex"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(307, 123)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(100, 24)
        Me.Label7.TabIndex = 13
        Me.Label7.Text = "Stop Number:"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(307, 92)
        Me.Label6.Name = "Label6"
        Me.Label6.TabIndex = 12
        Me.Label6.Text = "Comparison Value:"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(307, 60)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(100, 24)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "Internal Clock:"
        '
        'txtStopNum
        '
        Me.txtStopNum.Location = New System.Drawing.Point(408, 123)
        Me.txtStopNum.Name = "txtStopNum"
        Me.txtStopNum.Size = New System.Drawing.Size(88, 20)
        Me.txtStopNum.TabIndex = 10
        Me.txtStopNum.Text = "TextBox4"
        '
        'txtCompStop
        '
        Me.txtCompStop.Location = New System.Drawing.Point(408, 92)
        Me.txtCompStop.Name = "txtCompStop"
        Me.txtCompStop.Size = New System.Drawing.Size(88, 20)
        Me.txtCompStop.TabIndex = 9
        Me.txtCompStop.Text = "TextBox3"
        '
        'txtInternalClock
        '
        Me.txtInternalClock.Location = New System.Drawing.Point(408, 60)
        Me.txtInternalClock.Name = "txtInternalClock"
        Me.txtInternalClock.Size = New System.Drawing.Size(88, 20)
        Me.txtInternalClock.TabIndex = 8
        Me.txtInternalClock.Text = "TextBox2"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(307, 28)
        Me.Label4.Name = "Label4"
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "Comparison Value:"
        '
        'txtCompStart
        '
        Me.txtCompStart.Location = New System.Drawing.Point(408, 28)
        Me.txtCompStart.Name = "txtCompStart"
        Me.txtCompStart.Size = New System.Drawing.Size(88, 20)
        Me.txtCompStart.TabIndex = 6
        Me.txtCompStart.Text = "TextBox1"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 92)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(88, 23)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "Stop Condition:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 60)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(88, 24)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "Clock Condition:"
        '
        'cboStopTrg
        '
        Me.cboStopTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStopTrg.Location = New System.Drawing.Point(104, 92)
        Me.cboStopTrg.Name = "cboStopTrg"
        Me.cboStopTrg.Size = New System.Drawing.Size(200, 21)
        Me.cboStopTrg.TabIndex = 3
        '
        'cboClockTrg
        '
        Me.cboClockTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboClockTrg.Location = New System.Drawing.Point(104, 60)
        Me.cboClockTrg.Name = "cboClockTrg"
        Me.cboClockTrg.Size = New System.Drawing.Size(200, 21)
        Me.cboClockTrg.TabIndex = 2
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 28)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(88, 23)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Start Condition:"
        '
        'cboStartTrg
        '
        Me.cboStartTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStartTrg.Location = New System.Drawing.Point(104, 28)
        Me.cboStartTrg.Name = "cboStartTrg"
        Me.cboStartTrg.Size = New System.Drawing.Size(200, 21)
        Me.cboStartTrg.TabIndex = 0
        '
        'btnOK
        '
        Me.btnOK.Location = New System.Drawing.Point(300, 411)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(104, 31)
        Me.btnOK.TabIndex = 12
        Me.btnOK.Text = "OK"
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label11, Me.txtNumEvent})
        Me.GroupBox4.Location = New System.Drawing.Point(8, 346)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(528, 56)
        Me.GroupBox4.TabIndex = 11
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "Transfer Number Event Notification"
        '
        'Label11
        '
        Me.Label11.Location = New System.Drawing.Point(168, 28)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(160, 23)
        Me.Label11.TabIndex = 1
        Me.Label11.Text = "Each data notification"
        '
        'txtNumEvent
        '
        Me.txtNumEvent.Location = New System.Drawing.Point(32, 22)
        Me.txtNumEvent.Name = "txtNumEvent"
        Me.txtNumEvent.Size = New System.Drawing.Size(112, 20)
        Me.txtNumEvent.TabIndex = 0
        Me.txtNumEvent.Text = "TextBox5"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdoStartCntwithSamp, Me.rdoStartCntNotwithSamp})
        Me.GroupBox2.Location = New System.Drawing.Point(8, 179)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(528, 74)
        Me.GroupBox2.TabIndex = 9
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Counter Start Mode"
        '
        'rdoStartCntwithSamp
        '
        Me.rdoStartCntwithSamp.Location = New System.Drawing.Point(16, 47)
        Me.rdoStartCntwithSamp.Name = "rdoStartCntwithSamp"
        Me.rdoStartCntwithSamp.Size = New System.Drawing.Size(208, 18)
        Me.rdoStartCntwithSamp.TabIndex = 1
        Me.rdoStartCntwithSamp.Text = "Start counter when sampling starts"
        '
        'rdoStartCntNotwithSamp
        '
        Me.rdoStartCntNotwithSamp.Location = New System.Drawing.Point(16, 19)
        Me.rdoStartCntNotwithSamp.Name = "rdoStartCntNotwithSamp"
        Me.rdoStartCntNotwithSamp.Size = New System.Drawing.Size(232, 28)
        Me.rdoStartCntNotwithSamp.TabIndex = 0
        Me.rdoStartCntNotwithSamp.Text = "Start counter regardless of sampling"
        '
        'btnCancel
        '
        Me.btnCancel.Location = New System.Drawing.Point(420, 411)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(104, 31)
        Me.btnCancel.TabIndex = 13
        Me.btnCancel.Text = "Cancel"
        '
        'frmCondition
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(544, 453)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox3, Me.GroupBox1, Me.btnOK, Me.GroupBox4, Me.GroupBox2, Me.btnCancel})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmCondition"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Infinite Sampling Condition Setting"
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim Id As Short

    Dim StartComp As Integer
    Dim StopComp As Integer

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

    Dim StartCountMode As Short
    Dim StopCountMode As Short
    '===================================================
    '	Dialog initialization
    '===================================================
    Private Sub frmCondition_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '--------------------------------
        ' Display initialization dialog
        '--------------------------------

        With cboStartTrg
            .Items.Clear()
            .Items.Insert(0, "Software Start")
            .Items.Insert(1, "External Signal Rising")
            .Items.Insert(2, "External Signal Falling")
            .Items.Insert(3, "Count-match Ch0 Compare-register 0")
            .Items.Insert(4, "Count-match Ch1 Compare-register 0")
            .Items.Insert(5, "Count-match Ch2 Compare-register 0")
            .Items.Insert(6, "Count-match Ch3 Compare-register 0")
            .Items.Insert(7, "Count-match Ch0 Compare-register 1")
            .Items.Insert(8, "Count-match Ch1 Compare-register 1")
            .Items.Insert(9, "Count-match Ch2 Compare-register 1")
            .Items.Insert(10, "Count-match Ch3 Compare-register 1")
        End With

        With cboClockTrg
            .Items.Clear()
            .Items.Insert(0, "Internal Clock")
            .Items.Insert(1, "External Clock")
        End With

        With cboStopTrg
            .Items.Clear()
            .Items.Insert(0, "Software Stop")
            .Items.Insert(1, "External Signal Rising")
            .Items.Insert(2, "External Signal Falling")
            .Items.Insert(3, "Stop Transfer by Specified Times")
            .Items.Insert(4, "Count-match Ch0 Compare-register 0")
            .Items.Insert(5, "Count-match Ch1 Compare-register 0")
            .Items.Insert(6, "Count-match Ch2 Compare-register 0")
            .Items.Insert(7, "Count-match Ch3 Compare-register 0")
            .Items.Insert(8, "Count-match Ch0 Compare-register 1")
            .Items.Insert(9, "Count-match Ch1 Compare-register 1")
            .Items.Insert(10, "Count-match Ch2 Compare-register 1")
            .Items.Insert(11, "Count-match Ch3 Compare-register 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)
        ' In order to display the internal clock to unsigned, convert it once through hexadecimal characters
        txtInternalClock.Text = Convert.ToUInt32(Hex(InternalClock), 16)
        txtCompStop.Text = Hex(StopComp)
        ' In order to display the stop number to unsigned, convert it once through hexadecimal characters
        txtStopNum.Text = Convert.ToUInt32(Hex(StopNumber), 16)
        ' In order to display the number of sampling cycles for notification to unsigned, convert it once through hexadecimal characters
        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

    '===================================================
    '	Change start condition setting
    '===================================================
    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, "Count-match") > 0 Then
            txtCompStart.Enabled = True
        Else
            txtCompStart.Enabled = False
        End If
    End Sub

    '===================================================
    '	Change clock condition setting
    '===================================================
    Private Sub cboClockTrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboClockTrg.SelectedIndexChanged
        Dim szBuf As New String("", 100)

        '--------------------------------
        ' Change validity of internal clock value
        '--------------------------------
        szBuf = cboClockTrg.Text

        If StrComp(szBuf, "Internal Clock") = 0 Then
            txtInternalClock.Enabled = True
        Else
            txtInternalClock.Enabled = False
        End If

    End Sub

    '===================================================
    '	Change stop condition setting
    '===================================================
    Private Sub cboStopTrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboStopTrg.SelectedIndexChanged
        Dim szBuf As New String("", 100)

        '--------------------------------
        ' Change validity of stop number
        '--------------------------------
        szBuf = cboStopTrg.Text
        If InStr(szBuf, "Count-match") > 0 Then
            txtCompStop.Enabled = True
        Else
            txtCompStop.Enabled = False
        End If
        If StrComp(szBuf, "Stop Transfer by Specified Times") = 0 Then
            txtStopNum.Enabled = True
        Else
            txtStopNum.Enabled = False
        End If

    End Sub

    '===================================================
    '	OK processing
    '===================================================
    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

        '--------------------------------
        ' Get displayed data
        '--------------------------------
        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)
        ' In order to set the internal clock to signed, convert it once through hexadecimal characters
        InternalClock = Convert.ToInt32(Hex(Val(txtInternalClock.Text)), 16)
        StopComp = Val("&H" & txtCompStart.Text)
        ' In order to set the stop number to signed, convert it once through hexadecimal characters
        StopNumber = Convert.ToInt32(Hex(Val(txtStopNum.Text)), 16)
        ' In order to set the number of sampling cycles for notification to signed, convert it once through hexadecimal characters
        NumberOfData = Convert.ToInt32(Hex(Val(txtNumEvent.Text)), 16)

        '--------------------------------
        ' Set sampling condition
        '--------------------------------
        ' StandAlone
        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
        ' Set start condition
        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

        ' Set clock condition
        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
        ' Set internal clock value
        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

        ' Set stop condition
        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
        ' Set stop number
        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

    '===================================================
    '	Cancel processing
    '===================================================
    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
