﻿Option Strict Off
Option Explicit On 
Imports System.Text

Public Class ModeDlg
	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.
	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(27, 303)
		Me.Label10.Name = "Label10"
		Me.Label10.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label10.Size = New System.Drawing.Size(215, 14)
		Me.Label10.TabIndex = 33
		Me.Label10.Text = "All channels use the same setting."
		'
		'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(229, 326)
		Me.btnCancel.Name = "btnCancel"
		Me.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.btnCancel.Size = New System.Drawing.Size(85, 22)
		Me.btnCancel.TabIndex = 31
		Me.btnCancel.Text = "Cancel"
		'
		'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(135, 326)
		Me.btnOK.Name = "btnOK"
		Me.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.btnOK.Size = New System.Drawing.Size(85, 22)
		Me.btnOK.TabIndex = 30
		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(14, 10)
		Me.Frame1.Name = "Frame1"
		Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Frame1.Size = New System.Drawing.Size(300, 285)
		Me.Frame1.TabIndex = 32
		Me.Frame1.TabStop = False
		Me.Frame1.Text = "Counter Mode"
		'
		'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(112, 245)
		Me.cboCounterMode.Name = "cboCounterMode"
		Me.cboCounterMode.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboCounterMode.Size = New System.Drawing.Size(176, 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(112, 217)
		Me.cboFilter.Name = "cboFilter"
		Me.cboFilter.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboFilter.Size = New System.Drawing.Size(176, 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(112, 189)
		Me.cboSyncClear.Name = "cboSyncClear"
		Me.cboSyncClear.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboSyncClear.Size = New System.Drawing.Size(176, 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(112, 161)
		Me.cboMul.Name = "cboMul"
		Me.cboMul.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboMul.Size = New System.Drawing.Size(176, 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(112, 133)
		Me.cboPhase.Name = "cboPhase"
		Me.cboPhase.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboPhase.Size = New System.Drawing.Size(176, 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(112, 105)
		Me.cboCountDirection.Name = "cboCountDirection"
		Me.cboCountDirection.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboCountDirection.Size = New System.Drawing.Size(176, 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(112, 77)
		Me.cboSignalSource.Name = "cboSignalSource"
		Me.cboSignalSource.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboSignalSource.Size = New System.Drawing.Size(176, 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(112, 49)
		Me.cboZPhaseLogic.Name = "cboZPhaseLogic"
		Me.cboZPhaseLogic.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboZPhaseLogic.Size = New System.Drawing.Size(176, 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(112, 21)
		Me.cboZPhaseMode.Name = "cboZPhaseMode"
		Me.cboZPhaseMode.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.cboZPhaseMode.Size = New System.Drawing.Size(176, 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(11, 248)
		Me.Label9.Name = "Label9"
		Me.Label9.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label9.Size = New System.Drawing.Size(73, 14)
		Me.Label9.TabIndex = 11
		Me.Label9.Text = "Count Mode:"
		'
		'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(11, 220)
		Me.Label8.Name = "Label8"
		Me.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label8.Size = New System.Drawing.Size(97, 14)
		Me.Label8.TabIndex = 10
		Me.Label8.Text = "Digital Filter:"
		'
		'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(11, 192)
		Me.Label7.Name = "Label7"
		Me.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label7.Size = New System.Drawing.Size(42, 14)
		Me.Label7.TabIndex = 9
		Me.Label7.Text = "Clear:"
		'
		'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(11, 164)
		Me.Label6.Name = "Label6"
		Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label6.Size = New System.Drawing.Size(60, 14)
		Me.Label6.TabIndex = 8
		Me.Label6.Text = "Multiple:"
		'
		'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(11, 136)
		Me.Label5.Name = "Label5"
		Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label5.Size = New System.Drawing.Size(42, 14)
		Me.Label5.TabIndex = 7
		Me.Label5.Text = "Phase:"
		'
		'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(11, 108)
		Me.Label4.Name = "Label4"
		Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label4.Size = New System.Drawing.Size(103, 14)
		Me.Label4.TabIndex = 6
		Me.Label4.Text = "Count Direction:"
		'
		'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(11, 80)
		Me.Label3.Name = "Label3"
		Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label3.Size = New System.Drawing.Size(79, 14)
		Me.Label3.TabIndex = 5
		Me.Label3.Text = "Signal Type:"
		'
		'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(11, 52)
		Me.Label2.Name = "Label2"
		Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label2.Size = New System.Drawing.Size(91, 14)
		Me.Label2.TabIndex = 4
		Me.Label2.Text = "Z Phase Logic:"
		'
		'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(11, 24)
		Me.Label1.Name = "Label1"
		Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label1.Size = New System.Drawing.Size(85, 14)
		Me.Label1.TabIndex = 3
		Me.Label1.Text = "Z Phase Mode:"
		'
		'ModeDlg
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
		Me.ClientSize = New System.Drawing.Size(328, 358)
		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 = "Counter Mode Setting"
		Me.Frame1.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region

	'===================================================
	' Dialog initialization
	'===================================================
	Private Sub ModeDlg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		'===================================================
		' Initialize ComboBox
		'===================================================
		Dim i As Short
		' Z phase mode
		cboZPhaseMode.Items.Clear()
		cboZPhaseMode.Items.Insert(0, "Not Use")
		cboZPhaseMode.Items.Insert(1, "Next One")
		cboZPhaseMode.Items.Insert(2, "Every Time")

		' Z phase logic
		cboZPhaseLogic.Items.Clear()
		cboZPhaseLogic.Items.Insert(0, "Positive")
		cboZPhaseLogic.Items.Insert(1, "Negative")

		' Signal source
        cboSignalSource.Items.Clear()
        cboSignalSource.Items.Insert(0, "Photocoupler insulation")
        cboSignalSource.Items.Insert(1, "TTL")
        cboSignalSource.Items.Insert(2, "Line Receiver")

		' Count direction
		cboCountDirection.Items.Clear()
		cboCountDirection.Items.Insert(0, "Down Count")
		cboCountDirection.Items.Insert(1, "Up Count")
	
		' 1Phase/2Phase
		cboPhase.Items.Clear()
		cboPhase.Items.Insert(0, "1 Phase")
		cboPhase.Items.Insert(1, "2 Phase")
		cboPhase.Items.Insert(2, "Gate Control")

		' Mul
		cboMul.Items.Clear()
		cboMul.Items.Insert(0, "X1")
		cboMul.Items.Insert(1, "X2")
		cboMul.Items.Insert(2, "X4")

		' Sync clear
		cboSyncClear.Items.Clear()
		cboSyncClear.Items.Insert(0, "Async")
		cboSyncClear.Items.Insert(1, "Sync")

		' Filter
		cboFilter.Items.Clear()
		For i = 0 To 15
			cboFilter.Items.Insert(i, Hex(i))
		Next
	
		' Counter mode
		cboCounterMode.Items.Clear()
		cboCounterMode.Items.Insert(0, "Normal")
		cboCounterMode.Items.Insert(1, "Differencial")

		'-------------------------------
		' Set initial data
		'-------------------------------
		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

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

		'-------------------------------
		' Get setting information
		'-------------------------------
		'--------------------------------
		' Z phase mode
		'--------------------------------
		wZPhaseMode = 0
		If cboZPhaseMode.Text = "Not Use" Then wZPhaseMode = CNT_ZPHASE_NOT_USE
		If cboZPhaseMode.Text = "Next One" Then wZPhaseMode = CNT_ZPHASE_NEXT_ONE
		If cboZPhaseMode.Text = "Every Time" Then wZPhaseMode = CNT_ZPHASE_EVERY_TIME
		'--------------------------------
		' Z phase logic
		'--------------------------------
		wZPhaseLogic = 0
		If cboZPhaseLogic.Text = "Positive" Then wZPhaseLogic = CNT_ZLOGIC_POSITIVE
		If cboZPhaseLogic.Text = "Negative" Then wZPhaseLogic = CNT_ZLOGIC_NEGATIVE
		'--------------------------------
		' Signal source
		'--------------------------------
		wSignalSource = 0
		If cboSignalSource.Text = "Photocoupler insulation" Then wSignalSource = CNT_SIGTYPE_ISOLATE
		If cboSignalSource.Text = "TTL" Then wSignalSource = CNT_SIGTYPE_TTL
		If cboSignalSource.Text = "Line Receiver" Then wSignalSource = CNT_SIGTYPE_LINERECEIVER
		'--------------------------------
		' Count direction
		'--------------------------------
		wCountDirection = 0
		If cboCountDirection.Text = "Down Count" Then wCountDirection = CNT_DIR_DOWN
		If cboCountDirection.Text = "Up Count" Then wCountDirection = CNT_DIR_UP
		'--------------------------------
		' 1Phase/2Phase
		'--------------------------------
		wPhase = 0
		If cboPhase.Text = "1 Phase" Then wPhase = CNT_MODE_1PHASE
		If cboPhase.Text = "2 Phase" Then wPhase = CNT_MODE_2PHASE
		If cboPhase.Text = "Gate Control" Then wPhase = CNT_MODE_GATECONTROL
		'--------------------------------
		' Mul
		'--------------------------------
		wMul = 0
		If cboMul.Text = "X1" Then wMul = CNT_MUL_X1
		If cboMul.Text = "X2" Then wMul = CNT_MUL_X2
		If cboMul.Text = "X4" Then wMul = CNT_MUL_X4
		'--------------------------------
		' Sync clear
		'--------------------------------
		wSyncClear = 0
		If cboSyncClear.Text = "Async" Then wSyncClear = CNT_CLR_ASYNC
		If cboSyncClear.Text = "Sync" Then wSyncClear = CNT_CLR_SYNC
		'--------------------------------
		' Filter
		'--------------------------------
		wFilter = cboFilter.SelectedIndex
		'--------------------------------
		' Counter mode
		'--------------------------------
		wCounterMode = 0
		If cboCounterMode.Text = "Normal" Then wCounterMode = CNTS_MODE_NORMAL
		If cboCounterMode.Text = "Differencial" Then wCounterMode = CNTS_MODE_DIFF


		'-------------------------------
		' Set setting information to device
		'-------------------------------
		For ChNo = 0 To CHANNEL_NUM - 1
			'---------------------------------------------
			' Set Z phase mode
			'---------------------------------------------
			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
			'---------------------------------------------
			' Set Z phase logic
			'---------------------------------------------
			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
			'---------------------------------------------
			' Set signal source
			'---------------------------------------------
			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
			'---------------------------------------------
			' Set count direction
			'---------------------------------------------
			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
			'---------------------------------------------
			' Set 1Phase/2Phase
			'---------------------------------------------
			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
			'---------------------------------------------
			' Set filter
			'---------------------------------------------
			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
			'---------------------------------------------
			' Set counter mode
			'---------------------------------------------
			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

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