﻿Option Strict Off
Option Explicit On 
Imports System.Text

Public Class ModeDlg
	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 Label10 As System.Windows.Forms.Label
	Public WithEvents btnCancel As System.Windows.Forms.Button
	Public WithEvents btnOK As System.Windows.Forms.Button
	Public WithEvents Frame1 As System.Windows.Forms.GroupBox
	Public WithEvents cboCounterMode As System.Windows.Forms.ComboBox
	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 Label9 As System.Windows.Forms.Label
	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 Label1 As System.Windows.Forms.Label
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.Label10 = New System.Windows.Forms.Label()
		Me.btnCancel = New System.Windows.Forms.Button()
		Me.btnOK = New System.Windows.Forms.Button()
		Me.Frame1 = New System.Windows.Forms.GroupBox()
		Me.cboCounterMode = New System.Windows.Forms.ComboBox()
		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.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.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.Frame1.SuspendLayout()
		Me.SuspendLayout()
		'
		'Label10
		'
		Me.Label10.AutoSize = True
		Me.Label10.BackColor = System.Drawing.SystemColors.Control
		Me.Label10.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label10.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label10.Location = New System.Drawing.Point(12, 273)
		Me.Label10.Name = "Label10"
		Me.Label10.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label10.Size = New System.Drawing.Size(199, 12)
		Me.Label10.TabIndex = 29
		Me.Label10.Text = "全てのチャネルが同一の設定となります。"
		'
		'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(268, 297)
		Me.btnCancel.Name = "btnCancel"
		Me.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.btnCancel.Size = New System.Drawing.Size(81, 23)
		Me.btnCancel.TabIndex = 27
		Me.btnCancel.Text = "ｷｬﾝｾﾙ"
		'
		'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(177, 297)
		Me.btnOK.Name = "btnOK"
		Me.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.btnOK.Size = New System.Drawing.Size(81, 23)
		Me.btnOK.TabIndex = 26
		Me.btnOK.Text = "OK"
		'
		'Frame1
		'
		Me.Frame1.BackColor = System.Drawing.SystemColors.Control
		Me.Frame1.Controls.AddRange(New System.Windows.Forms.Control() {Me.cboCounterMode, Me.cboFilter, Me.cboSyncClear, Me.cboMul, Me.cboPhase, Me.cboCountDirection, Me.cboSignalSource, Me.cboZPhaseLogic, Me.cboZPhaseMode, Me.Label9, Me.Label8, Me.Label7, Me.Label6, Me.Label5, Me.Label4, Me.Label3, Me.Label2, Me.Label1})
		Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Frame1.Location = New System.Drawing.Point(12, 9)
		Me.Frame1.Name = "Frame1"
		Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Frame1.Size = New System.Drawing.Size(337, 249)
		Me.Frame1.TabIndex = 28
		Me.Frame1.TabStop = False
		Me.Frame1.Text = "カウンタ モード"
		'
		'cboCounterMode
		'
		Me.cboCounterMode.BackColor = System.Drawing.SystemColors.Window
		Me.cboCounterMode.Cursor = System.Windows.Forms.Cursors.Default
		Me.cboCounterMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboCounterMode.ForeColor = System.Drawing.SystemColors.WindowText
		Me.cboCounterMode.Location = New System.Drawing.Point(136, 216)
		Me.cboCounterMode.Name = "cboCounterMode"
		Me.cboCounterMode.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboCounterMode.Size = New System.Drawing.Size(193, 20)
		Me.cboCounterMode.TabIndex = 20
		'
		'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(136, 192)
		Me.cboFilter.Name = "cboFilter"
		Me.cboFilter.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboFilter.Size = New System.Drawing.Size(193, 20)
		Me.cboFilter.TabIndex = 19
		'
		'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(136, 168)
		Me.cboSyncClear.Name = "cboSyncClear"
		Me.cboSyncClear.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboSyncClear.Size = New System.Drawing.Size(193, 20)
		Me.cboSyncClear.TabIndex = 18
		'
		'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(136, 144)
		Me.cboMul.Name = "cboMul"
		Me.cboMul.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboMul.Size = New System.Drawing.Size(193, 20)
		Me.cboMul.TabIndex = 17
		'
		'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(136, 120)
		Me.cboPhase.Name = "cboPhase"
		Me.cboPhase.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboPhase.Size = New System.Drawing.Size(193, 20)
		Me.cboPhase.TabIndex = 16
		'
		'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(136, 96)
		Me.cboCountDirection.Name = "cboCountDirection"
		Me.cboCountDirection.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboCountDirection.Size = New System.Drawing.Size(193, 20)
		Me.cboCountDirection.TabIndex = 15
		'
		'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(136, 72)
		Me.cboSignalSource.Name = "cboSignalSource"
		Me.cboSignalSource.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboSignalSource.Size = New System.Drawing.Size(193, 20)
		Me.cboSignalSource.TabIndex = 14
		'
		'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(136, 48)
		Me.cboZPhaseLogic.Name = "cboZPhaseLogic"
		Me.cboZPhaseLogic.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboZPhaseLogic.Size = New System.Drawing.Size(193, 20)
		Me.cboZPhaseLogic.TabIndex = 13
		'
		'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(136, 24)
		Me.cboZPhaseMode.Name = "cboZPhaseMode"
		Me.cboZPhaseMode.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboZPhaseMode.Size = New System.Drawing.Size(193, 20)
		Me.cboZPhaseMode.TabIndex = 12
		'
		'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(16, 220)
		Me.Label9.Name = "Label9"
		Me.Label9.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label9.Size = New System.Drawing.Size(75, 12)
		Me.Label9.TabIndex = 11
		Me.Label9.Text = "カウントモード："
		'
		'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(16, 196)
		Me.Label8.Name = "Label8"
		Me.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label8.Size = New System.Drawing.Size(96, 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(16, 172)
		Me.Label7.Name = "Label7"
		Me.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label7.Size = New System.Drawing.Size(36, 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(16, 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(16, 124)
		Me.Label5.Name = "Label5"
		Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label5.Size = New System.Drawing.Size(104, 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(16, 100)
		Me.Label4.Name = "Label4"
		Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label4.Size = New System.Drawing.Size(71, 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(16, 76)
		Me.Label3.Name = "Label3"
		Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label3.Size = New System.Drawing.Size(72, 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(16, 52)
		Me.Label2.Name = "Label2"
		Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label2.Size = New System.Drawing.Size(55, 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(16, 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相モード："
		'
		'ModeDlg
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
		Me.ClientSize = New System.Drawing.Size(360, 328)
		Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label10, Me.btnCancel, Me.btnOK, Me.Frame1})
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "ModeDlg"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "カウンタモード設定"
		Me.Frame1.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region

	'===================================================
	'	ダイアログ初期化
	'===================================================
	Private Sub ModeDlg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

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

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

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

		' カウント方向
		cboCountDirection.Items.Clear()
		cboCountDirection.Items.Insert(0, "ダウンカウント")
		cboCountDirection.Items.Insert(1, "アップカウント")
	
		' 動作モード
		cboPhase.Items.Clear()
		cboPhase.Items.Insert(0, "単相")
		cboPhase.Items.Insert(1, "2相")
		cboPhase.Items.Insert(2, "ゲートコントロール")

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

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

		' デジタルフィルタ値
		cboFilter.Items.Clear()
		For i = 0 To 15
			cboFilter.Items.Insert(i, Hex(i))
		Next
	
		' カウンタモード値
		cboCounterMode.Items.Clear()
		cboCounterMode.Items.Insert(0, "積算")
		cboCounterMode.Items.Insert(1, "差分")

		'-------------------------------
		' 初期データのセット
		'-------------------------------
		cboZPhaseMode.SelectedIndex = 0
		cboZPhaseLogic.SelectedIndex = 1
        cboSignalSource.SelectedIndex = 2
		cboCountDirection.SelectedIndex = 1
		cboPhase.SelectedIndex = 1
		cboMul.SelectedIndex = 0
		cboSyncClear.SelectedIndex = 0
		cboFilter.SelectedIndex = 0
		cboCounterMode.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
		Dim wCounterMode 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
		'--------------------------------
		' カウンタモード
		'--------------------------------
		wCounterMode = 0
		If cboCounterMode.Text = "積算" Then wCounterMode = CNTS_MODE_NORMAL
		If cboCounterMode.Text = "差分" Then wCounterMode = CNTS_MODE_DIFF


		'-------------------------------
		' 設定情報をデバイスへセット
		'-------------------------------
		For ChNo = 0 To CHANNEL_NUM - 1
			'---------------------------------------------
			' Z相使用方法 設定
			'---------------------------------------------
			ret = CntSetZMode(Id, ChNo, wZPhaseMode)
			If ret <> 0 Then
				CntGetErrorString(ret, error_string)
                str = String.Format("CntSetZMode : ret = {0:X} h" & vbCrLf & error_string.ToString(), ret)
				MessageBox.Show(str, "Error", MessageBoxButtons.OK)
				Exit For
			End If
			'---------------------------------------------
			' Z相論理 設定
			'---------------------------------------------
			ret = CntSetZLogic(Id, ChNo, wZPhaseLogic)
			If ret <> 0 Then
				CntGetErrorString(ret, error_string)
                str = String.Format("CntSetZLogic : ret = {0:X} h" & vbCrLf & error_string.ToString(), ret)
				MessageBox.Show(str, "Error", MessageBoxButtons.OK)
				Exit For
			End If
			'---------------------------------------------
			' 外部信号源 設定
			'---------------------------------------------
			ret = CntSelectChannelSignal(Id, ChNo, wSignalSource)
			If ret <> 0 Then
				CntGetErrorString(ret, error_string)
                str = String.Format("CntSelectChannelSignal : ret = {0:X} h" & vbCrLf & error_string.ToString(), ret)
				MessageBox.Show(str, "Error", MessageBoxButtons.OK)
				Exit For
			End If
			'---------------------------------------------
			' カウント方向 設定
			'---------------------------------------------
			ret = CntSetCountDirection(Id, ChNo, wCountDirection)
			If ret <> 0 Then
				CntGetErrorString(ret, error_string)
                str = String.Format("CntSetCountDirection : ret = {0:X} h" & vbCrLf & error_string.ToString(), ret)
				MessageBox.Show(str, "Error", MessageBoxButtons.OK)
				Exit For
			End If
			'---------------------------------------------
			' 動作モード 設定
			'---------------------------------------------
			ret = CntSetOperationMode(Id, ChNo, wPhase, wMul, wSyncClear)
			If ret <> 0 Then
				CntGetErrorString(ret, error_string)
                str = String.Format("CntSetOperationMode : ret = {0:X} h" & vbCrLf & error_string.ToString(), ret)
				MessageBox.Show(str, "Error", MessageBoxButtons.OK)
				Exit For
			End If
			'---------------------------------------------
			' デジタルフィルタ値 設定
			'---------------------------------------------
			ret = CntSetDigitalFilter(Id, ChNo, wFilter)
			If ret <> 0 Then
				CntGetErrorString(ret, error_string)
                str = String.Format("CntSetOperationMode : ret = {0:X} h" & vbCrLf & error_string.ToString(), ret)
				MessageBox.Show(str, "Error", MessageBoxButtons.OK)
				Exit For
			End If
			'---------------------------------------------
			' カウンタモード値 設定
			'---------------------------------------------
			ret = CntSetCounterMode(Id, ChNo, wCounterMode)
			If ret <> 0 Then
				CntGetErrorString(ret, error_string)
                str = String.Format("CntSetCounterMode : ret = {0:X} h" & vbCrLf & error_string.ToString(), ret)
				MessageBox.Show(str, "Error", MessageBoxButtons.OK)
				Exit For
			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 ModeDlg_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

		e.Cancel = True
		Me.Hide()

	End Sub
End Class