﻿Imports System.Text

Public Class frmMSmpMode
    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 GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label16 As System.Windows.Forms.Label
    Friend WithEvents txtNumberData As System.Windows.Forms.TextBox
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents rdoRing As System.Windows.Forms.RadioButton
    Friend WithEvents rdoOnce As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label15 As System.Windows.Forms.Label
    Friend WithEvents Label14 As System.Windows.Forms.Label
    Friend WithEvents Label13 As System.Windows.Forms.Label
    Friend WithEvents txtStopNumber As System.Windows.Forms.TextBox
    Friend WithEvents txtCompStop As System.Windows.Forms.TextBox
    Friend WithEvents txtInternalClock As System.Windows.Forms.TextBox
    Friend WithEvents Label12 As System.Windows.Forms.Label
    Friend WithEvents Label11 As System.Windows.Forms.Label
    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 txtCompStart As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents cboStopWith As System.Windows.Forms.ComboBox
    Friend WithEvents cboStop As System.Windows.Forms.ComboBox
    Friend WithEvents cboClock As System.Windows.Forms.ComboBox
    Friend WithEvents cboStartWith As System.Windows.Forms.ComboBox
    Friend WithEvents cboStart As System.Windows.Forms.ComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.Label16 = New System.Windows.Forms.Label()
        Me.txtNumberData = New System.Windows.Forms.TextBox()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.rdoRing = New System.Windows.Forms.RadioButton()
        Me.rdoOnce = New System.Windows.Forms.RadioButton()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Label15 = New System.Windows.Forms.Label()
        Me.Label14 = New System.Windows.Forms.Label()
        Me.Label13 = New System.Windows.Forms.Label()
        Me.txtStopNumber = New System.Windows.Forms.TextBox()
        Me.txtCompStop = New System.Windows.Forms.TextBox()
        Me.txtInternalClock = New System.Windows.Forms.TextBox()
        Me.Label12 = New System.Windows.Forms.Label()
        Me.Label11 = New System.Windows.Forms.Label()
        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.txtCompStart = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.cboStopWith = New System.Windows.Forms.ComboBox()
        Me.cboStop = New System.Windows.Forms.ComboBox()
        Me.cboClock = New System.Windows.Forms.ComboBox()
        Me.cboStartWith = New System.Windows.Forms.ComboBox()
        Me.cboStart = New System.Windows.Forms.ComboBox()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label16, Me.txtNumberData})
        Me.GroupBox2.Location = New System.Drawing.Point(8, 208)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(296, 65)
        Me.GroupBox2.TabIndex = 13
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Transfer Number Event Notification"
        '
        'Label16
        '
        Me.Label16.Location = New System.Drawing.Point(40, 26)
        Me.Label16.Name = "Label16"
        Me.Label16.Size = New System.Drawing.Size(80, 18)
        Me.Label16.TabIndex = 22
        Me.Label16.Text = "Number:"
        '
        'txtNumberData
        '
        Me.txtNumberData.Location = New System.Drawing.Point(168, 26)
        Me.txtNumberData.Name = "txtNumberData"
        Me.txtNumberData.Size = New System.Drawing.Size(80, 20)
        Me.txtNumberData.TabIndex = 21
        Me.txtNumberData.Text = "TextBox5"
        '
        'btnCancel
        '
        Me.btnCancel.Location = New System.Drawing.Point(552, 283)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(112, 28)
        Me.btnCancel.TabIndex = 16
        Me.btnCancel.Text = "Cancel"
        '
        'btnOK
        '
        Me.btnOK.Location = New System.Drawing.Point(424, 283)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(112, 28)
        Me.btnOK.TabIndex = 15
        Me.btnOK.Text = "OK"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdoRing, Me.rdoOnce})
        Me.GroupBox3.Location = New System.Drawing.Point(320, 208)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(352, 65)
        Me.GroupBox3.TabIndex = 14
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Transfer Mode"
        '
        'rdoRing
        '
        Me.rdoRing.Location = New System.Drawing.Point(176, 26)
        Me.rdoRing.Name = "rdoRing"
        Me.rdoRing.Size = New System.Drawing.Size(120, 18)
        Me.rdoRing.TabIndex = 1
        Me.rdoRing.Text = "Ring"
        '
        'rdoOnce
        '
        Me.rdoOnce.Location = New System.Drawing.Point(32, 26)
        Me.rdoOnce.Name = "rdoOnce"
        Me.rdoOnce.Size = New System.Drawing.Size(112, 18)
        Me.rdoOnce.TabIndex = 0
        Me.rdoOnce.Text = "Once"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label15, Me.Label14, Me.Label13, Me.txtStopNumber, Me.txtCompStop, Me.txtInternalClock, Me.Label12, Me.Label11, Me.Label10, Me.Label9, Me.Label8, Me.Label7, Me.Label6, Me.txtCompStart, Me.Label5, Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.cboStopWith, Me.cboStop, Me.cboClock, Me.cboStartWith, Me.cboStart})
        Me.GroupBox1.Location = New System.Drawing.Point(8, 12)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(664, 186)
        Me.GroupBox1.TabIndex = 12
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Sampling Mode"
        '
        'Label15
        '
        Me.Label15.Location = New System.Drawing.Point(634, 121)
        Me.Label15.Name = "Label15"
        Me.Label15.Size = New System.Drawing.Size(24, 23)
        Me.Label15.TabIndex = 23
        Me.Label15.Text = "Hex"
        '
        'Label14
        '
        Me.Label14.Location = New System.Drawing.Point(634, 88)
        Me.Label14.Name = "Label14"
        Me.Label14.Size = New System.Drawing.Size(24, 24)
        Me.Label14.TabIndex = 22
        Me.Label14.Text = "ns"
        '
        'Label13
        '
        Me.Label13.Location = New System.Drawing.Point(634, 26)
        Me.Label13.Name = "Label13"
        Me.Label13.Size = New System.Drawing.Size(24, 23)
        Me.Label13.TabIndex = 21
        Me.Label13.Text = "Hex"
        '
        'txtStopNumber
        '
        Me.txtStopNumber.Location = New System.Drawing.Point(528, 149)
        Me.txtStopNumber.Name = "txtStopNumber"
        Me.txtStopNumber.Size = New System.Drawing.Size(104, 20)
        Me.txtStopNumber.TabIndex = 20
        Me.txtStopNumber.Text = "TextBox4"
        '
        'txtCompStop
        '
        Me.txtCompStop.Location = New System.Drawing.Point(528, 116)
        Me.txtCompStop.Name = "txtCompStop"
        Me.txtCompStop.Size = New System.Drawing.Size(104, 20)
        Me.txtCompStop.TabIndex = 19
        Me.txtCompStop.Text = "TextBox3"
        '
        'txtInternalClock
        '
        Me.txtInternalClock.Location = New System.Drawing.Point(528, 84)
        Me.txtInternalClock.Name = "txtInternalClock"
        Me.txtInternalClock.Size = New System.Drawing.Size(104, 20)
        Me.txtInternalClock.TabIndex = 18
        Me.txtInternalClock.Text = "TextBox2"
        '
        'Label12
        '
        Me.Label12.Location = New System.Drawing.Point(331, 119)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(57, 18)
        Me.Label12.TabIndex = 17
        Me.Label12.Text = "->ExtSig3"
        '
        'Label11
        '
        Me.Label11.Location = New System.Drawing.Point(331, 93)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(57, 19)
        Me.Label11.TabIndex = 16
        Me.Label11.Text = "->ExtSig1"
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(331, 23)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(57, 19)
        Me.Label10.TabIndex = 15
        Me.Label10.Text = "->ExtSig2"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(408, 149)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(104, 19)
        Me.Label9.TabIndex = 14
        Me.Label9.Text = "Stop Number:"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(408, 116)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(104, 19)
        Me.Label8.TabIndex = 13
        Me.Label8.Text = "Comparison Value:"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(408, 84)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(104, 18)
        Me.Label7.TabIndex = 12
        Me.Label7.Text = "Internal Clock:"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(408, 21)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(104, 19)
        Me.Label6.TabIndex = 11
        Me.Label6.Text = "Comparison Value:"
        '
        'txtCompStart
        '
        Me.txtCompStart.Location = New System.Drawing.Point(528, 21)
        Me.txtCompStart.Name = "txtCompStart"
        Me.txtCompStart.Size = New System.Drawing.Size(104, 20)
        Me.txtCompStart.TabIndex = 10
        Me.txtCompStart.Text = "TextBox1"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(8, 149)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(112, 19)
        Me.Label5.TabIndex = 9
        Me.Label5.Text = "Counter Stop Mode:"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 116)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(112, 19)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "Stop Condition:"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 84)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(112, 18)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "Clock Condition:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 51)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(112, 19)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "Counter Start Mode:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 21)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(112, 19)
        Me.Label1.TabIndex = 5
        Me.Label1.Text = "Start Condition:"
        '
        'cboStopWith
        '
        Me.cboStopWith.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStopWith.Location = New System.Drawing.Point(120, 149)
        Me.cboStopWith.Name = "cboStopWith"
        Me.cboStopWith.Size = New System.Drawing.Size(208, 21)
        Me.cboStopWith.TabIndex = 4
        '
        'cboStop
        '
        Me.cboStop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStop.Location = New System.Drawing.Point(120, 116)
        Me.cboStop.Name = "cboStop"
        Me.cboStop.Size = New System.Drawing.Size(208, 21)
        Me.cboStop.TabIndex = 3
        '
        'cboClock
        '
        Me.cboClock.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboClock.Location = New System.Drawing.Point(120, 84)
        Me.cboClock.Name = "cboClock"
        Me.cboClock.Size = New System.Drawing.Size(208, 21)
        Me.cboClock.TabIndex = 2
        '
        'cboStartWith
        '
        Me.cboStartWith.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStartWith.Location = New System.Drawing.Point(120, 51)
        Me.cboStartWith.Name = "cboStartWith"
        Me.cboStartWith.Size = New System.Drawing.Size(208, 21)
        Me.cboStartWith.TabIndex = 1
        '
        'cboStart
        '
        Me.cboStart.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStart.Location = New System.Drawing.Point(120, 21)
        Me.cboStart.Name = "cboStart"
        Me.cboStart.Size = New System.Drawing.Size(208, 21)
        Me.cboStart.TabIndex = 0
        '
        'frmMSmpMode
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(680, 323)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.btnCancel, Me.btnOK, Me.GroupBox3, Me.GroupBox1})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmMSmpMode"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Master Sampling Condition Setting"
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim StartComp As Integer
    Dim StopComp As Integer

    Dim InternalClock As Integer
    Dim StopNum As Integer
    Public Shared M_NotifyCount As Integer
    '===================================================
    '	Dialog initialization
    '===================================================
    Private Sub frmMSmpMode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '--------------------------------
        ' Initialize dialog display
        '--------------------------------
        ' Start
        With cboStart
            .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 CH4 Compare-register 0")
            .Items.Insert(8, "Count-match CH5 Compare-register 0")
            .Items.Insert(9, "Count-match CH6 Compare-register 0")
            .Items.Insert(10, "Count-match CH7 Compare-register 0")
            .Items.Insert(11, "Count-match CH0 Compare-register 1")
            .Items.Insert(12, "Count-match CH1 Compare-register 1")
            .Items.Insert(13, "Count-match CH2 Compare-register 1")
            .Items.Insert(14, "Count-match CH3 Compare-register 1")
            .Items.Insert(15, "Count-match CH4 Compare-register 1")
            .Items.Insert(16, "Count-match CH5 Compare-register 1")
            .Items.Insert(17, "Count-match CH6 Compare-register 1")
            .Items.Insert(18, "Count-match CH7 Compare-register 1")
        End With
        ' Start with
        With cboStartWith
            .Items.Clear()
            .Items.Insert(0, "Start counter regardless of sampling")
            .Items.Insert(1, "Start counter when sampling starts")
        End With
        ' Clock
        With cboClock
            .Items.Clear()
            .Items.Insert(0, "Internal Clock")
            .Items.Insert(1, "External Clock")
        End With
        ' Stop
        With cboStop
            .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 CH4 Compare-register 0")
            .Items.Insert(9, "Count-match CH5 Compare-register 0")
            .Items.Insert(10, "Count-match CH6 Compare-register 0")
            .Items.Insert(11, "Count-match CH7 Compare-register 0")
            .Items.Insert(12, "Count-match CH0 Compare-register 1")
            .Items.Insert(13, "Count-match CH1 Compare-register 1")
            .Items.Insert(14, "Count-match CH2 Compare-register 1")
            .Items.Insert(15, "Count-match CH3 Compare-register 1")
            .Items.Insert(16, "Count-match CH4 Compare-register 1")
            .Items.Insert(17, "Count-match CH5 Compare-register 1")
            .Items.Insert(18, "Count-match CH6 Compare-register 1")
            .Items.Insert(19, "Count-match CH7 Compare-register 1")
        End With
        ' Stop with
        With cboStopWith
            .Items.Clear()
            .Items.Insert(0, "Stop counter regardless of sampling")
            .Items.Insert(1, "Stop counter when sampling stops")
        End With

        cboStart.SelectedIndex = 0
        cboStartWith.SelectedIndex = 0
        cboClock.SelectedIndex = 0
        cboStop.SelectedIndex = 0
        cboStopWith.SelectedIndex = 0

        StartComp = &H100S
        InternalClock = 1000
        StopComp = &H200S
        StopNum = 1000
        M_NotifyCount = 500
        Sync.M_IsRing = CNTS_WRITE_ONCE


        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
        txtStopNumber.Text = Convert.ToUInt32(Hex(StopNum), 16)
        ' In order to display the number of sampling cycles for notification to unsigned, convert it once through hexadecimal characters
        txtNumberData.Text = Convert.ToUInt32(Hex(M_NotifyCount), 16)

        If Sync.M_IsRing = CNTS_WRITE_ONCE Then
            rdoOnce.Checked = True
            rdoRing.Checked = False
        Else
            rdoOnce.Checked = False
            rdoRing.Checked = True
        End If

        cboStart_SelectedIndexChanged(cboStart, New System.EventArgs())
        cboClock_SelectedIndexChanged(cboClock, New System.EventArgs())
        cboStop_SelectedIndexChanged(cboStop, New System.EventArgs())
    End Sub

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

        szBuf = cboStart.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 cboClock_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboClock.SelectedIndexChanged
        Dim szBuf As New String("", 100)

        szBuf = cboClock.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 cboStop_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboStop.SelectedIndexChanged
        Dim szBuf As New String("", 100)

        szBuf = cboStop.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
            txtStopNumber.Enabled = True
        Else
            txtStopNumber.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 szBuf As New String("", 100)
        Dim Checked As Boolean
        Dim dwStart As Short
        Dim ExtSig1, ExtSig2, ExtSig3 As Short
        Dim wStartWith As Short
        Dim dwClock As Short
        Dim dwStop As Short
        Dim wStopWith As Short
        Dim ret As Integer
        Dim strMsg As String
        Dim CompChNo As Integer
        Dim CompRegNo As Integer
        Dim error_string As New StringBuilder("", 256)

        '--------------------------------
        ' Get displaying data
        '--------------------------------
        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
        StopNum = Convert.ToInt32(Hex(Val(txtStopNumber.Text)), 16)
        ' In order to set the number of sampling cycles for notification to signed, convert it once through hexadecimal characters
        M_NotifyCount = Convert.ToInt32(Hex(Val(txtNumberData.Text)), 16)
        Checked = rdoOnce.Checked

        Select Case cboStart.SelectedIndex
            Case 0
                dwStart = CNTS_START_SOFT
                ExtSig2 = CNTS_EXT_START_SOFT
            Case 1
                dwStart = CNTS_START_EXT_RISE
                ExtSig2 = CNTS_EXT_START_EXT_RISE
            Case 2
                dwStart = CNTS_START_EXT_FALL
                ExtSig2 = CNTS_EXT_START_EXT_FALL
            Case 3
                dwStart = CNTS_START_CNTMATCH_CH0_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH0_REG0
            Case 4
                dwStart = CNTS_START_CNTMATCH_CH1_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH1_REG0
            Case 5
                dwStart = CNTS_START_CNTMATCH_CH2_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH2_REG0
            Case 6
                dwStart = CNTS_START_CNTMATCH_CH3_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH3_REG0
            Case 7
                dwStart = CNTS_START_CNTMATCH_CH4_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH4_REG0
            Case 8
                dwStart = CNTS_START_CNTMATCH_CH5_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH5_REG0
            Case 9
                dwStart = CNTS_START_CNTMATCH_CH6_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH6_REG0
            Case 10
                dwStart = CNTS_START_CNTMATCH_CH7_REG0
                ExtSig2 = CNTS_EXT_CNTMATCH_CH7_REG0
            Case 11
                dwStart = CNTS_START_CNTMATCH_CH0_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH0_REG1
            Case 12
                dwStart = CNTS_START_CNTMATCH_CH1_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH1_REG1
            Case 12
                dwStart = CNTS_START_CNTMATCH_CH2_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH2_REG1
            Case 12
                dwStart = CNTS_START_CNTMATCH_CH3_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH3_REG1
            Case 12
                dwStart = CNTS_START_CNTMATCH_CH4_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH4_REG1
            Case 12
                dwStart = CNTS_START_CNTMATCH_CH5_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH5_REG1
            Case 12
                dwStart = CNTS_START_CNTMATCH_CH6_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH6_REG1
            Case 12
                dwStart = CNTS_START_CNTMATCH_CH7_REG1
                ExtSig2 = CNTS_EXT_CNTMATCH_CH7_REG1
        End Select

        Select Case cboStartWith.SelectedIndex
            Case 0
                wStartWith = CNTS_START_CNT_NOT_WITH_SAMP
            Case 1
                wStartWith = CNTS_START_CNT_WITH_SAMP
        End Select
        Select Case cboClock.SelectedIndex
            Case 0
                dwClock = CNTS_CLOCK_CLOCK
                ExtSig1 = CNTS_EXT_CLOCK
            Case 1
                dwClock = CNTS_CLOCK_EXT_TRG
                ExtSig1 = CNTS_EXT_EXT_TRG
        End Select

        Select Case cboStop.SelectedIndex
            Case 0
                dwStop = CNTS_STOP_SOFT
                ExtSig3 = CNTS_STOP_EXT_RISE
            Case 1
                dwStop = CNTS_CLOCK_EXT_TRG
                ExtSig3 = CNTS_EXT_STOP_EXT_RISE
            Case 2
                dwStop = CNTS_STOP_EXT_FALL
                ExtSig3 = CNTS_EXT_STOP_EXT_FALL
            Case 3
                dwStop = CNTS_STOP_NUM
                ExtSig3 = CNTS_EXT_TRNSNUM
            Case 4
                dwStop = CNTS_STOP_CNTMATCH_CH0_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH0_REG0
            Case 5
                dwStop = CNTS_STOP_CNTMATCH_CH1_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH1_REG0
            Case 6
                dwStop = CNTS_STOP_CNTMATCH_CH2_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH2_REG0
            Case 7
                dwStop = CNTS_STOP_CNTMATCH_CH3_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH3_REG0
            Case 8
                dwStop = CNTS_STOP_CNTMATCH_CH4_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH4_REG0
            Case 9
                dwStop = CNTS_STOP_CNTMATCH_CH5_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH5_REG0
            Case 10
                dwStop = CNTS_STOP_CNTMATCH_CH6_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH6_REG0
            Case 11
                dwStop = CNTS_STOP_CNTMATCH_CH7_REG0
                ExtSig3 = CNTS_EXT_CNTMATCH_CH7_REG0
            Case 12
                dwStop = CNTS_STOP_CNTMATCH_CH0_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH0_REG1
            Case 13
                dwStop = CNTS_STOP_CNTMATCH_CH1_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH1_REG1
            Case 14
                dwStop = CNTS_STOP_CNTMATCH_CH2_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH2_REG1
            Case 15
                dwStop = CNTS_STOP_CNTMATCH_CH3_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH3_REG1
            Case 16
                dwStop = CNTS_STOP_CNTMATCH_CH4_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH4_REG1
            Case 17
                dwStop = CNTS_STOP_CNTMATCH_CH5_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH5_REG1
            Case 18
                dwStop = CNTS_STOP_CNTMATCH_CH6_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH6_REG1
            Case 19
                dwStop = CNTS_STOP_CNTMATCH_CH7_REG1
                ExtSig3 = CNTS_EXT_CNTMATCH_CH7_REG1
        End Select

        Select Case cboStopWith.SelectedIndex
            Case 0
                wStopWith = CNTS_STOP_CNT_NOT_WITH_SAMP
            Case 1
                wStopWith = CNTS_STOP_CNT_WITH_SAMP
        End Select

        If Checked = True Then
            Sync.M_IsRing = CNTS_WRITE_ONCE
        Else
            Sync.M_IsRing = CNTS_WRITE_RING
        End If

        '--------------------------------
        ' Set sampling condition
        '--------------------------------
        ret = CntSetMaster(Sync.M_Id, ExtSig1, ExtSig2, ExtSig3, 1, 1)
        If ret <> 0 Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetMaster ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
        End If
        ret = CntSetSamplingStartTrigger(Sync.M_Id, dwStart, wStartWith, CHANNEL_NUM)
        If ret <> 0 Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetSamplingStartTrigger ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
        End If
        ret = CntSetSamplingClockTrigger(Sync.M_Id, dwClock)
        If ret <> 0 Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetSamplingClockTrigger ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
        End If
        ret = CntSetSamplingStopTrigger(Sync.M_Id, dwStop, wStopWith, CHANNEL_NUM)
        If ret <> 0 Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetSamplingStopTrigger ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
        End If
        ret = CntSetSamplingInternalClock(Sync.M_Id, InternalClock, CNTS_TIM_UNIT_NS)
        If ret <> 0 Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetSamplingInternalClock ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
        End If
        ret = CntSetSamplingStopNumber(Sync.M_Id, StopNum)
        If ret <> 0 Then
            CntGetErrorString(ret, error_string)
            strMsg = String.Format("CntSetSamplingStopNumber ret = {0:d}: {1}", ret, error_string)
            MsgBox(strMsg, MsgBoxStyle.OKOnly, Nothing)
        End If

        Select Case dwStart
            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
            Case 0
                CompChNo = &HFFFFS
                CompRegNo = &HFFFFS
        End Select
        If (CompChNo <> &HFFFFS) And (CompRegNo <> &HFFFFS) Then
            ret = CntNotifyCountUp(Sync.M_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
        Select Case dwStop
            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
            Case 0
                CompChNo = &HFFFFS
                CompRegNo = &HFFFFS
        End Select
        If (CompChNo <> &HFFFFS) And (CompRegNo <> &HFFFFS) Then
            ret = CntNotifyCountUp(Sync.M_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
        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 frmMSmpMode_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        e.Cancel = True
        Me.Hide()
    End Sub
End Class
