﻿Imports VB = Microsoft.VisualBasic
Imports System.Text
Imports System.Runtime.InteropServices

Public Class frmCounter
    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 Frame2 As System.Windows.Forms.GroupBox
    Public WithEvents lblNotify As System.Windows.Forms.Label
    Public WithEvents btnCntExit As System.Windows.Forms.Button
    Public WithEvents btnCntNotify As System.Windows.Forms.Button
    Public WithEvents btnCntMode As System.Windows.Forms.Button
    Public WithEvents btnCntInit As System.Windows.Forms.Button
    Public WithEvents Label6 As System.Windows.Forms.Label
    Public WithEvents txtRet As System.Windows.Forms.TextBox
    Public WithEvents Frame1 As System.Windows.Forms.GroupBox
    Public WithEvents txtCountValue0 As System.Windows.Forms.TextBox
    Public WithEvents txtCountValue3 As System.Windows.Forms.TextBox
    Public WithEvents txtCountValue2 As System.Windows.Forms.TextBox
    Public WithEvents txtCountValue1 As System.Windows.Forms.TextBox
    Public WithEvents Label2 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 btnCntStop As System.Windows.Forms.Button
    Public WithEvents btnCntReset As System.Windows.Forms.Button
    Public WithEvents btnCntPreset As System.Windows.Forms.Button
    Public WithEvents btnCntStart As System.Windows.Forms.Button
    Public WithEvents txtDeviceName As System.Windows.Forms.TextBox
    Public WithEvents Label1 As System.Windows.Forms.Label
    Public WithEvents btnCntEvent As System.Windows.Forms.Button
    Public WithEvents btnExit As System.Windows.Forms.Button
    Public WithEvents txtCountStatus0 As System.Windows.Forms.TextBox
    Public WithEvents txtCountStatus1 As System.Windows.Forms.TextBox
    Public WithEvents txtCountStatus2 As System.Windows.Forms.TextBox
    Private WithEvents timer1 As System.Windows.Forms.Timer
    Public WithEvents txtCountStatus3 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.Frame2 = New System.Windows.Forms.GroupBox
        Me.lblNotify = New System.Windows.Forms.Label
        Me.btnCntExit = New System.Windows.Forms.Button
        Me.btnCntNotify = New System.Windows.Forms.Button
        Me.btnCntMode = New System.Windows.Forms.Button
        Me.btnCntInit = New System.Windows.Forms.Button
        Me.Label6 = New System.Windows.Forms.Label
        Me.txtRet = New System.Windows.Forms.TextBox
        Me.Frame1 = New System.Windows.Forms.GroupBox
        Me.txtCountStatus3 = New System.Windows.Forms.TextBox
        Me.txtCountStatus2 = New System.Windows.Forms.TextBox
        Me.txtCountStatus1 = New System.Windows.Forms.TextBox
        Me.txtCountStatus0 = New System.Windows.Forms.TextBox
        Me.txtCountValue0 = New System.Windows.Forms.TextBox
        Me.txtCountValue3 = New System.Windows.Forms.TextBox
        Me.txtCountValue2 = New System.Windows.Forms.TextBox
        Me.txtCountValue1 = New System.Windows.Forms.TextBox
        Me.Label2 = 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.btnCntStop = New System.Windows.Forms.Button
        Me.btnCntReset = New System.Windows.Forms.Button
        Me.btnCntPreset = New System.Windows.Forms.Button
        Me.btnCntStart = New System.Windows.Forms.Button
        Me.txtDeviceName = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnCntEvent = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Frame2.SuspendLayout()
        Me.Frame1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Frame2
        '
        Me.Frame2.BackColor = System.Drawing.SystemColors.Control
        Me.Frame2.Controls.Add(Me.lblNotify)
        Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame2.Location = New System.Drawing.Point(13, 186)
        Me.Frame2.Name = "Frame2"
        Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame2.Size = New System.Drawing.Size(273, 129)
        Me.Frame2.TabIndex = 52
        Me.Frame2.TabStop = False
        Me.Frame2.Text = "通知："
        '
        'lblNotify
        '
        Me.lblNotify.BackColor = System.Drawing.SystemColors.Control
        Me.lblNotify.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblNotify.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblNotify.Location = New System.Drawing.Point(8, 24)
        Me.lblNotify.Name = "lblNotify"
        Me.lblNotify.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblNotify.Size = New System.Drawing.Size(249, 89)
        Me.lblNotify.TabIndex = 20
        Me.lblNotify.Text = "Notification:"
        '
        'btnCntExit
        '
        Me.btnCntExit.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntExit.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntExit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntExit.Location = New System.Drawing.Point(306, 290)
        Me.btnCntExit.Name = "btnCntExit"
        Me.btnCntExit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntExit.Size = New System.Drawing.Size(105, 24)
        Me.btnCntExit.TabIndex = 49
        Me.btnCntExit.Text = "CntExit"
        Me.btnCntExit.UseVisualStyleBackColor = False
        '
        'btnCntNotify
        '
        Me.btnCntNotify.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntNotify.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntNotify.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntNotify.Location = New System.Drawing.Point(306, 80)
        Me.btnCntNotify.Name = "btnCntNotify"
        Me.btnCntNotify.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntNotify.Size = New System.Drawing.Size(105, 24)
        Me.btnCntNotify.TabIndex = 43
        Me.btnCntNotify.Text = "通知..."
        Me.btnCntNotify.UseVisualStyleBackColor = False
        '
        'btnCntMode
        '
        Me.btnCntMode.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntMode.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntMode.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntMode.Location = New System.Drawing.Point(306, 45)
        Me.btnCntMode.Name = "btnCntMode"
        Me.btnCntMode.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntMode.Size = New System.Drawing.Size(105, 24)
        Me.btnCntMode.TabIndex = 42
        Me.btnCntMode.Text = "カウンタモード..."
        Me.btnCntMode.UseVisualStyleBackColor = False
        '
        'btnCntInit
        '
        Me.btnCntInit.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntInit.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntInit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntInit.Location = New System.Drawing.Point(306, 10)
        Me.btnCntInit.Name = "btnCntInit"
        Me.btnCntInit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntInit.Size = New System.Drawing.Size(105, 24)
        Me.btnCntInit.TabIndex = 0
        Me.btnCntInit.Text = "CntInit"
        Me.btnCntInit.UseVisualStyleBackColor = False
        '
        '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(13, 331)
        Me.Label6.Name = "Label6"
        Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label6.Size = New System.Drawing.Size(43, 12)
        Me.Label6.TabIndex = 53
        Me.Label6.Text = "戻り値："
        '
        'txtRet
        '
        Me.txtRet.AcceptsReturn = True
        Me.txtRet.BackColor = System.Drawing.SystemColors.Window
        Me.txtRet.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtRet.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtRet.Location = New System.Drawing.Point(74, 326)
        Me.txtRet.MaxLength = 0
        Me.txtRet.Name = "txtRet"
        Me.txtRet.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtRet.Size = New System.Drawing.Size(217, 19)
        Me.txtRet.TabIndex = 54
        '
        'Frame1
        '
        Me.Frame1.BackColor = System.Drawing.SystemColors.Control
        Me.Frame1.Controls.Add(Me.txtCountStatus3)
        Me.Frame1.Controls.Add(Me.txtCountStatus2)
        Me.Frame1.Controls.Add(Me.txtCountStatus1)
        Me.Frame1.Controls.Add(Me.txtCountStatus0)
        Me.Frame1.Controls.Add(Me.txtCountValue0)
        Me.Frame1.Controls.Add(Me.txtCountValue3)
        Me.Frame1.Controls.Add(Me.txtCountValue2)
        Me.Frame1.Controls.Add(Me.txtCountValue1)
        Me.Frame1.Controls.Add(Me.Label2)
        Me.Frame1.Controls.Add(Me.Label5)
        Me.Frame1.Controls.Add(Me.Label4)
        Me.Frame1.Controls.Add(Me.Label3)
        Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame1.Location = New System.Drawing.Point(13, 50)
        Me.Frame1.Name = "Frame1"
        Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame1.Size = New System.Drawing.Size(273, 129)
        Me.Frame1.TabIndex = 51
        Me.Frame1.TabStop = False
        Me.Frame1.Text = "カウント値/ステータス："
        '
        'txtCountStatus3
        '
        Me.txtCountStatus3.AcceptsReturn = True
        Me.txtCountStatus3.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountStatus3.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountStatus3.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountStatus3.Location = New System.Drawing.Point(160, 96)
        Me.txtCountStatus3.MaxLength = 0
        Me.txtCountStatus3.Name = "txtCountStatus3"
        Me.txtCountStatus3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountStatus3.Size = New System.Drawing.Size(104, 19)
        Me.txtCountStatus3.TabIndex = 28
        '
        'txtCountStatus2
        '
        Me.txtCountStatus2.AcceptsReturn = True
        Me.txtCountStatus2.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountStatus2.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountStatus2.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountStatus2.Location = New System.Drawing.Point(160, 72)
        Me.txtCountStatus2.MaxLength = 0
        Me.txtCountStatus2.Name = "txtCountStatus2"
        Me.txtCountStatus2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountStatus2.Size = New System.Drawing.Size(104, 19)
        Me.txtCountStatus2.TabIndex = 27
        '
        'txtCountStatus1
        '
        Me.txtCountStatus1.AcceptsReturn = True
        Me.txtCountStatus1.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountStatus1.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountStatus1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountStatus1.Location = New System.Drawing.Point(160, 48)
        Me.txtCountStatus1.MaxLength = 0
        Me.txtCountStatus1.Name = "txtCountStatus1"
        Me.txtCountStatus1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountStatus1.Size = New System.Drawing.Size(104, 19)
        Me.txtCountStatus1.TabIndex = 26
        '
        'txtCountStatus0
        '
        Me.txtCountStatus0.AcceptsReturn = True
        Me.txtCountStatus0.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountStatus0.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountStatus0.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountStatus0.Location = New System.Drawing.Point(160, 24)
        Me.txtCountStatus0.MaxLength = 0
        Me.txtCountStatus0.Name = "txtCountStatus0"
        Me.txtCountStatus0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountStatus0.Size = New System.Drawing.Size(104, 19)
        Me.txtCountStatus0.TabIndex = 25
        '
        'txtCountValue0
        '
        Me.txtCountValue0.AcceptsReturn = True
        Me.txtCountValue0.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountValue0.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountValue0.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountValue0.Location = New System.Drawing.Point(48, 24)
        Me.txtCountValue0.MaxLength = 0
        Me.txtCountValue0.Name = "txtCountValue0"
        Me.txtCountValue0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountValue0.Size = New System.Drawing.Size(104, 19)
        Me.txtCountValue0.TabIndex = 24
        '
        'txtCountValue3
        '
        Me.txtCountValue3.AcceptsReturn = True
        Me.txtCountValue3.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountValue3.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountValue3.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountValue3.Location = New System.Drawing.Point(48, 96)
        Me.txtCountValue3.MaxLength = 0
        Me.txtCountValue3.Name = "txtCountValue3"
        Me.txtCountValue3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountValue3.Size = New System.Drawing.Size(104, 19)
        Me.txtCountValue3.TabIndex = 18
        '
        'txtCountValue2
        '
        Me.txtCountValue2.AcceptsReturn = True
        Me.txtCountValue2.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountValue2.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountValue2.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountValue2.Location = New System.Drawing.Point(48, 72)
        Me.txtCountValue2.MaxLength = 0
        Me.txtCountValue2.Name = "txtCountValue2"
        Me.txtCountValue2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountValue2.Size = New System.Drawing.Size(104, 19)
        Me.txtCountValue2.TabIndex = 17
        '
        'txtCountValue1
        '
        Me.txtCountValue1.AcceptsReturn = True
        Me.txtCountValue1.BackColor = System.Drawing.SystemColors.Window
        Me.txtCountValue1.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtCountValue1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtCountValue1.Location = New System.Drawing.Point(48, 48)
        Me.txtCountValue1.MaxLength = 0
        Me.txtCountValue1.Name = "txtCountValue1"
        Me.txtCountValue1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtCountValue1.Size = New System.Drawing.Size(104, 19)
        Me.txtCountValue1.TabIndex = 16
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(8, 29)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(33, 12)
        Me.Label2.TabIndex = 23
        Me.Label2.Text = "CH0："
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.BackColor = System.Drawing.SystemColors.Control
        Me.Label5.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label5.Location = New System.Drawing.Point(8, 101)
        Me.Label5.Name = "Label5"
        Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label5.Size = New System.Drawing.Size(33, 12)
        Me.Label5.TabIndex = 15
        Me.Label5.Text = "CH3："
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.BackColor = System.Drawing.SystemColors.Control
        Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label4.Location = New System.Drawing.Point(8, 77)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(33, 12)
        Me.Label4.TabIndex = 14
        Me.Label4.Text = "CH2："
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(8, 53)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(33, 12)
        Me.Label3.TabIndex = 13
        Me.Label3.Text = "CH1："
        '
        'btnCntStop
        '
        Me.btnCntStop.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntStop.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntStop.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntStop.Location = New System.Drawing.Point(306, 255)
        Me.btnCntStop.Name = "btnCntStop"
        Me.btnCntStop.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntStop.Size = New System.Drawing.Size(105, 24)
        Me.btnCntStop.TabIndex = 48
        Me.btnCntStop.Text = "CntStop"
        Me.btnCntStop.UseVisualStyleBackColor = False
        '
        'btnCntReset
        '
        Me.btnCntReset.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntReset.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntReset.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntReset.Location = New System.Drawing.Point(306, 220)
        Me.btnCntReset.Name = "btnCntReset"
        Me.btnCntReset.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntReset.Size = New System.Drawing.Size(105, 24)
        Me.btnCntReset.TabIndex = 47
        Me.btnCntReset.Text = "CntReset"
        Me.btnCntReset.UseVisualStyleBackColor = False
        '
        'btnCntPreset
        '
        Me.btnCntPreset.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntPreset.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntPreset.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntPreset.Location = New System.Drawing.Point(306, 185)
        Me.btnCntPreset.Name = "btnCntPreset"
        Me.btnCntPreset.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntPreset.Size = New System.Drawing.Size(105, 24)
        Me.btnCntPreset.TabIndex = 46
        Me.btnCntPreset.Text = "CntPreset"
        Me.btnCntPreset.UseVisualStyleBackColor = False
        '
        'btnCntStart
        '
        Me.btnCntStart.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntStart.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntStart.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntStart.Location = New System.Drawing.Point(306, 150)
        Me.btnCntStart.Name = "btnCntStart"
        Me.btnCntStart.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntStart.Size = New System.Drawing.Size(105, 24)
        Me.btnCntStart.TabIndex = 45
        Me.btnCntStart.Text = "CntStart"
        Me.btnCntStart.UseVisualStyleBackColor = False
        '
        'txtDeviceName
        '
        Me.txtDeviceName.AcceptsReturn = True
        Me.txtDeviceName.BackColor = System.Drawing.SystemColors.Window
        Me.txtDeviceName.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtDeviceName.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txtDeviceName.Location = New System.Drawing.Point(90, 11)
        Me.txtDeviceName.MaxLength = 0
        Me.txtDeviceName.Name = "txtDeviceName"
        Me.txtDeviceName.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txtDeviceName.Size = New System.Drawing.Size(113, 19)
        Me.txtDeviceName.TabIndex = 40
        '
        '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(13, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(61, 12)
        Me.Label1.TabIndex = 39
        Me.Label1.Text = "デバイス名："
        '
        'btnCntEvent
        '
        Me.btnCntEvent.BackColor = System.Drawing.SystemColors.Control
        Me.btnCntEvent.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnCntEvent.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCntEvent.Location = New System.Drawing.Point(306, 115)
        Me.btnCntEvent.Name = "btnCntEvent"
        Me.btnCntEvent.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnCntEvent.Size = New System.Drawing.Size(105, 24)
        Me.btnCntEvent.TabIndex = 44
        Me.btnCntEvent.Text = "イベント設定..."
        Me.btnCntEvent.UseVisualStyleBackColor = False
        '
        'btnExit
        '
        Me.btnExit.BackColor = System.Drawing.SystemColors.Control
        Me.btnExit.Cursor = System.Windows.Forms.Cursors.Default
        Me.btnExit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnExit.Location = New System.Drawing.Point(306, 325)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.btnExit.Size = New System.Drawing.Size(105, 24)
        Me.btnExit.TabIndex = 50
        Me.btnExit.Text = "Exit"
        Me.btnExit.UseVisualStyleBackColor = False
        '
        'timer1
        '
        '
        'frmCounter
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(424, 358)
        Me.Controls.Add(Me.Frame2)
        Me.Controls.Add(Me.btnCntExit)
        Me.Controls.Add(Me.btnCntNotify)
        Me.Controls.Add(Me.btnCntMode)
        Me.Controls.Add(Me.btnCntInit)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.txtRet)
        Me.Controls.Add(Me.Frame1)
        Me.Controls.Add(Me.btnCntStop)
        Me.Controls.Add(Me.btnCntReset)
        Me.Controls.Add(Me.btnCntPreset)
        Me.Controls.Add(Me.btnCntStart)
        Me.Controls.Add(Me.txtDeviceName)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnCntEvent)
        Me.Controls.Add(Me.btnExit)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmCounter"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "カウンタ"
        Me.Frame2.ResumeLayout(False)
        Me.Frame1.ResumeLayout(False)
        Me.Frame1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    '関数の戻り値
    'ID
    Public Shared Id As Short
    Public Shared ChannelNum As Short
    Const CHANNEL_NUM As Short = 4

    Dim CountMatch(CHANNEL_NUM) As UInteger
    Dim gMode As New frmMode()
    Dim g_Event As New frmEvent()
    Dim gNotify As New frmNotify()
    Dim txt_Count(CHANNEL_NUM) As TextBox
    Dim txt_Status(CHANNEL_NUM) As TextBox

    'コールバックルーチンの宣言
    Dim hGC_CountUp As GCHandle
    Dim hGC_CounterError As GCHandle
    Dim hGC_CarryBorrow As GCHandle
    Dim hGC_Timer As GCHandle
    Dim dele_CountUp As PCOUNTUPCALLBACK
    Dim dele_CounterError As PCOUNTERERRORCALLBACK
    Dim dele_CarryBorrow As PCARRYBORROWCALLBACK
    '------------------------------
    ' デバイスのタイマー通知イベントを利用される場合は、
    ' 以下の宣言をご使用ください
    '-----------------------------
    'Dim dele_Timer As PTIMERCALLBACK
    Dim pCountUp As IntPtr
    Dim pCounterError As IntPtr
    Dim pCarryBorrow As IntPtr
    Dim pTimer As IntPtr

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

        Dim i As Short

        Me.Left = (Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.Bounds.Height - Me.Height) / 2

        '-----------------------------------
        ' コントロール配列設定
        '-----------------------------------
        '-----------------
        ' カウント値コントロール
        '-----------------
        txt_Count(0) = txtCountValue0
        txt_Count(1) = txtCountValue1
        txt_Count(2) = txtCountValue2
        txt_Count(3) = txtCountValue3
        '-----------------
        ' カウントステータスコントロール
        '-----------------
        txt_Status(0) = txtCountStatus0
        txt_Status(1) = txtCountStatus1
        txt_Status(2) = txtCountStatus2
        txt_Status(3) = txtCountStatus3
        '-----------------------------------
        ' 画面表示の初期化
        '-----------------------------------
        txtDeviceName.Text = "CNT000"
        '-----------------------------------
        ' 各チャネルごとに
        '-----------------------------------
        For i = 0 To CHANNEL_NUM - 1
            '-----------------
            ' カウント値コントロール
            '-----------------
            txt_Count(i).Text = ""
            '-----------------
            ' カウントステータスコントロール
            '-----------------
            txt_Status(i).Text = ""
        Next i
        '-----------------------------------
        ' パラメータの初期化
        '-----------------------------------
        ChannelNum = CHANNEL_NUM
        '--------------------------------------
        ' イベント通知用デリゲート初期化
        '--------------------------------------
        dele_CountUp = New PCOUNTUPCALLBACK(AddressOf SetCountUpCallBackProc)
        dele_CounterError = New PCOUNTERERRORCALLBACK(AddressOf CounterErrorCallBackProc)
        dele_CarryBorrow = New PCARRYBORROWCALLBACK(AddressOf CarryBorrowCallBackProc)
        '--------------------------------------
        ' デリゲートが開放されないように設定します。
        '--------------------------------------
        If hGC_CountUp.IsAllocated = False Then
            hGC_CountUp = GCHandle.Alloc(dele_CountUp)
        End If
        If hGC_CounterError.IsAllocated = False Then
            hGC_CounterError = GCHandle.Alloc(dele_CounterError)
        End If
        If hGC_CarryBorrow.IsAllocated = False Then
            hGC_CarryBorrow = GCHandle.Alloc(dele_CarryBorrow)
        End If
        '------------------------------
        ' デバイスのタイマー通知イベントを利用される場合は、
        ' 以下の設定をご使用ください
        '------------------------------
        '-----------------------------------
        ' タイマーイベント通知用デリゲート初期化
        '-----------------------------------
        'dele_Timer = New PTIMERCALLBACK(AddressOf TimerCallBackProc)
        '-----------------------------------
        ' デリゲートが開放されないように設定します。
        '-----------------------------------
        'If hGC_Timer.IsAllocated = False Then
        '    hGC_Timer = GCHandle.Alloc(dele_Timer)
        'End If
    End Sub

    '---------------------------------------------
    ' CntInit()
    '---------------------------------------------
    Private Sub btnCntInit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntInit.Click
        Dim buf As New String("", 100)
        Dim error_string As New StringBuilder("", 256)
        Dim ret As Integer
        Dim i As Short

        '------------------------------
        ' 初期化処理
        '------------------------------
        ret = CntInit(txtDeviceName.Text, Id)
        CntGetErrorString(ret, error_string)
        txtRet.Text = "CntInit ret = " & ret & ": " & error_string.ToString()

        If (ret <> CNT_ERR_SUCCESS) Then
            Exit Sub
        End If

        '------------------------------
        ' 総チャネル数を取得
        '------------------------------
        Call CntGetMaxChannels(Id, ChannelNum)

        '------------------------------
        ' サンプルのコントロール数を超える場合、総チャネル数をコントロール数に補正
        '------------------------------
        if (ChannelNum > CHANNEL_NUM) Then
            ChannelNum = CHANNEL_NUM
        End If

        '------------------------------
        ' カウンタ、ステータス表示を総チャネル数に合わせて切り替え
        '------------------------------
        For i = 0 To CHANNEL_NUM - 1
            '------------------------------
            ' 総チャネル数を超えた場合表示を無効化
            '------------------------------
            if (i >= ChannelNum) Then
                txt_Count(i).Enabled = False
                txt_Status(i).Enabled = False
            '------------------------------
            ' 総チャネル数以下の場合表示を有効化
            '------------------------------
            Else
                txt_Count(i).Enabled = True
                txt_Status(i).Enabled = True
            End If
        Next i

    End Sub

    '---------------------------------------------
    ' カウンタモード設定画面表示
    '---------------------------------------------
    Private Sub btnCntMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntMode.Click
        '------------------------------
        ' カウンタモード設定画面表示
        '------------------------------
        gMode.Show()

    End Sub

    '---------------------------------------------
    ' 通知設定画面表示
    '---------------------------------------------
    Private Sub btnCntNotify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntNotify.Click
        '------------------------------
        ' 通知設定画面表示
        '------------------------------
        gNotify.Show()
    End Sub

    '---------------------------------------------
    ' イベント設定画面表示
    '---------------------------------------------
    Private Sub btnCntEvent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntEvent.Click
        '------------------------------
        ' イベント設定画面表示
        '------------------------------
        g_Event.Show()
    End Sub

    '---------------------------------------------
    ' カウント開始
    '---------------------------------------------
    Private Sub btnCntStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntStart.Click

        Dim error_string As New StringBuilder("", 256)
        Dim ret As Integer
        Dim ChNo(CHANNEL_NUM) As Short
        Dim i As Short

        '--------------------------------------
        ' コールバックルーチン
        '--------------------------------------
        Dim Temp As IntPtr = New IntPtr(Id)
        ' カウント一致
        pCountUp = Marshal.GetFunctionPointerForDelegate(dele_CountUp)
        ret = CntCountUpCallbackProc(Id, pCountUp, Temp)
        '--------------------------------------
        ' イベント通知機能のないデバイスに合わせてエラーチェックをコメントアウトしています
        ' エラーチェックが必要な場合はコメントアウトを解除してください
        '--------------------------------------
        'CntGetErrorString(ret, error_string)
        'txtRet.Text = "CntCountUpCallbackProc Ret = " & ret & ":" & error_string.ToString()
        ' カウンタ エラー
        pCounterError = Marshal.GetFunctionPointerForDelegate(dele_CounterError)
        ret = CntCounterErrorCallbackProc(Id, pCounterError, Temp)
        '--------------------------------------
        ' イベント通知機能のないデバイスに合わせてエラーチェックをコメントアウトしています
        ' エラーチェックが必要な場合はコメントアウトを解除してください
        '--------------------------------------
        'CntGetErrorString(ret, error_string)
        'txtRet.Text = "CntCounterErrorCallbackProc Ret = " & ret & ":" & error_string.ToString()
        ' キャリー/ボロー
        pCarryBorrow = Marshal.GetFunctionPointerForDelegate(dele_CarryBorrow)
        ret = CntCarryBorrowCallbackProc(Id, pCarryBorrow, Temp)
        '--------------------------------------
        ' イベント通知機能のないデバイスに合わせてエラーチェックをコメントアウトしています
        ' エラーチェックが必要な場合はコメントアウトを解除してください
        '--------------------------------------
        'CntGetErrorString(ret, error_string)
        'txtRet.Text = "CntCarryBorrowCallbackProc Ret = " & ret & ":" & error_string.ToString()
        '------------------------------
        ' デバイスのタイマー通知イベントを利用される場合は、
        ' 以下の関数をご使用ください
        '------------------------------
        ' タイマー
        'pTimer = Marshal.GetFunctionPointerForDelegate(dele_Timer)
        ' タイマー通知
        'ret = CntTimerCallbackProc(Id, pTimer, Temp)
        'CntGetErrorString(ret, error_string)
        'txtRet.Text = "CntTimerCallbackProc Ret = " & ret & ":" & error_string.ToString()

        '------------------------------
        ' パラメータのセット
        '------------------------------
        For i = 0 To ChannelNum - 1
            ChNo(i) = i
        Next i

        '------------------------------
        ' カウント開始処理
        '------------------------------
        ret = CntStartCount(Id, ChNo, ChannelNum)
        CntGetErrorString(ret, error_string)
        txtRet.Text = "CntStartCount ret = " & ret & ": " & error_string.ToString()

        If ret = 0 Then
            '------------------------------
            ' タイマー通知機能を持たないデバイスを考慮し、
            ' ウィンドウタイマーを使用しております。
            ' 用途に合わせて、切り替えてご使用ください。
            '------------------------------
            '------------------------------
            ' タイマーを起動
            '------------------------------
            timer1.Start()
            '------------------------------
            ' デバイスのタイマー通知イベントを利用される場合は、
            ' 以下の関数をご使用ください
            '------------------------------
            'CntNotifyTimer(Id, 100, Me.Handle.ToInt32)
        End If
    End Sub

    '---------------------------------------------
    ' カウンタプリセット
    '---------------------------------------------
    Private Sub btnCntPreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntPreset.Click

        Dim error_string As New StringBuilder("", 256)
        Dim ret As Integer
        Dim ChNo(CHANNEL_NUM) As Short
        Dim PresetData(CHANNEL_NUM) As Integer
        Dim i As Short

        '------------------------------
        ' プリセット値のセット
        '------------------------------
        For i = 0 To ChannelNum - 1
            ChNo(i) = i
            PresetData(i) = i * 100
        Next i

        '------------------------------
        ' プリセット設定処理
        '------------------------------
        ret = CntPreset(Id, ChNo, ChannelNum, PresetData)
        CntGetErrorString(ret, error_string)
        txtRet.Text = "CntPreset ret = " & ret & ": " & error_string.ToString()
    End Sub

    '---------------------------------------------
    ' カウンタリセット
    '---------------------------------------------
    Private Sub btnCntReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntReset.Click

        Dim error_string As New StringBuilder("", 256)
        Dim ret As Integer
        Dim ChNo(CHANNEL_NUM) As Short
        Dim i As Short

        '------------------------------
        ' パラメータのセット
        '------------------------------
        For i = 0 To ChannelNum - 1
            ChNo(i) = i
        Next i

        '------------------------------
        ' カウンタリセット処理
        '------------------------------
        ret = CntZeroClearCount(Id, ChNo, ChannelNum)
        CntGetErrorString(ret, error_string)
        txtRet.Text = "CntZeroClearCount ret = " & ret & ": " & error_string.ToString()

    End Sub

    '---------------------------------------------
    ' カウント停止
    '---------------------------------------------
    Private Sub btnCntStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntStop.Click

        Dim error_string As New StringBuilder("", 256)
        Dim ret As Integer
        Dim ChNo(CHANNEL_NUM) As Short
        Dim i As Short

        '------------------------------
        ' パラメータのセット
        '------------------------------
        For i = 0 To ChannelNum - 1
            ChNo(i) = i
        Next i

        '------------------------------
        ' カウント停止処理
        '------------------------------
        ret = CntStopCount(Id, ChNo, ChannelNum)
        CntGetErrorString(ret, error_string)
        txtRet.Text = "CntStopCount ret = " & ret & ": " & error_string.ToString()

        '------------------------------
        ' タイマー通知機能を持たないデバイスを考慮し、
        ' ウィンドウタイマーを使用しております。
        ' 用途に合わせて、切り替えてご使用ください。
        '------------------------------
        '------------------------------
        ' タイマーを停止
        '------------------------------
        timer1.Stop()
        '------------------------------
        ' デバイスのタイマー通知イベントを利用される場合は、
        ' 以下の関数をご使用ください
        '------------------------------
        'CntStopNotifyTimer(Id)

    End Sub

    '---------------------------------------------
    ' CntExit()
    '---------------------------------------------
    Private Sub btnCntExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCntExit.Click

        Dim error_string As New StringBuilder("", 256)
        Dim ret As Integer

        '------------------------------
        ' タイマー通知機能を持たないデバイスを考慮し、
        ' ウィンドウタイマーを使用しております。
        ' 用途に合わせて、切り替えてご使用ください。
        '------------------------------
        '------------------------------
        ' タイマーを停止
        '------------------------------
        timer1.Stop()
        '------------------------------
        ' デバイスのタイマー通知イベントを利用される場合は、
        ' 以下の関数をご使用ください
        '------------------------------
        'CntStopNotifyTimer(Id)

        '------------------------------
        ' カウンタ終了処理
        '------------------------------
        ret = CntExit(Id)
        CntGetErrorString(ret, error_string)
        txtRet.Text = "CntExit ret = " & ret & ": " & error_string.ToString()

    End Sub

    '---------------------------------------------
    ' サンプルプログラム終了
    '---------------------------------------------
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Dim ret As Integer

        '------------------------------
        ' タイマー通知機能を持たないデバイスを考慮し、
        ' ウィンドウタイマーを使用しております。
        ' 用途に合わせて、切り替えてご使用ください。
        '------------------------------
        '------------------------------
        ' タイマーを停止
        '------------------------------
        timer1.Stop()
        '------------------------------
        ' デバイスのタイマー通知イベントを利用される場合は、
        ' 以下の関数をご使用ください
        '------------------------------
        'CntStopNotifyTimer(Id)

        '------------------------------
        ' カウンタ終了処理
        '------------------------------
        ret = CntExit(Id)

        '--------------------------------------
        ' イベント通知用デリゲートのガベージコレクションハンドルを開放
        '--------------------------------------
        If hGC_CountUp.IsAllocated = True Then
            hGC_CountUp.Free()
        End If
        If hGC_CounterError.IsAllocated = True Then
            hGC_CounterError.Free()
        End If
        If hGC_CarryBorrow.IsAllocated = True Then
            hGC_CarryBorrow.Free()
        End If
        If hGC_Timer.IsAllocated = True Then
            hGC_Timer.Free()
        End If

        End
    End Sub

    '---------------------------------------------
    ' コールバックルーチン
    '---------------------------------------------
    ' カウント一致
    Protected Sub SetCountUpCallBackProc(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)

        Dim str As String
        Dim MatchCh As Short
        MatchCh = HiLoWord(wParam, 0)

        Select Case MatchCh
            Case 0      ' カウント一致: 0CH
                CountMatch(0) = CountMatch(0) + 1
                If HiLoWord(wParam, 1) = 1 Then
                    str = String.Format("カウント一致! チャネル番号: 0, UP, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(0))
                Else
                    str = String.Format("カウント一致! チャネル番号: 0, DOWN, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(0))
                End If
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})

            Case 1      ' カウント一致: 1CH
                CountMatch(1) = CountMatch(1) + 1
                If HiLoWord(wParam, 1) = 1 Then
                    str = String.Format("カウント一致! チャネル番号: 1, UP, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(1))
                Else
                    str = String.Format("カウント一致! チャネル番号: 1, DOWN, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(1))
                End If
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})

            Case 2      ' カウント一致: 2CH
                CountMatch(2) = CountMatch(2) + 1
                If HiLoWord(wParam, 1) = 1 Then
                    str = String.Format("カウント一致! チャネル番号: 2, UP, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(2))
                Else
                    str = String.Format("カウント一致! チャネル番号: 2, DOWN, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(2))
                End If
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})

            Case 3      ' カウント一致: 3CH
                CountMatch(3) = CountMatch(3) + 1
                If HiLoWord(wParam, 1) = 1 Then
                    str = String.Format("カウント一致! チャネル番号: 3, UP, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(3))
                Else
                    str = String.Format("カウント一致! チャネル番号: 3, DOWN, " & vbCrLf & "カウント: {0:X8}(Hex) 一致回数: {1:D}回", lParam, CountMatch(3))
                End If
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})
        End Select

    End Sub

    ' カウンタ エラー
    Protected Sub CounterErrorCallBackProc(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)

        Dim str As String
        Dim ErrType As Short
        Dim ErrCh As Short

        ErrType = HiLoWord(lParam, 0)
        ErrCh = HiLoWord(wParam, 0)

        Select Case ErrType
            Case CNT_AI_ERROR  ' 異常入力
                str = String.Format("異常入力エラー! チャネル番号: {0:D}", ErrCh)
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})
            Case CNT_FLT_ERROR ' フィルター
                str = String.Format("フィルタエラー! チャネル番号: {0:D}", ErrCh)
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})
            Case CNT_ALM_ERROR ' アラーム
                str = String.Format("アラームエラー! チャネル番号: {0:D}", ErrCh)
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})
        End Select

    End Sub

    ' キャリー/ボロー
    Protected Sub CarryBorrowCallBackProc(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)

        Dim str As String
        Dim NotifyFac As Short
        Dim CarryCh As Short

        NotifyFac = HiLoWord(lParam, 0)
        CarryCh = HiLoWord(wParam, 0)

        Select Case NotifyFac
            Case CNT_CB_CARRY  ' キャリー
                str = String.Format("キャリー! チャネル番号: {0:D}", CarryCh)
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})
            Case CNT_CB_BORROW ' ボロー
                str = String.Format("ボロー! チャネル番号: {0:D}", CarryCh)
                Invoke(New SetTextDelegate(AddressOf SetNotifyText), New Object() {str})
        End Select

    End Sub

    '---------------------------------------------------------
    ' タイマー通知機能を持たないデバイスを考慮し、
    ' ウィンドウタイマーを使用しております。
    ' 用途に合わせて、切り替えてご使用ください。
    '---------------------------------------------------------
    '---------------------------------------------------------
    ' ウィンドウタイマー用メソッド
    '---------------------------------------------------------
    Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick

        Dim ChNo(CHANNEL_NUM) As Short
        Dim CntData(CHANNEL_NUM) As Integer
        Dim StatusData(CHANNEL_NUM) As Integer
        Dim i As Short
        Dim ret As Integer
        Dim error_string As New StringBuilder("", 256)
        Dim str As String

        '------------------------------
        ' パラメータのセット
        '------------------------------
        For i = 0 To ChannelNum - 1
            ChNo(i) = i
            CntData(i) = 0
            StatusData(i) = 0
        Next i
        '------------------------------
        ' カウント値取得処理
        '------------------------------
        ret = CntReadCount(Id, ChNo, ChannelNum, CntData)
        If ret <> 0 Then
            CntGetErrorString(ret, error_string)
            str = String.Format("CntReadCnt ret = {0:D}: " & error_string.ToString(), ret)
            txtRet.Text = str
            timer1.Stop()
        End If
        '------------------------------
        ' ステータス取得処理
        '------------------------------
        For i = 0 To ChannelNum - 1
            ret = CntReadStatusEx(Id, i, StatusData(i))
            If ret <> 0 Then
                CntGetErrorString(ret, error_string)
                str = String.Format("CntReadStatus ret = {0:D}: " & error_string.ToString(), ret)
                txtRet.Text = str
                timer1.Stop()
            End If
        Next i

        '------------------------------
        ' データ表示処理
        '------------------------------
       For i = 0 To ChannelNum - 1
            ' カウントデータを符号無しで表示するため、一度16進文字例変換を経由
            txt_Count(i).Text = String.Format("{0:D}", Convert.ToUInt32(Hex(CntData(i)), 16))
            txt_Status(i).Text = String.Format("{0:X8}H", StatusData(i))
        Next i

    End Sub

    '---------------------------------------------------------
    ' デバイスのタイマー通知イベントを利用される場合、
    ' 以下のコールバックルーチンをご使用ください。
    '---------------------------------------------------------
    '---------------------------------------------------------
    ' タイマー通知用コールバックルーチン
    '---------------------------------------------------------
    'Protected Sub TimerCallBackProc(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)

    '    Dim ChNo(CHANNEL_NUM) As Short
    '    Dim CntData(CHANNEL_NUM) As Integer
    '    Dim StatusData(CHANNEL_NUM) As Integer
    '    Dim i As Short
    '    Dim ret As Integer
    '    Dim error_string As New StringBuilder("", 256)
    '    Dim str As String

    '    '------------------------------
    '    ' パラメータのセット
    '    '------------------------------
    '    For i = 0 To ChannelNum - 1
    '        ChNo(i) = i
    '        CntData(i) = 0
    '        StatusData(i) = 0
    '    Next i
    '    '------------------------------
    '    ' カウント値取得処理
    '    '------------------------------
    '    ret = CntReadCount(Id, ChNo, ChannelNum, CntData)
    '    If ret <> 0 Then
    '        CntGetErrorString(ret, error_string)
    '        str = String.Format("CntReadCnt ret = {0:D}: " & error_string.ToString(), ret)
    '        Invoke(New SetTextDelegate(AddressOf SetRetText), New Object() {str})
    '        CntStopNotifyTimer(Id)
    '    End If
    '    '------------------------------
    '    ' ステータス取得処理
    '    '------------------------------
    '    For i = 0 To ChannelNum - 1
    '        ret = CntReadStatusEx(Id, i, StatusData(i))
    '        If ret <> 0 Then
    '            CntGetErrorString(ret, error_string)
    '            str = String.Format("CntReadStatus ret = {0:D}: " & error_string.ToString(), ret)
    '            Invoke(New SetTextDelegate(AddressOf SetRetText), New Object() {str})
    '            CntStopNotifyTimer(Id)
    '        End If
    '    Next i

    '    '------------------------------
    '    ' データ表示処理
    '    '------------------------------
    '    Invoke(New SetCountDataDelegate(AddressOf SetCountDataText), New Object() {CntData, StatusData})

    'End Sub

    '---------------------------------------------------------
    ' サブルーチン：HIWORD,LOWORDを取得する
    '---------------------------------------------------------
    Function HiLoWord(ByRef Number As Integer, ByRef HiLo As Short) As Integer

        Dim Hi As Integer
        Dim Lo As Integer
        Dim StrData As String
        Dim i As Short

        StrData = Hex(Number)
        If Len(StrData) < 8 Then
            For i = 1 To 8 - Len(StrData)
                StrData = "0" & StrData
            Next i
        End If

        Lo = Val("&h" & VB.Right(StrData, 4))
        Hi = Val("&h" & VB.Left(StrData, 4))
        If HiLo = 0 Then
            HiLoWord = Lo
        ElseIf HiLo = 1 Then
            HiLoWord = Hi
        End If

    End Function

    Delegate Sub SetTextDelegate(ByVal str As String)
    Delegate Sub SetCountDataDelegate(ByVal CntData() As Integer, ByVal StatusData() As Integer)

    '---------------------------------------------------------
    ' NotifyLabel設定(コントロール操作用同期関数)
    '---------------------------------------------------------
    Sub SetNotifyText(ByVal str As String)
        lblNotify.Text = str
    End Sub
    '---------------------------------------------------------
    ' RetTextBox設定(コントロール操作用同期関数)
    '---------------------------------------------------------
    Sub SetRetText(ByVal str As String)
        txtRet.Text = str
    End Sub
    '---------------------------------------------------------
    ' カウントデータ設定(コントロール操作用同期関数)
    '---------------------------------------------------------
    Sub SetCountDataText(ByVal CntData() As Integer, ByVal StatusData() As Integer)

        Dim i As Short

        '------------------------------
        ' データ表示処理
        '------------------------------
        For i = 0 To ChannelNum - 1
            ' カウントデータを符号無しで表示するため、一度16進文字例変換を経由
            txt_Count(i).Text = String.Format("{0:D}", Convert.ToUInt32(Hex(CntData(i)), 16))
            txt_Status(i).Text = String.Format("{0:X8}H", StatusData(i))
        Next i

    End Sub

End Class
