Option Strict Off
Option Explicit On 
Public Class Mode
    Inherits System.Windows.Forms.Form

#Region " Windows tH[ fUCiŐꂽR[h "

    Public Sub New()
        MyBase.New()

        ' ̌Ăяo Windows tH[ fUCiŕKvłB
        InitializeComponent()

        ' InitializeComponent() Ăяǒɏǉ܂B

    End Sub

    ' Form  dispose I[o[ChăR|[lgꗗ܂B
    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 tH[ fUCiŕKvłB
    Private components As System.ComponentModel.IContainer

    '  : ȉ̃vV[ẂAWindows tH[ fUCiŕKvłB
    ' Windows tH[ fUCigĕύXĂB  
    ' R[h GfB^͎gpȂłB
	Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
	Friend WithEvents Label1 As System.Windows.Forms.Label
	Friend WithEvents Label2 As System.Windows.Forms.Label
	Friend WithEvents Label3 As System.Windows.Forms.Label
	Friend WithEvents Label4 As System.Windows.Forms.Label
	Friend WithEvents Label5 As System.Windows.Forms.Label
	Friend WithEvents Label6 As System.Windows.Forms.Label
	Friend WithEvents Label7 As System.Windows.Forms.Label
	Friend WithEvents Label8 As System.Windows.Forms.Label
	Friend WithEvents Label9 As System.Windows.Forms.Label
	Friend WithEvents Label10 As System.Windows.Forms.Label
	Friend WithEvents cboClr As System.Windows.Forms.ComboBox
	Friend WithEvents cboMul As System.Windows.Forms.ComboBox
	Friend WithEvents txtFilter As System.Windows.Forms.TextBox
	Friend WithEvents cboPhase As System.Windows.Forms.ComboBox
	Friend WithEvents cboDir As System.Windows.Forms.ComboBox
	Friend WithEvents cboSource As System.Windows.Forms.ComboBox
	Friend WithEvents cboZLogic As System.Windows.Forms.ComboBox
	Friend WithEvents cboZMode As System.Windows.Forms.ComboBox
	Friend WithEvents cboChNo As System.Windows.Forms.ComboBox
	Friend WithEvents btnSet As System.Windows.Forms.Button
	Friend WithEvents btnCancel As System.Windows.Forms.Button
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.GroupBox1 = New System.Windows.Forms.GroupBox()
		Me.Label10 = New System.Windows.Forms.Label()
		Me.Label9 = New System.Windows.Forms.Label()
		Me.Label8 = New System.Windows.Forms.Label()
		Me.Label7 = New System.Windows.Forms.Label()
		Me.Label6 = New System.Windows.Forms.Label()
		Me.Label5 = New System.Windows.Forms.Label()
		Me.Label4 = New System.Windows.Forms.Label()
		Me.Label3 = New System.Windows.Forms.Label()
		Me.cboClr = New System.Windows.Forms.ComboBox()
		Me.cboMul = New System.Windows.Forms.ComboBox()
		Me.txtFilter = New System.Windows.Forms.TextBox()
		Me.cboPhase = New System.Windows.Forms.ComboBox()
		Me.cboDir = New System.Windows.Forms.ComboBox()
		Me.cboSource = New System.Windows.Forms.ComboBox()
		Me.cboZLogic = New System.Windows.Forms.ComboBox()
		Me.cboZMode = New System.Windows.Forms.ComboBox()
		Me.cboChNo = New System.Windows.Forms.ComboBox()
		Me.Label2 = New System.Windows.Forms.Label()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.btnSet = New System.Windows.Forms.Button()
		Me.btnCancel = New System.Windows.Forms.Button()
		Me.GroupBox1.SuspendLayout()
		Me.SuspendLayout()
		'
		'GroupBox1
		'
		Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label10, Me.Label9, Me.Label8, Me.Label7, Me.Label6, Me.Label5, Me.Label4, Me.Label3, Me.cboClr, Me.cboMul, Me.txtFilter, Me.cboPhase, Me.cboDir, Me.cboSource, Me.cboZLogic, Me.cboZMode, Me.cboChNo, Me.Label2, Me.Label1})
		Me.GroupBox1.Location = New System.Drawing.Point(16, 8)
		Me.GroupBox1.Name = "GroupBox1"
		Me.GroupBox1.Size = New System.Drawing.Size(320, 288)
		Me.GroupBox1.TabIndex = 0
		Me.GroupBox1.TabStop = False
		Me.GroupBox1.Text = "JE^[h"
		'
		'Label10
		'
		Me.Label10.Location = New System.Drawing.Point(286, 168)
		Me.Label10.Name = "Label10"
		Me.Label10.Size = New System.Drawing.Size(26, 15)
		Me.Label10.TabIndex = 18
		Me.Label10.Text = "Hex"
		'
		'Label9
		'
		Me.Label9.Location = New System.Drawing.Point(16, 253)
		Me.Label9.Name = "Label9"
		Me.Label9.Size = New System.Drawing.Size(85, 16)
		Me.Label9.TabIndex = 17
		Me.Label9.Text = "NAF"
		'
		'Label8
		'
		Me.Label8.Location = New System.Drawing.Point(16, 226)
		Me.Label8.Name = "Label8"
		Me.Label8.Size = New System.Drawing.Size(85, 16)
		Me.Label8.TabIndex = 16
		Me.Label8.Text = "{F"
		'
		'Label7
		'
		Me.Label7.Location = New System.Drawing.Point(16, 197)
		Me.Label7.Name = "Label7"
		Me.Label7.Size = New System.Drawing.Size(85, 16)
		Me.Label7.TabIndex = 15
		Me.Label7.Text = "F"
		'
		'Label6
		'
		Me.Label6.Location = New System.Drawing.Point(16, 168)
		Me.Label6.Name = "Label6"
		Me.Label6.Size = New System.Drawing.Size(96, 16)
		Me.Label6.TabIndex = 14
		Me.Label6.Text = "fW^tB^F"
		'
		'Label5
		'
		Me.Label5.Location = New System.Drawing.Point(16, 140)
		Me.Label5.Name = "Label5"
		Me.Label5.Size = New System.Drawing.Size(85, 16)
		Me.Label5.TabIndex = 13
		Me.Label5.Text = "JEgF"
		'
		'Label4
		'
		Me.Label4.Location = New System.Drawing.Point(16, 112)
		Me.Label4.Name = "Label4"
		Me.Label4.Size = New System.Drawing.Size(85, 16)
		Me.Label4.TabIndex = 12
		Me.Label4.Text = "MF"
		'
		'Label3
		'
		Me.Label3.Location = New System.Drawing.Point(16, 85)
		Me.Label3.Name = "Label3"
		Me.Label3.Size = New System.Drawing.Size(85, 16)
		Me.Label3.TabIndex = 11
		Me.Label3.Text = "Z_F"
		'
		'cboClr
		'
		Me.cboClr.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboClr.Location = New System.Drawing.Point(113, 248)
		Me.cboClr.Name = "cboClr"
		Me.cboClr.Size = New System.Drawing.Size(165, 20)
		Me.cboClr.TabIndex = 10
		'
		'cboMul
		'
		Me.cboMul.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboMul.Location = New System.Drawing.Point(113, 220)
		Me.cboMul.Name = "cboMul"
		Me.cboMul.Size = New System.Drawing.Size(165, 20)
		Me.cboMul.TabIndex = 9
		'
		'txtFilter
		'
		Me.txtFilter.Location = New System.Drawing.Point(113, 164)
		Me.txtFilter.Name = "txtFilter"
		Me.txtFilter.Size = New System.Drawing.Size(165, 19)
		Me.txtFilter.TabIndex = 8
		Me.txtFilter.Text = ""
		'
		'cboPhase
		'
		Me.cboPhase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboPhase.Location = New System.Drawing.Point(113, 192)
		Me.cboPhase.Name = "cboPhase"
		Me.cboPhase.Size = New System.Drawing.Size(165, 20)
		Me.cboPhase.TabIndex = 7
		'
		'cboDir
		'
		Me.cboDir.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboDir.Location = New System.Drawing.Point(113, 136)
		Me.cboDir.Name = "cboDir"
		Me.cboDir.Size = New System.Drawing.Size(165, 20)
		Me.cboDir.TabIndex = 6
		'
		'cboSource
		'
		Me.cboSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboSource.Location = New System.Drawing.Point(113, 108)
		Me.cboSource.Name = "cboSource"
		Me.cboSource.Size = New System.Drawing.Size(165, 20)
		Me.cboSource.TabIndex = 5
		'
		'cboZLogic
		'
		Me.cboZLogic.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboZLogic.Location = New System.Drawing.Point(113, 80)
		Me.cboZLogic.Name = "cboZLogic"
		Me.cboZLogic.Size = New System.Drawing.Size(165, 20)
		Me.cboZLogic.TabIndex = 4
		'
		'cboZMode
		'
		Me.cboZMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboZMode.Location = New System.Drawing.Point(113, 52)
		Me.cboZMode.Name = "cboZMode"
		Me.cboZMode.Size = New System.Drawing.Size(165, 20)
		Me.cboZMode.TabIndex = 3
		'
		'cboChNo
		'
		Me.cboChNo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboChNo.Location = New System.Drawing.Point(113, 24)
		Me.cboChNo.Name = "cboChNo"
		Me.cboChNo.Size = New System.Drawing.Size(165, 20)
		Me.cboChNo.TabIndex = 2
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(16, 56)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(85, 16)
		Me.Label2.TabIndex = 1
		Me.Label2.Text = "Z[hF"
		'
		'Label1
		'
		Me.Label1.Location = New System.Drawing.Point(16, 30)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(85, 16)
		Me.Label1.TabIndex = 0
		Me.Label1.Text = "`lԍF"
		'
		'btnSet
		'
		Me.btnSet.Location = New System.Drawing.Point(128, 320)
		Me.btnSet.Name = "btnSet"
		Me.btnSet.Size = New System.Drawing.Size(96, 24)
		Me.btnSet.TabIndex = 1
		Me.btnSet.Text = "ݒ"
		'
		'btnCancel
		'
		Me.btnCancel.Location = New System.Drawing.Point(240, 320)
		Me.btnCancel.Name = "btnCancel"
		Me.btnCancel.Size = New System.Drawing.Size(96, 24)
		Me.btnCancel.TabIndex = 2
		Me.btnCancel.Text = ""
		'
		'Mode
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
		Me.ClientSize = New System.Drawing.Size(346, 357)
		Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnSet, Me.GroupBox1})
		Me.Font = New System.Drawing.Font("lr oSVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "Mode"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "[hݒ"
		Me.GroupBox1.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region
    Dim Ret As Int32                            ' ߂l
    Dim szError As New System.Text.StringBuilder("", 256)   ' G[
	Dim szReturnCode As New String("", 256)		' \G[
	Dim szText As New String("", 256)			' e|

	Dim ChNo As Short
	Dim ZMode As Short
	Dim ZLogic As Short
	Dim SigType As Short
	Dim Dir As Short
	Dim Phase As Short
	Dim Mul As Short
	Dim SyncClr As Short
	Dim FilterValue As Short

	'---------------------------------------------------------
	' [h`
	'---------------------------------------------------------
	Private Structure StrNum
		Public Str As String
		Public Num As Short
		Public Sub New(ByVal Str As String, ByVal Num As Short)
			Me.Str = Str
			Me.Num = Num
		End Sub
	End Structure

	Dim cboZModeL() As StrNum = { _
												New StrNum("gp", CNT_ZPHASE_NOT_USE), _
												New StrNum("̂P", CNT_ZPHASE_NEXT_ONE), _
												New StrNum("", CNT_ZPHASE_EVERY_TIME), _
												New StrNum("End", 0) _
	}
	Dim cboZLogicL() As StrNum = { _
												New StrNum("_", CNT_ZLOGIC_POSITIVE), _
												New StrNum("_", CNT_ZLOGIC_NEGATIVE), _
												New StrNum("End", 0) _
	}
	Dim cboChannelSignalL() As StrNum = { _
												New StrNum("tHgJv≏", CNT_SIGTYPE_ISOLATE), _
												New StrNum("TTL", CNT_SIGTYPE_TTL), _
												New StrNum("", CNT_SIGTYPE_LINERECEIVER), _
												New StrNum("End", 0) _
	}
	Dim cboCntDirL() As StrNum = { _
												New StrNum("_EJEg", CNT_DIR_DOWN), _
												New StrNum("AbvJEg", CNT_DIR_UP), _
												New StrNum("End", 0) _
	}
	Dim cboPhaseL() As StrNum = { _
												New StrNum("P", CNT_MODE_1PHASE), _
												New StrNum("Q", CNT_MODE_2PHASE), _
												New StrNum("Q[gRg[", CNT_MODE_GATECONTROL), _
												New StrNum("End", 0) _
	}
	Dim cboMulL() As StrNum = { _
												New StrNum("P{", CNT_MUL_X1), _
												New StrNum("Q{", CNT_MUL_X2), _
												New StrNum("S{", CNT_MUL_X4), _
												New StrNum("End", 0) _
	}
	Dim cboSyncClrL() As StrNum = { _
												New StrNum("񓯊NA", CNT_CLR_ASYNC), _
												New StrNum("NA", CNT_CLR_SYNC), _
												New StrNum("End", 0) _
	}

	'---------------------------------------------------------
	'	Tu[`Fԍϊ
	'---------------------------------------------------------
	Private Function NumToStr(ByVal p() As StrNum, ByVal Num As Short) As String

		Dim i As Short
		Dim None As String = ""
		i = 0
		While (StrComp(p(i).Str, "End") <> 0)
			If p(i).Num = Num Then
				Return p(i).Str
			End If
			i += 1
		End While
		Return None

	End Function

	Private Function StrToNum(ByVal p() As StrNum, ByVal Str As String) As Short

		Dim i As Short
		i = 0
		While (StrComp(p(i).Str, "End") <> 0)
			If StrComp(p(i).Str, Str) = 0 Then
				Return p(i).Num
			End If
			i += 1
		End While
		Return 0

	End Function

	'---------------------------------------------------------
	'	_CAO
	'---------------------------------------------------------
	Private Sub Mode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		'-----------------------------------
		' R{{bNX̏
		'-----------------------------------
		Dim i As Short
		For i = 0 To (ChannelNum - 1)
			cboChNo.Items.Add(i)
		Next i
		cboChNo.SelectedIndex = 0
		i = 0
		While (StrComp(cboZModeL(i).Str, "End") <> 0)
			cboZMode.Items.Add(cboZModeL(i).Str)
			i += 1
		End While
		i = 0
		While (StrComp(cboZLogicL(i).Str, "End") <> 0)
			cboZLogic.Items.Add(cboZLogicL(i).Str)
			i += 1
		End While
		i = 0
		While (StrComp(cboChannelSignalL(i).Str, "End") <> 0)
			cboSource.Items.Add(cboChannelSignalL(i).Str)
			i += 1
		End While
		i = 0
		While (StrComp(cboCntDirL(i).Str, "End") <> 0)
			cboDir.Items.Add(cboCntDirL(i).Str)
			i += 1
		End While
		i = 0
		While (StrComp(cboPhaseL(i).Str, "End") <> 0)
			cboPhase.Items.Add(cboPhaseL(i).Str)
			i += 1
		End While
		i = 0
		While (StrComp(cboMulL(i).Str, "End") <> 0)
			cboMul.Items.Add(cboMulL(i).Str)
			i += 1
		End While
		i = 0
		While (StrComp(cboSyncClrL(i).Str, "End") <> 0)
			cboClr.Items.Add(cboSyncClrL(i).Str)
			i += 1
		End While
		'-----------------------------------
		' `l0I
		'-----------------------------------
		cboChNo_SelectionChangeCommitted(cboChNo, New System.EventArgs())

	End Sub

	'---------------------------------------------------------
	'	ݒ{^̏
	'---------------------------------------------------------
	Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click
		'-----------------------------------
		' ʂ烂[h擾
		'-----------------------------------
		szText = cboZMode.Text
		ZMode = StrToNum(cboZModeL, szText)
		szText = cboZLogic.Text
		ZLogic = StrToNum(cboZLogicL, szText)
		szText = cboSource.Text
		SigType = StrToNum(cboChannelSignalL, szText)
		szText = cboDir.Text
		Dir = StrToNum(cboCntDirL, szText)
		szText = cboPhase.Text
		Phase = StrToNum(cboPhaseL, szText)
		szText = cboMul.Text
		Mul = StrToNum(cboMulL, szText)
		szText = cboClr.Text
		SyncClr = StrToNum(cboSyncClrL, szText)
		szText = txtFilter.Text
        FilterValue = Short.Parse(szText, System.Globalization.NumberStyles.HexNumber)
        '-----------------------------------
		' [h̐ݒ
		'-----------------------------------
		Ret = CntSetZMode(Id, ChNo, ZMode)
		If Ret <> CNT_ERR_SUCCESS Then
			CntGetErrorString(Ret, szError)
            szReturnCode = "CntSetZMode : " & szError.ToString()
			MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
		End If
		Ret = CntSetZLogic(Id, ChNo, ZLogic)
		If Ret <> CNT_ERR_SUCCESS Then
			CntGetErrorString(Ret, szError)
            szReturnCode = "CntSetZLogic : " & szError.ToString()
			MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
		End If
		Ret = CntSelectChannelSignal(Id, ChNo, SigType)
		If Ret <> CNT_ERR_SUCCESS Then
			CntGetErrorString(Ret, szError)
            szReturnCode = "CntSelectChannelSignal : " & szError.ToString()
			MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
		End If
		Ret = CntSetCountDirection(Id, ChNo, Dir)
		If Ret <> CNT_ERR_SUCCESS Then
			CntGetErrorString(Ret, szError)
            szReturnCode = "CntSetCountDirection : " & szError.ToString()
			MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
		End If
		Ret = CntSetOperationMode(Id, ChNo, Phase, Mul, SyncClr)
		If Ret <> CNT_ERR_SUCCESS Then
			CntGetErrorString(Ret, szError)
            szReturnCode = "CntSetOperationMode : " & szError.ToString()
			MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
		End If
		Ret = CntSetDigitalFilter(Id, ChNo, FilterValue)
		If Ret <> CNT_ERR_SUCCESS Then
			CntGetErrorString(Ret, szError)
            szReturnCode = "CntSetDigitalFilter : " & szError.ToString()
			MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
		End If

		Me.Close()

	End Sub

	'---------------------------------------------------------
	'	LZ{^̏
	'---------------------------------------------------------
	Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

		Me.Close()

	End Sub

	'---------------------------------------------------------
	'	`lR{{bNXI
	'---------------------------------------------------------
	Private Sub cboChNo_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboChNo.SelectionChangeCommitted

		'-----------------------------------
		' [h̎擾
		'-----------------------------------
		ChNo = CShort(cboChNo.Text)

		CntGetZMode(Id, ChNo, ZMode)
		CntGetZLogic(Id, ChNo, ZLogic)
		CntGetChannelSignal(Id, ChNo, SigType)
		CntGetCountDirection(Id, ChNo, Dir)
		CntGetOperationMode(Id, ChNo, Phase, Mul, SyncClr)
		CntGetDigitalFilter(Id, ChNo, FilterValue)
		'-----------------------------------
		' [h̐ݒ
		'-----------------------------------
		cboZMode.Text = NumToStr(cboZModeL, ZMode)
		cboZLogic.Text = NumToStr(cboZLogicL, ZLogic)
		cboSource.Text = NumToStr(cboChannelSignalL, SigType)
		cboDir.Text = NumToStr(cboCntDirL, Dir)
		cboPhase.Text = NumToStr(cboPhaseL, Phase)
		cboMul.Text = NumToStr(cboMulL, Mul)
		cboClr.Text = NumToStr(cboSyncClrL, SyncClr)
		txtFilter.Text = Hex(FilterValue)

	End Sub
End Class