﻿Imports System.Text

Public Class frmMode
    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 フォーム デザイナを使って変更してください。  
    ' コード エディタは使用しないでください。
    Public WithEvents btnCancel As System.Windows.Forms.Button
    Public WithEvents btnOK As System.Windows.Forms.Button
    Public WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents Frame1 As System.Windows.Forms.GroupBox
    Public WithEvents cboFilter As System.Windows.Forms.ComboBox
    Public WithEvents cboSyncClear As System.Windows.Forms.ComboBox
    Public WithEvents cboMul As System.Windows.Forms.ComboBox
    Public WithEvents cboPhase As System.Windows.Forms.ComboBox
    Public WithEvents cboCountDirection As System.Windows.Forms.ComboBox
    Public WithEvents cboSignalSource As System.Windows.Forms.ComboBox
    Public WithEvents cboZPhaseLogic As System.Windows.Forms.ComboBox
    Public WithEvents cboZPhaseMode As System.Windows.Forms.ComboBox
    Public WithEvents Label8 As System.Windows.Forms.Label
    Public WithEvents Label7 As System.Windows.Forms.Label
    Public WithEvents Label6 As System.Windows.Forms.Label
    Public WithEvents Label5 As System.Windows.Forms.Label
    Public WithEvents Label4 As System.Windows.Forms.Label
    Public WithEvents Label3 As System.Windows.Forms.Label
    Public WithEvents Label2 As System.Windows.Forms.Label
    Public WithEvents Label9 As Label
    Public WithEvents Label1 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Frame1 = New System.Windows.Forms.GroupBox()
        Me.cboFilter = New System.Windows.Forms.ComboBox()
        Me.cboSyncClear = New System.Windows.Forms.ComboBox()
        Me.cboMul = New System.Windows.Forms.ComboBox()
        Me.cboPhase = New System.Windows.Forms.ComboBox()
        Me.cboCountDirection = New System.Windows.Forms.ComboBox()
        Me.cboSignalSource = New System.Windows.Forms.ComboBox()
        Me.cboZPhaseLogic = New System.Windows.Forms.ComboBox()
        Me.cboZPhaseMode = New System.Windows.Forms.ComboBox()
        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.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.Label9 = New System.Windows.Forms.Label()
        Me.Frame1.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnCancel
        '
        Me.btnCancel.BackColor = System.Drawing.SystemColors.Control
        Me.btnCancel.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCancel.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCancel.Location = New System.Drawing.Point(249, 247)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCancel.Size = New System.Drawing.Size(97, 24)
        Me.btnCancel.TabIndex = 7
        Me.btnCancel.Text = "ｷｬﾝｾﾙ"
        Me.btnCancel.UseVisualStyleBackColor = False
        '
        'btnOK
        '
        Me.btnOK.BackColor = System.Drawing.SystemColors.Control
        Me.btnOK.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnOK.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnOK.Location = New System.Drawing.Point(137, 247)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnOK.Size = New System.Drawing.Size(97, 24)
        Me.btnOK.TabIndex = 0
        Me.btnOK.Text = "OK"
        Me.btnOK.UseVisualStyleBackColor = False
        '
        'Frame1
        '
        Me.Frame1.BackColor = System.Drawing.SystemColors.Control
        Me.Frame1.Controls.Add(Me.Label9)
        Me.Frame1.Controls.Add(Me.cboFilter)
        Me.Frame1.Controls.Add(Me.cboSyncClear)
        Me.Frame1.Controls.Add(Me.cboMul)
        Me.Frame1.Controls.Add(Me.cboPhase)
        Me.Frame1.Controls.Add(Me.cboCountDirection)
        Me.Frame1.Controls.Add(Me.cboSignalSource)
        Me.Frame1.Controls.Add(Me.cboZPhaseLogic)
        Me.Frame1.Controls.Add(Me.cboZPhaseMode)
        Me.Frame1.Controls.Add(Me.Label8)
        Me.Frame1.Controls.Add(Me.Label7)
        Me.Frame1.Controls.Add(Me.Label6)
        Me.Frame1.Controls.Add(Me.Label5)
        Me.Frame1.Controls.Add(Me.Label4)
        Me.Frame1.Controls.Add(Me.Label3)
        Me.Frame1.Controls.Add(Me.Label2)
        Me.Frame1.Controls.Add(Me.Label1)
        Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame1.Location = New System.Drawing.Point(16, 15)
        Me.Frame1.Name = "Frame1"
        Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame1.Size = New System.Drawing.Size(368, 225)
        Me.Frame1.TabIndex = 8
        Me.Frame1.TabStop = False
        Me.Frame1.Text = "カウンタ モード"
        '
        'cboFilter
        '
        Me.cboFilter.BackColor = System.Drawing.SystemColors.Window
        Me.cboFilter.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboFilter.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboFilter.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboFilter.Location = New System.Drawing.Point(132, 192)
        Me.cboFilter.Name = "cboFilter"
        Me.cboFilter.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboFilter.Size = New System.Drawing.Size(201, 20)
        Me.cboFilter.TabIndex = 18
        '
        'cboSyncClear
        '
        Me.cboSyncClear.BackColor = System.Drawing.SystemColors.Window
        Me.cboSyncClear.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboSyncClear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboSyncClear.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboSyncClear.Location = New System.Drawing.Point(132, 168)
        Me.cboSyncClear.Name = "cboSyncClear"
        Me.cboSyncClear.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboSyncClear.Size = New System.Drawing.Size(201, 20)
        Me.cboSyncClear.TabIndex = 17
        '
        'cboMul
        '
        Me.cboMul.BackColor = System.Drawing.SystemColors.Window
        Me.cboMul.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboMul.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboMul.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboMul.Location = New System.Drawing.Point(132, 144)
        Me.cboMul.Name = "cboMul"
        Me.cboMul.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboMul.Size = New System.Drawing.Size(201, 20)
        Me.cboMul.TabIndex = 16
        '
        'cboPhase
        '
        Me.cboPhase.BackColor = System.Drawing.SystemColors.Window
        Me.cboPhase.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboPhase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboPhase.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboPhase.Location = New System.Drawing.Point(132, 120)
        Me.cboPhase.Name = "cboPhase"
        Me.cboPhase.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboPhase.Size = New System.Drawing.Size(201, 20)
        Me.cboPhase.TabIndex = 15
        '
        'cboCountDirection
        '
        Me.cboCountDirection.BackColor = System.Drawing.SystemColors.Window
        Me.cboCountDirection.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboCountDirection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboCountDirection.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboCountDirection.Location = New System.Drawing.Point(132, 96)
        Me.cboCountDirection.Name = "cboCountDirection"
        Me.cboCountDirection.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboCountDirection.Size = New System.Drawing.Size(201, 20)
        Me.cboCountDirection.TabIndex = 14
        '
        'cboSignalSource
        '
        Me.cboSignalSource.BackColor = System.Drawing.SystemColors.Window
        Me.cboSignalSource.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboSignalSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboSignalSource.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboSignalSource.Location = New System.Drawing.Point(132, 72)
        Me.cboSignalSource.Name = "cboSignalSource"
        Me.cboSignalSource.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboSignalSource.Size = New System.Drawing.Size(201, 20)
        Me.cboSignalSource.TabIndex = 13
        '
        'cboZPhaseLogic
        '
        Me.cboZPhaseLogic.BackColor = System.Drawing.SystemColors.Window
        Me.cboZPhaseLogic.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboZPhaseLogic.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboZPhaseLogic.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboZPhaseLogic.Location = New System.Drawing.Point(132, 48)
        Me.cboZPhaseLogic.Name = "cboZPhaseLogic"
        Me.cboZPhaseLogic.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboZPhaseLogic.Size = New System.Drawing.Size(201, 20)
        Me.cboZPhaseLogic.TabIndex = 12
        '
        'cboZPhaseMode
        '
        Me.cboZPhaseMode.BackColor = System.Drawing.SystemColors.Window
        Me.cboZPhaseMode.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboZPhaseMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboZPhaseMode.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboZPhaseMode.Location = New System.Drawing.Point(132, 24)
        Me.cboZPhaseMode.Name = "cboZPhaseMode"
        Me.cboZPhaseMode.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboZPhaseMode.Size = New System.Drawing.Size(201, 20)
        Me.cboZPhaseMode.TabIndex = 11
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.BackColor = System.Drawing.SystemColors.Control
        Me.Label8.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label8.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label8.Location = New System.Drawing.Point(8, 196)
        Me.Label8.Name = "Label8"
        Me.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label8.Size = New System.Drawing.Size(94, 12)
        Me.Label8.TabIndex = 10
        Me.Label8.Text = "デジタルフィルタ値："
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.BackColor = System.Drawing.SystemColors.Control
        Me.Label7.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label7.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label7.Location = New System.Drawing.Point(8, 172)
        Me.Label7.Name = "Label7"
        Me.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label7.Size = New System.Drawing.Size(35, 12)
        Me.Label7.TabIndex = 9
        Me.Label7.Text = "クリア："
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.BackColor = System.Drawing.SystemColors.Control
        Me.Label6.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label6.Location = New System.Drawing.Point(8, 148)
        Me.Label6.Name = "Label6"
        Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label6.Size = New System.Drawing.Size(35, 12)
        Me.Label6.TabIndex = 8
        Me.Label6.Text = "逓倍："
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.BackColor = System.Drawing.SystemColors.Control
        Me.Label5.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label5.Location = New System.Drawing.Point(8, 124)
        Me.Label5.Name = "Label5"
        Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label5.Size = New System.Drawing.Size(35, 12)
        Me.Label5.TabIndex = 7
        Me.Label5.Text = "相数："
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.BackColor = System.Drawing.SystemColors.Control
        Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label4.Location = New System.Drawing.Point(8, 100)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(70, 12)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "カウント方向："
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(8, 76)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(71, 12)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "外部信号源："
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(8, 52)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(54, 12)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "Z相論理："
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(8, 28)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(58, 12)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "Z相モード："
        '
        'Label9
        '
        Me.Label9.AutoSize = True
        Me.Label9.BackColor = System.Drawing.SystemColors.Control
        Me.Label9.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label9.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label9.Location = New System.Drawing.Point(339, 195)
        Me.Label9.Name = "Label9"
        Me.Label9.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label9.Size = New System.Drawing.Size(25, 12)
        Me.Label9.TabIndex = 19
        Me.Label9.Text = "Hex"
        '
        'frmMode
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(393, 278)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.Frame1)
        Me.Controls.Add(Me.btnCancel)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmMode"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "カウンタモード設定"
        Me.Frame1.ResumeLayout(False)
        Me.Frame1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmMode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '画面初期化
        Me.Left = (Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.Bounds.Height - Me.Height) / 2

        '===================================================
        '	コンボボックス初期化
        '===================================================
        'Z相使用方法
        With cboZPhaseMode
            .Items.Clear()
            .Items.Insert(0, "未使用")
            .Items.Insert(1, "1回")
            .Items.Insert(2, "毎回")
        End With

        'Z相論理
        With cboZPhaseLogic
            .Items.Clear()
            .Items.Insert(0, "正論理")
            .Items.Insert(1, "負論理")
        End With

        '外部信号源
        With cboSignalSource
            .Items.Clear()
            .Items.Insert(0, "フォトカプラ絶縁")
            .Items.Insert(1, "TTL")
            .Items.Insert(2, "差動")
        End With

        'カウント方向
        With cboCountDirection
            .Items.Clear()
            .Items.Insert(0, "ダウンカウント")
            .Items.Insert(1, "アップカウント")
        End With

        '動作モード
        With cboPhase
            .Items.Clear()
            .Items.Insert(0, "単相")
            .Items.Insert(1, "2相")
            .Items.Insert(2, "ゲートコントロール")
        End With

        '逓倍
        With cboMul
            .Items.Clear()
            .Items.Insert(0, "1逓倍")
            .Items.Insert(1, "2逓倍")
            .Items.Insert(2, "4逓倍")
        End With

        '同期/非同期クリア
        With cboSyncClear
            .Items.Clear()
            .Items.Insert(0, "非同期クリア")
            .Items.Insert(1, "同期クリア")
        End With

        'デジタルフィルタ値
        With cboFilter
            .Items.Clear()
            .Items.Insert(&H0S, "0")
            .Items.Insert(&H1S, "1")
            .Items.Insert(&H2S, "2")
            .Items.Insert(&H3S, "3")
            .Items.Insert(&H4S, "4")
            .Items.Insert(&H5S, "5")
            .Items.Insert(&H6S, "6")
            .Items.Insert(&H7S, "7")
            .Items.Insert(&H8S, "8")
            .Items.Insert(&H9S, "9")
            .Items.Insert(&HAS, "A")
            .Items.Insert(&HBS, "B")
            .Items.Insert(&HCS, "C")
            .Items.Insert(&HDS, "D")
            .Items.Insert(&HES, "E")
            .Items.Insert(&HFS, "F")
            .Items.Insert(&H10S, "10")
            .Items.Insert(&H11S, "11")
            .Items.Insert(&H12S, "12")
            .Items.Insert(&H13S, "13")
            .Items.Insert(&H14S, "14")
        End With

        cboZPhaseMode.SelectedIndex = 0
        cboZPhaseLogic.SelectedIndex = 1
        cboSignalSource.SelectedIndex = 2
        cboCountDirection.SelectedIndex = 1
        cboPhase.SelectedIndex = 1
        cboMul.SelectedIndex = 0
        cboSyncClear.SelectedIndex = 0
        cboFilter.SelectedIndex = 0

    End Sub

    '---------------------------------------------
    ' 設定完了処理
    '---------------------------------------------
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim ChNo As Short
        Dim ret As Integer
        Dim str As String
        Dim error_string As New StringBuilder("", 256)

        Dim wZPhaseMode As Short
        Dim wZPhaseLogic As Short
        Dim wSignalSource As Short
        Dim wCountDirection As Short
        Dim wPhase As Short
        Dim wMul As Short
        Dim wSyncClear As Short
        Dim wFilter As Short

        '-------------------------------
        ' 設定情報の取得
        '-------------------------------
        '--------------------------------
        ' Z相使用方法
        '--------------------------------
        wZPhaseMode = 0
        If cboZPhaseMode.Text = "未使用" Then wZPhaseMode = CNT_ZPHASE_NOT_USE
        If cboZPhaseMode.Text = "1回" Then wZPhaseMode = CNT_ZPHASE_NEXT_ONE
        If cboZPhaseMode.Text = "毎回" Then wZPhaseMode = CNT_ZPHASE_EVERY_TIME
        '--------------------------------
        ' Z相使用方法
        '--------------------------------
        wZPhaseLogic = 0
        If cboZPhaseLogic.Text = "正論理" Then wZPhaseLogic = CNT_ZLOGIC_POSITIVE
        If cboZPhaseLogic.Text = "負論理" Then wZPhaseLogic = CNT_ZLOGIC_NEGATIVE
        '--------------------------------
        ' 外部信号源
        '--------------------------------
        wSignalSource = 0
        If cboSignalSource.Text = "フォトカプラ絶縁" Then wSignalSource = CNT_SIGTYPE_ISOLATE
        If cboSignalSource.Text = "TTL" Then wSignalSource = CNT_SIGTYPE_TTL
        If cboSignalSource.Text = "差動" Then wSignalSource = CNT_SIGTYPE_LINERECEIVER
        '--------------------------------
        ' カウント方向
        '--------------------------------
        wCountDirection = 0
        If cboCountDirection.Text = "ダウンカウント" Then wCountDirection = CNT_DIR_DOWN
        If cboCountDirection.Text = "アップカウント" Then wCountDirection = CNT_DIR_UP
        '--------------------------------
        ' 動作モード
        '--------------------------------
        wPhase = 0
        If cboPhase.Text = "単相" Then wPhase = CNT_MODE_1PHASE
        If cboPhase.Text = "2相" Then wPhase = CNT_MODE_2PHASE
        If cboPhase.Text = "ゲートコントロール" Then wPhase = CNT_MODE_GATECONTROL
        '--------------------------------
        ' 逓倍
        '--------------------------------
        wMul = 0
        If cboMul.Text = "1逓倍" Then wMul = CNT_MUL_X1
        If cboMul.Text = "2逓倍" Then wMul = CNT_MUL_X2
        If cboMul.Text = "4逓倍" Then wMul = CNT_MUL_X4
        '--------------------------------
        ' 同期/非同期クリア
        '--------------------------------
        wSyncClear = 0
        If cboSyncClear.Text = "非同期クリア" Then wSyncClear = CNT_CLR_ASYNC
        If cboSyncClear.Text = "同期クリア" Then wSyncClear = CNT_CLR_SYNC
        '--------------------------------
        ' デジタルフィルタ値
        '--------------------------------
        wFilter = cboFilter.SelectedIndex

        '-------------------------------
        ' 設定情報をデバイスへセット
        '-------------------------------
        For ChNo = 0 To frmCounter.ChannelNum - 1
            '---------------------------------------------
            ' Z相使用方法 設定
            '---------------------------------------------
            ret = CntSetZMode(frmCounter.Id, ChNo, wZPhaseMode)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                str = String.Format("CntSetZMode : ret = {0:D}" & vbCrLf & error_string.ToString(), ret)
                MsgBox(str, MsgBoxStyle.OKOnly, "Error")
            End If
            '---------------------------------------------
            ' Z相論理 設定
            '---------------------------------------------
            ret = CntSetZLogic(frmCounter.Id, ChNo, wZPhaseLogic)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                str = String.Format("CntSetZLogic : ret = {0:D}" & vbCrLf & error_string.ToString(), ret)
                MsgBox(str, MsgBoxStyle.OKOnly, "Error")
            End If

            '---------------------------------------------
            ' 外部信号源 設定
            '---------------------------------------------
            ret = CntSelectChannelSignal(frmCounter.Id, ChNo, wSignalSource)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                str = String.Format("CntSelectChannelSignal : ret = {0:D}" & vbCrLf & error_string.ToString(), ret)
                MsgBox(str, MsgBoxStyle.OKOnly, "Error")
            End If
            '---------------------------------------------
            ' カウント方向 設定
            '---------------------------------------------
            ret = CntSetCountDirection(frmCounter.Id, ChNo, wCountDirection)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                str = String.Format("CntSetCountDirection : ret = {0:D}" & vbCrLf & error_string.ToString(), ret)
                MsgBox(str, MsgBoxStyle.OKOnly, "Error")
            End If
            '---------------------------------------------
            ' 動作モード 設定
            '---------------------------------------------
            ret = CntSetOperationMode(frmCounter.Id, ChNo, wPhase, wMul, wSyncClear)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                str = String.Format("CntSetOperationMode : ret = {0:D}" & vbCrLf & error_string.ToString(), ret)
                MsgBox(str, MsgBoxStyle.OKOnly, "Error")
            End If

            '---------------------------------------------
            ' デジタルフィルタ値 設定
            '---------------------------------------------
            ret = CntSetDigitalFilter(frmCounter.Id, ChNo, wFilter)
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                str = String.Format("CntSetDigitalFilter : ret = {0:D}" & vbCrLf & error_string.ToString(), ret)
                MsgBox(str, MsgBoxStyle.OKOnly, "Error")
            End If
        Next ChNo
        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 frmMode_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        e.Cancel = True
        Me.Hide()
    End Sub
End Class
