Public Class KDIOForm
    Inherits System.Windows.Forms.Form

    Private DevId As Integer         'Device Id
    Private DOUTStatus(1) As Byte    'Digital Output Status
    'チェックボックスコントロール用配列を作成
    Private P1OUT() As System.Windows.Forms.CheckBox
    Private P2OUT() As System.Windows.Forms.CheckBox
    'ラベルコントロール用配列を作成
    Private P1ST() As System.Windows.Forms.Label
    Private P2ST() As System.Windows.Forms.Label

#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 フォーム デザイナを使って変更してください。  
    ' コード エディタは使用しないでください。
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents P1IOSEL1 As System.Windows.Forms.RadioButton
    Friend WithEvents P1IOSEL2 As System.Windows.Forms.RadioButton
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents P1OUT0 As System.Windows.Forms.CheckBox
    Friend WithEvents P1OUT1 As System.Windows.Forms.CheckBox
    Friend WithEvents P1OUT2 As System.Windows.Forms.CheckBox
    Friend WithEvents P1OUT3 As System.Windows.Forms.CheckBox
    Friend WithEvents P1OUT4 As System.Windows.Forms.CheckBox
    Friend WithEvents P1OUT5 As System.Windows.Forms.CheckBox
    Friend WithEvents P1OUT6 As System.Windows.Forms.CheckBox
    Friend WithEvents P1OUT7 As System.Windows.Forms.CheckBox
    Friend WithEvents P1ST0 As System.Windows.Forms.Label
    Friend WithEvents P1ST1 As System.Windows.Forms.Label
    Friend WithEvents P1ST2 As System.Windows.Forms.Label
    Friend WithEvents P1ST3 As System.Windows.Forms.Label
    Friend WithEvents P1ST4 As System.Windows.Forms.Label
    Friend WithEvents P1ST5 As System.Windows.Forms.Label
    Friend WithEvents P1ST6 As System.Windows.Forms.Label
    Friend WithEvents P1ST7 As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents Label12 As System.Windows.Forms.Label
    Friend WithEvents P2IOSEL2 As System.Windows.Forms.RadioButton
    Friend WithEvents P2IOSEL1 As System.Windows.Forms.RadioButton
    Friend WithEvents P2OUT7 As System.Windows.Forms.CheckBox
    Friend WithEvents P2OUT6 As System.Windows.Forms.CheckBox
    Friend WithEvents P2OUT5 As System.Windows.Forms.CheckBox
    Friend WithEvents P2OUT4 As System.Windows.Forms.CheckBox
    Friend WithEvents P2OUT3 As System.Windows.Forms.CheckBox
    Friend WithEvents P2OUT2 As System.Windows.Forms.CheckBox
    Friend WithEvents P2OUT1 As System.Windows.Forms.CheckBox
    Friend WithEvents P2OUT0 As System.Windows.Forms.CheckBox
    Friend WithEvents P2ST7 As System.Windows.Forms.Label
    Friend WithEvents P2ST6 As System.Windows.Forms.Label
    Friend WithEvents P2ST5 As System.Windows.Forms.Label
    Friend WithEvents P2ST4 As System.Windows.Forms.Label
    Friend WithEvents P2ST3 As System.Windows.Forms.Label
    Friend WithEvents P2ST2 As System.Windows.Forms.Label
    Friend WithEvents P2ST1 As System.Windows.Forms.Label
    Friend WithEvents P2ST0 As System.Windows.Forms.Label
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.P1ST7 = New System.Windows.Forms.Label()
        Me.P1ST6 = New System.Windows.Forms.Label()
        Me.P1ST5 = New System.Windows.Forms.Label()
        Me.P1ST4 = New System.Windows.Forms.Label()
        Me.P1ST3 = New System.Windows.Forms.Label()
        Me.P1ST2 = New System.Windows.Forms.Label()
        Me.P1ST1 = New System.Windows.Forms.Label()
        Me.P1ST0 = New System.Windows.Forms.Label()
        Me.P1OUT7 = New System.Windows.Forms.CheckBox()
        Me.P1OUT6 = New System.Windows.Forms.CheckBox()
        Me.P1OUT5 = New System.Windows.Forms.CheckBox()
        Me.P1OUT4 = New System.Windows.Forms.CheckBox()
        Me.P1OUT3 = New System.Windows.Forms.CheckBox()
        Me.P1OUT2 = New System.Windows.Forms.CheckBox()
        Me.P1OUT1 = New System.Windows.Forms.CheckBox()
        Me.P1OUT0 = New System.Windows.Forms.CheckBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.P1IOSEL2 = New System.Windows.Forms.RadioButton()
        Me.P1IOSEL1 = New System.Windows.Forms.RadioButton()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.P2ST7 = New System.Windows.Forms.Label()
        Me.P2ST6 = New System.Windows.Forms.Label()
        Me.P2ST5 = New System.Windows.Forms.Label()
        Me.P2ST4 = New System.Windows.Forms.Label()
        Me.P2ST3 = New System.Windows.Forms.Label()
        Me.P2ST2 = New System.Windows.Forms.Label()
        Me.P2ST1 = New System.Windows.Forms.Label()
        Me.P2ST0 = New System.Windows.Forms.Label()
        Me.P2OUT7 = New System.Windows.Forms.CheckBox()
        Me.P2OUT6 = New System.Windows.Forms.CheckBox()
        Me.P2OUT5 = New System.Windows.Forms.CheckBox()
        Me.P2OUT4 = New System.Windows.Forms.CheckBox()
        Me.P2OUT3 = New System.Windows.Forms.CheckBox()
        Me.P2OUT2 = New System.Windows.Forms.CheckBox()
        Me.P2OUT1 = New System.Windows.Forms.CheckBox()
        Me.P2OUT0 = New System.Windows.Forms.CheckBox()
        Me.Label11 = New System.Windows.Forms.Label()
        Me.Label12 = New System.Windows.Forms.Label()
        Me.P2IOSEL2 = New System.Windows.Forms.RadioButton()
        Me.P2IOSEL1 = New System.Windows.Forms.RadioButton()
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.P1ST7, Me.P1ST6, Me.P1ST5, Me.P1ST4, Me.P1ST3, Me.P1ST2, Me.P1ST1, Me.P1ST0, Me.P1OUT7, Me.P1OUT6, Me.P1OUT5, Me.P1OUT4, Me.P1OUT3, Me.P1OUT2, Me.P1OUT1, Me.P1OUT0, Me.Label2, Me.Label1, Me.P1IOSEL2, Me.P1IOSEL1})
        Me.GroupBox1.Location = New System.Drawing.Point(8, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(144, 216)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Port1"
        '
        'P1ST7
        '
        Me.P1ST7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST7.Location = New System.Drawing.Point(72, 192)
        Me.P1ST7.Name = "P1ST7"
        Me.P1ST7.Size = New System.Drawing.Size(48, 16)
        Me.P1ST7.TabIndex = 19
        '
        'P1ST6
        '
        Me.P1ST6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST6.Location = New System.Drawing.Point(72, 176)
        Me.P1ST6.Name = "P1ST6"
        Me.P1ST6.Size = New System.Drawing.Size(48, 16)
        Me.P1ST6.TabIndex = 18
        '
        'P1ST5
        '
        Me.P1ST5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST5.Location = New System.Drawing.Point(72, 160)
        Me.P1ST5.Name = "P1ST5"
        Me.P1ST5.Size = New System.Drawing.Size(48, 16)
        Me.P1ST5.TabIndex = 17
        '
        'P1ST4
        '
        Me.P1ST4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST4.Location = New System.Drawing.Point(72, 144)
        Me.P1ST4.Name = "P1ST4"
        Me.P1ST4.Size = New System.Drawing.Size(48, 16)
        Me.P1ST4.TabIndex = 16
        '
        'P1ST3
        '
        Me.P1ST3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST3.Location = New System.Drawing.Point(72, 128)
        Me.P1ST3.Name = "P1ST3"
        Me.P1ST3.Size = New System.Drawing.Size(48, 16)
        Me.P1ST3.TabIndex = 15
        '
        'P1ST2
        '
        Me.P1ST2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST2.Location = New System.Drawing.Point(72, 112)
        Me.P1ST2.Name = "P1ST2"
        Me.P1ST2.Size = New System.Drawing.Size(48, 16)
        Me.P1ST2.TabIndex = 14
        '
        'P1ST1
        '
        Me.P1ST1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST1.Location = New System.Drawing.Point(72, 96)
        Me.P1ST1.Name = "P1ST1"
        Me.P1ST1.Size = New System.Drawing.Size(48, 16)
        Me.P1ST1.TabIndex = 13
        '
        'P1ST0
        '
        Me.P1ST0.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P1ST0.Location = New System.Drawing.Point(72, 80)
        Me.P1ST0.Name = "P1ST0"
        Me.P1ST0.Size = New System.Drawing.Size(48, 16)
        Me.P1ST0.TabIndex = 12
        '
        'P1OUT7
        '
        Me.P1OUT7.Location = New System.Drawing.Point(24, 192)
        Me.P1OUT7.Name = "P1OUT7"
        Me.P1OUT7.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT7.TabIndex = 11
        Me.P1OUT7.Text = "7"
        '
        'P1OUT6
        '
        Me.P1OUT6.Location = New System.Drawing.Point(24, 176)
        Me.P1OUT6.Name = "P1OUT6"
        Me.P1OUT6.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT6.TabIndex = 10
        Me.P1OUT6.Text = "6"
        '
        'P1OUT5
        '
        Me.P1OUT5.Location = New System.Drawing.Point(24, 160)
        Me.P1OUT5.Name = "P1OUT5"
        Me.P1OUT5.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT5.TabIndex = 9
        Me.P1OUT5.Text = "5"
        '
        'P1OUT4
        '
        Me.P1OUT4.Location = New System.Drawing.Point(24, 144)
        Me.P1OUT4.Name = "P1OUT4"
        Me.P1OUT4.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT4.TabIndex = 8
        Me.P1OUT4.Text = "4"
        '
        'P1OUT3
        '
        Me.P1OUT3.Location = New System.Drawing.Point(24, 128)
        Me.P1OUT3.Name = "P1OUT3"
        Me.P1OUT3.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT3.TabIndex = 7
        Me.P1OUT3.Text = "3"
        '
        'P1OUT2
        '
        Me.P1OUT2.Location = New System.Drawing.Point(24, 112)
        Me.P1OUT2.Name = "P1OUT2"
        Me.P1OUT2.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT2.TabIndex = 6
        Me.P1OUT2.Text = "2"
        '
        'P1OUT1
        '
        Me.P1OUT1.Location = New System.Drawing.Point(24, 96)
        Me.P1OUT1.Name = "P1OUT1"
        Me.P1OUT1.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT1.TabIndex = 5
        Me.P1OUT1.Text = "1"
        '
        'P1OUT0
        '
        Me.P1OUT0.Location = New System.Drawing.Point(24, 80)
        Me.P1OUT0.Name = "P1OUT0"
        Me.P1OUT0.Size = New System.Drawing.Size(32, 16)
        Me.P1OUT0.TabIndex = 4
        Me.P1OUT0.Text = "0"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(80, 56)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 16)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Status"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 56)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(48, 16)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Output"
        '
        'P1IOSEL2
        '
        Me.P1IOSEL2.Location = New System.Drawing.Point(72, 16)
        Me.P1IOSEL2.Name = "P1IOSEL2"
        Me.P1IOSEL2.Size = New System.Drawing.Size(64, 24)
        Me.P1IOSEL2.TabIndex = 1
        Me.P1IOSEL2.Text = "Output"
        '
        'P1IOSEL1
        '
        Me.P1IOSEL1.Location = New System.Drawing.Point(8, 16)
        Me.P1IOSEL1.Name = "P1IOSEL1"
        Me.P1IOSEL1.Size = New System.Drawing.Size(56, 24)
        Me.P1IOSEL1.TabIndex = 0
        Me.P1IOSEL1.Text = "Input"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.P2ST7, Me.P2ST6, Me.P2ST5, Me.P2ST4, Me.P2ST3, Me.P2ST2, Me.P2ST1, Me.P2ST0, Me.P2OUT7, Me.P2OUT6, Me.P2OUT5, Me.P2OUT4, Me.P2OUT3, Me.P2OUT2, Me.P2OUT1, Me.P2OUT0, Me.Label11, Me.Label12, Me.P2IOSEL2, Me.P2IOSEL1})
        Me.GroupBox2.Location = New System.Drawing.Point(160, 16)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(144, 216)
        Me.GroupBox2.TabIndex = 1
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Port2"
        '
        'P2ST7
        '
        Me.P2ST7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST7.Location = New System.Drawing.Point(72, 192)
        Me.P2ST7.Name = "P2ST7"
        Me.P2ST7.Size = New System.Drawing.Size(48, 16)
        Me.P2ST7.TabIndex = 19
        '
        'P2ST6
        '
        Me.P2ST6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST6.Location = New System.Drawing.Point(72, 176)
        Me.P2ST6.Name = "P2ST6"
        Me.P2ST6.Size = New System.Drawing.Size(48, 16)
        Me.P2ST6.TabIndex = 18
        '
        'P2ST5
        '
        Me.P2ST5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST5.Location = New System.Drawing.Point(72, 160)
        Me.P2ST5.Name = "P2ST5"
        Me.P2ST5.Size = New System.Drawing.Size(48, 16)
        Me.P2ST5.TabIndex = 17
        '
        'P2ST4
        '
        Me.P2ST4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST4.Location = New System.Drawing.Point(72, 144)
        Me.P2ST4.Name = "P2ST4"
        Me.P2ST4.Size = New System.Drawing.Size(48, 16)
        Me.P2ST4.TabIndex = 16
        '
        'P2ST3
        '
        Me.P2ST3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST3.Location = New System.Drawing.Point(72, 128)
        Me.P2ST3.Name = "P2ST3"
        Me.P2ST3.Size = New System.Drawing.Size(48, 16)
        Me.P2ST3.TabIndex = 15
        '
        'P2ST2
        '
        Me.P2ST2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST2.Location = New System.Drawing.Point(72, 112)
        Me.P2ST2.Name = "P2ST2"
        Me.P2ST2.Size = New System.Drawing.Size(48, 16)
        Me.P2ST2.TabIndex = 14
        '
        'P2ST1
        '
        Me.P2ST1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST1.Location = New System.Drawing.Point(72, 96)
        Me.P2ST1.Name = "P2ST1"
        Me.P2ST1.Size = New System.Drawing.Size(48, 16)
        Me.P2ST1.TabIndex = 13
        '
        'P2ST0
        '
        Me.P2ST0.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.P2ST0.Location = New System.Drawing.Point(72, 80)
        Me.P2ST0.Name = "P2ST0"
        Me.P2ST0.Size = New System.Drawing.Size(48, 16)
        Me.P2ST0.TabIndex = 12
        '
        'P2OUT7
        '
        Me.P2OUT7.Location = New System.Drawing.Point(24, 192)
        Me.P2OUT7.Name = "P2OUT7"
        Me.P2OUT7.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT7.TabIndex = 11
        Me.P2OUT7.Text = "7"
        '
        'P2OUT6
        '
        Me.P2OUT6.Location = New System.Drawing.Point(24, 176)
        Me.P2OUT6.Name = "P2OUT6"
        Me.P2OUT6.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT6.TabIndex = 10
        Me.P2OUT6.Text = "6"
        '
        'P2OUT5
        '
        Me.P2OUT5.Location = New System.Drawing.Point(24, 160)
        Me.P2OUT5.Name = "P2OUT5"
        Me.P2OUT5.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT5.TabIndex = 9
        Me.P2OUT5.Text = "5"
        '
        'P2OUT4
        '
        Me.P2OUT4.Location = New System.Drawing.Point(24, 144)
        Me.P2OUT4.Name = "P2OUT4"
        Me.P2OUT4.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT4.TabIndex = 8
        Me.P2OUT4.Text = "4"
        '
        'P2OUT3
        '
        Me.P2OUT3.Location = New System.Drawing.Point(24, 128)
        Me.P2OUT3.Name = "P2OUT3"
        Me.P2OUT3.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT3.TabIndex = 7
        Me.P2OUT3.Text = "3"
        '
        'P2OUT2
        '
        Me.P2OUT2.Location = New System.Drawing.Point(24, 112)
        Me.P2OUT2.Name = "P2OUT2"
        Me.P2OUT2.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT2.TabIndex = 6
        Me.P2OUT2.Text = "2"
        '
        'P2OUT1
        '
        Me.P2OUT1.Location = New System.Drawing.Point(24, 96)
        Me.P2OUT1.Name = "P2OUT1"
        Me.P2OUT1.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT1.TabIndex = 5
        Me.P2OUT1.Text = "1"
        '
        'P2OUT0
        '
        Me.P2OUT0.Location = New System.Drawing.Point(24, 80)
        Me.P2OUT0.Name = "P2OUT0"
        Me.P2OUT0.Size = New System.Drawing.Size(32, 16)
        Me.P2OUT0.TabIndex = 4
        Me.P2OUT0.Text = "0"
        '
        'Label11
        '
        Me.Label11.Location = New System.Drawing.Point(80, 56)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(48, 16)
        Me.Label11.TabIndex = 3
        Me.Label11.Text = "Status"
        '
        'Label12
        '
        Me.Label12.Location = New System.Drawing.Point(16, 56)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(48, 16)
        Me.Label12.TabIndex = 2
        Me.Label12.Text = "Output"
        '
        'P2IOSEL2
        '
        Me.P2IOSEL2.Location = New System.Drawing.Point(72, 16)
        Me.P2IOSEL2.Name = "P2IOSEL2"
        Me.P2IOSEL2.Size = New System.Drawing.Size(64, 24)
        Me.P2IOSEL2.TabIndex = 1
        Me.P2IOSEL2.Text = "Output"
        '
        'P2IOSEL1
        '
        Me.P2IOSEL1.Location = New System.Drawing.Point(8, 16)
        Me.P2IOSEL1.Name = "P2IOSEL1"
        Me.P2IOSEL1.Size = New System.Drawing.Size(56, 24)
        Me.P2IOSEL1.TabIndex = 0
        Me.P2IOSEL1.Text = "Input"
        '
        'Timer1
        '
        '
        'KDIOForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(312, 246)
        Me.ControlBox = False
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.GroupBox1})
        Me.Name = "KDIOForm"
        Me.Text = "KDIOForm"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    'This Form module initialize
    Public Sub SetId(ByVal Id As Short)
        Dim retErr As Integer
        Dim Dir1 As Byte
        Dim Dir2 As Byte
        Dim Bit As Byte
        Dim Mask As Integer

        DevId = Id

        Me.Text = "ID = " + CStr(DevId) + "  Panel"

        retErr = TUSBK16DIO_DirRead(DevId, Dir1, Dir2)
        If retErr Then
            TUSBK02AD_ErrorDisp(retErr)
            Me.Close()
            Exit Sub
        End If

        If Dir1 Then
            P1IOSEL2.Checked = True
        Else
            P1IOSEL1.Checked = True
        End If

        If Dir2 Then
            P2IOSEL2.Checked = True
        Else
            P2IOSEL1.Checked = True
        End If

        retErr = TUSBK16DIO_OutputRead(DevId, DOUTStatus(0), DOUTStatus(1))
        If retErr Then
            TUSBK02AD_ErrorDisp(retErr)
            Me.Close()
            Exit Sub
        Else
            Mask = 1
            For Bit = 0 To 7
                If DOUTStatus(0) And Mask Then
                    P1OUT(Bit).Checked = True
                End If
                If DOUTStatus(1) And Mask Then
                    P2OUT(Bit).Checked = True
                End If
                Mask = Mask * 2
            Next Bit
        End If

        IoCheck()

        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub

    Private Sub KDIOForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim bit As Integer

        'チェックボックスのインスタンスを配列にコピーして配列化する
        Me.P1OUT = New System.Windows.Forms.CheckBox() _
            {Me.P1OUT0, Me.P1OUT1, Me.P1OUT2, Me.P1OUT3, _
            Me.P1OUT4, Me.P1OUT5, Me.P1OUT6, Me.P1OUT7}
        Me.P2OUT = New System.Windows.Forms.CheckBox() _
            {Me.P2OUT0, Me.P2OUT1, Me.P2OUT2, Me.P2OUT3, _
            Me.P2OUT4, Me.P2OUT5, Me.P2OUT6, Me.P2OUT7}
        'ラベルコントロールのインスタンスを配列にコピーして配列化する
        Me.P1ST = New System.Windows.Forms.Label() _
            {Me.P1ST0, Me.P1ST1, Me.P1ST2, Me.P1ST3, _
            Me.P1ST4, Me.P1ST5, Me.P1ST6, Me.P1ST7}
        Me.P2ST = New System.Windows.Forms.Label() _
            {Me.P2ST0, Me.P2ST1, Me.P2ST2, Me.P2ST3, _
            Me.P2ST4, Me.P2ST5, Me.P2ST6, Me.P2ST7}
    End Sub

    Private Sub IoCheck()
        Dim retErr As Short
        Dim Data1 As Byte
        Dim Data2 As Byte
        Dim Bit As Short
        Dim Mask As Short

        retErr = TUSBK16DIO_Read(DevId, Data1, Data2)

        Mask = 1

        For Bit = 0 To 7
            If Data1 And Mask Then
                P1ST(Bit).Text = "High"
            Else
                P1ST(Bit).Text = "Low"
            End If

            If Data2 And Mask Then
                P2ST(Bit).Text = "High"
            Else
                P2ST(Bit).Text = "Low"
            End If

            Mask = Mask * 2
        Next Bit
    End Sub

    Private Sub P1IOSEL1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles P1IOSEL1.CheckedChanged
        Dim retErr As Short
        Dim Bit As Short

        If sender.Checked Then
            retErr = TUSBK16DIO_Dir(DevId, 0, 0)
            If retErr Then
                TUSBK02AD_ErrorDisp(retErr)
            End If
        End If
    End Sub

    Private Sub P1IOSEL2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles P1IOSEL2.CheckedChanged
        Dim retErr As Short
        Dim Bit As Short

        If sender.Checked Then
            retErr = TUSBK16DIO_Dir(DevId, 0, 1)
            If retErr Then
                TUSBK02AD_ErrorDisp(retErr)
            End If
        End If
    End Sub

    Private Sub P1OUT_Changed(ByVal index As Integer)
        Dim retErr As Short
        Dim tmpB As Byte

        tmpB = 2 ^ index

        If P1OUT(index).CheckState Then
            DOUTStatus(0) = DOUTStatus(0) Or tmpB
        Else
            DOUTStatus(0) = DOUTStatus(0) And (Not tmpB)
        End If

        retErr = TUSBK16DIO_PortWrite(DevId, 0, DOUTStatus(0))

        If retErr Then
            TUSBK02AD_ErrorDisp(retErr)
        End If
    End Sub

    Private Sub P1OUT0_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT0.CheckStateChanged
        P1OUT_Changed(0)
    End Sub
    Private Sub P1OUT1_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT1.CheckStateChanged
        P1OUT_Changed(1)
    End Sub
    Private Sub P1OUT2_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT2.CheckStateChanged
        P1OUT_Changed(2)
    End Sub
    Private Sub P1OUT3_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT3.CheckStateChanged
        P1OUT_Changed(3)
    End Sub
    Private Sub P1OUT4_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT4.CheckStateChanged
        P1OUT_Changed(4)
    End Sub
    Private Sub P1OUT5_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT5.CheckStateChanged
        P1OUT_Changed(5)
    End Sub
    Private Sub P1OUT6_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT6.CheckStateChanged
        P1OUT_Changed(6)
    End Sub
    Private Sub P1OUT7_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P1OUT7.CheckStateChanged
        P1OUT_Changed(7)
    End Sub

    Private Sub P2IOSEL1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles P2IOSEL1.CheckedChanged
        Dim retErr As Short
        Dim Bit As Short

        If sender.Checked Then
            retErr = TUSBK16DIO_Dir(DevId, 1, 0)
            If retErr Then
                TUSBK02AD_ErrorDisp(retErr)
            End If
        End If
    End Sub

    Private Sub P2IOSEL2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles P2IOSEL2.CheckedChanged
        Dim retErr As Short
        Dim Bit As Short

        If sender.Checked Then
            retErr = TUSBK16DIO_Dir(DevId, 1, 1)
            If retErr Then
                TUSBK02AD_ErrorDisp(retErr)
            End If
        End If
    End Sub

    Private Sub P2OUT_Changed(ByVal index As Integer)
        Dim retErr As Short
        Dim tmpB As Byte

        tmpB = 2 ^ index

        If P2OUT(index).CheckState Then
            DOUTStatus(1) = DOUTStatus(1) Or tmpB
        Else
            DOUTStatus(1) = DOUTStatus(1) And (Not tmpB)
        End If

        retErr = TUSBK16DIO_PortWrite(DevId, 1, DOUTStatus(1))

        If retErr Then
            TUSBK02AD_ErrorDisp(retErr)
        End If
    End Sub

    Private Sub P2OUT0_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT0.CheckStateChanged
        P2OUT_Changed(0)
    End Sub
    Private Sub P2OUT1_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT1.CheckStateChanged
        P2OUT_Changed(1)
    End Sub
    Private Sub P2OUT2_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT2.CheckStateChanged
        P2OUT_Changed(2)
    End Sub
    Private Sub P2OUT3_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT3.CheckStateChanged
        P2OUT_Changed(3)
    End Sub
    Private Sub P2OUT4_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT4.CheckStateChanged
        P2OUT_Changed(4)
    End Sub
    Private Sub P2OUT5_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT5.CheckStateChanged
        P2OUT_Changed(5)
    End Sub
    Private Sub P2OUT6_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT6.CheckStateChanged
        P2OUT_Changed(6)
    End Sub
    Private Sub P2OUT7_CheckStateChanged _
        (ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles P2OUT7.CheckStateChanged
        P2OUT_Changed(7)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If TUSBK16DIO_Chk(DevId) <> 0 Then
            Me.Hide()
            Exit Sub
        End If
        IoCheck()
    End Sub
End Class
