﻿Option Strict Off
Option Explicit On 
Imports VB = Microsoft.VisualBasic
Imports System.Text
Imports System.Runtime.InteropServices

Public Class InterruptCallback
    Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()
    End Sub
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
        If Disposing Then
            If Not components Is Nothing Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(Disposing)
    End Sub
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents Edit_ReturnCode As System.Windows.Forms.TextBox
    Public WithEvents Button_DioExit As System.Windows.Forms.Button
    Public WithEvents Button_Exit As System.Windows.Forms.Button
    Public WithEvents Label3 As System.Windows.Forms.Label
    Public WithEvents Label2 As System.Windows.Forms.Label
    Public WithEvents Frame1 As System.Windows.Forms.GroupBox
    Public WithEvents Edit_DeviceName As System.Windows.Forms.TextBox
    Public WithEvents Label5 As System.Windows.Forms.Label
    Public WithEvents Label1 As System.Windows.Forms.Label
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Radio_Fall As System.Windows.Forms.RadioButton
    Friend WithEvents Radio_Rise As System.Windows.Forms.RadioButton
    Friend WithEvents Label4 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
    Public WithEvents Button_IntStop As System.Windows.Forms.Button
    Public WithEvents Button_IntStart As System.Windows.Forms.Button
    Public WithEvents Button_DioInit As System.Windows.Forms.Button
    Public WithEvents Edit_Down_3 As System.Windows.Forms.TextBox
    Public WithEvents Edit_Down_2 As System.Windows.Forms.TextBox
    Public WithEvents Edit_Down_1 As System.Windows.Forms.TextBox
    Public WithEvents Edit_Down_0 As System.Windows.Forms.TextBox
    Public WithEvents Edit_Up_3 As System.Windows.Forms.TextBox
    Public WithEvents Edit_Up_2 As System.Windows.Forms.TextBox
    Public WithEvents Edit_Up_1 As System.Windows.Forms.TextBox
    Public WithEvents Edit_Up_0 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Edit_ReturnCode = New System.Windows.Forms.TextBox()
        Me.Button_DioExit = New System.Windows.Forms.Button()
        Me.Button_Exit = New System.Windows.Forms.Button()
        Me.Frame1 = New System.Windows.Forms.GroupBox()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Button_IntStop = New System.Windows.Forms.Button()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Radio_Fall = New System.Windows.Forms.RadioButton()
        Me.Radio_Rise = New System.Windows.Forms.RadioButton()
        Me.Button_IntStart = New System.Windows.Forms.Button()
        Me.Edit_Down_3 = New System.Windows.Forms.TextBox()
        Me.Edit_Down_2 = New System.Windows.Forms.TextBox()
        Me.Edit_Down_1 = New System.Windows.Forms.TextBox()
        Me.Edit_Down_0 = New System.Windows.Forms.TextBox()
        Me.Edit_Up_3 = New System.Windows.Forms.TextBox()
        Me.Edit_Up_2 = New System.Windows.Forms.TextBox()
        Me.Edit_Up_1 = New System.Windows.Forms.TextBox()
        Me.Edit_Up_0 = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Button_DioInit = New System.Windows.Forms.Button()
        Me.Edit_DeviceName = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Frame1.SuspendLayout()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Edit_ReturnCode
        '
        Me.Edit_ReturnCode.AcceptsReturn = True
        Me.Edit_ReturnCode.AutoSize = False
        Me.Edit_ReturnCode.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_ReturnCode.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_ReturnCode.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_ReturnCode.Location = New System.Drawing.Point(80, 224)
        Me.Edit_ReturnCode.MaxLength = 0
        Me.Edit_ReturnCode.Name = "Edit_ReturnCode"
        Me.Edit_ReturnCode.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_ReturnCode.Size = New System.Drawing.Size(249, 18)
        Me.Edit_ReturnCode.TabIndex = 14
        Me.Edit_ReturnCode.Text = "Edit"
        '
        'Button_DioExit
        '
        Me.Button_DioExit.BackColor = System.Drawing.SystemColors.Control
        Me.Button_DioExit.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button_DioExit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button_DioExit.Location = New System.Drawing.Point(352, 224)
        Me.Button_DioExit.Name = "Button_DioExit"
        Me.Button_DioExit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button_DioExit.Size = New System.Drawing.Size(113, 20)
        Me.Button_DioExit.TabIndex = 15
        Me.Button_DioExit.Text = "DioExit"
        '
        'Button_Exit
        '
        Me.Button_Exit.BackColor = System.Drawing.SystemColors.Control
        Me.Button_Exit.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button_Exit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button_Exit.Location = New System.Drawing.Point(352, 264)
        Me.Button_Exit.Name = "Button_Exit"
        Me.Button_Exit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button_Exit.Size = New System.Drawing.Size(113, 20)
        Me.Button_Exit.TabIndex = 16
        Me.Button_Exit.Text = "Exit"
        '
        'Frame1
        '
        Me.Frame1.BackColor = System.Drawing.SystemColors.Control
        Me.Frame1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label8, Me.Label7, Me.Label6, Me.Label4, Me.Button_IntStop, Me.GroupBox1, Me.Button_IntStart, Me.Edit_Down_3, Me.Edit_Down_2, Me.Edit_Down_1, Me.Edit_Down_0, Me.Edit_Up_3, Me.Edit_Up_2, Me.Edit_Up_1, Me.Edit_Up_0, Me.Label3, Me.Label2})
        Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame1.Location = New System.Drawing.Point(8, 56)
        Me.Frame1.Name = "Frame1"
        Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame1.Size = New System.Drawing.Size(488, 153)
        Me.Frame1.TabIndex = 13
        Me.Frame1.TabStop = False
        Me.Frame1.Text = "割り込みモニター"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(267, 16)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(8, 16)
        Me.Label8.TabIndex = 36
        Me.Label8.Text = "3"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(223, 16)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(8, 16)
        Me.Label7.TabIndex = 35
        Me.Label7.Text = "2"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(179, 16)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(8, 16)
        Me.Label6.TabIndex = 34
        Me.Label6.Text = "1"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(135, 16)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(8, 16)
        Me.Label4.TabIndex = 33
        Me.Label4.Text = "0"
        '
        'Button_IntStop
        '
        Me.Button_IntStop.BackColor = System.Drawing.SystemColors.Control
        Me.Button_IntStop.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button_IntStop.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button_IntStop.Location = New System.Drawing.Point(344, 127)
        Me.Button_IntStop.Name = "Button_IntStop"
        Me.Button_IntStop.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button_IntStop.Size = New System.Drawing.Size(113, 20)
        Me.Button_IntStop.TabIndex = 13
        Me.Button_IntStop.Text = "割り込み停止"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Radio_Fall, Me.Radio_Rise})
        Me.GroupBox1.Location = New System.Drawing.Point(296, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(176, 80)
        Me.GroupBox1.TabIndex = 11
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "割り込み論理"
        '
        'Radio_Fall
        '
        Me.Radio_Fall.Location = New System.Drawing.Point(16, 48)
        Me.Radio_Fall.Name = "Radio_Fall"
        Me.Radio_Fall.Size = New System.Drawing.Size(152, 16)
        Me.Radio_Fall.TabIndex = 11
        Me.Radio_Fall.Text = "1 -> 0 (立ち下がりエッジ)"
        '
        'Radio_Rise
        '
        Me.Radio_Rise.Checked = True
        Me.Radio_Rise.Location = New System.Drawing.Point(16, 24)
        Me.Radio_Rise.Name = "Radio_Rise"
        Me.Radio_Rise.Size = New System.Drawing.Size(152, 16)
        Me.Radio_Rise.TabIndex = 10
        Me.Radio_Rise.TabStop = True
        Me.Radio_Rise.Text = "0 -> 1 (立ち上がりエッジ)"
        '
        'Button_IntStart
        '
        Me.Button_IntStart.BackColor = System.Drawing.SystemColors.Control
        Me.Button_IntStart.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button_IntStart.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button_IntStart.Location = New System.Drawing.Point(344, 102)
        Me.Button_IntStart.Name = "Button_IntStart"
        Me.Button_IntStart.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button_IntStart.Size = New System.Drawing.Size(113, 20)
        Me.Button_IntStart.TabIndex = 12
        Me.Button_IntStart.Text = "割り込み開始"
        '
        'Edit_Down_3
        '
        Me.Edit_Down_3.AcceptsReturn = True
        Me.Edit_Down_3.AutoSize = False
        Me.Edit_Down_3.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Down_3.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Down_3.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Down_3.Location = New System.Drawing.Point(252, 64)
        Me.Edit_Down_3.MaxLength = 0
        Me.Edit_Down_3.Name = "Edit_Down_3"
        Me.Edit_Down_3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Down_3.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Down_3.TabIndex = 9
        Me.Edit_Down_3.Text = "Edit"
        Me.Edit_Down_3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Edit_Down_2
        '
        Me.Edit_Down_2.AcceptsReturn = True
        Me.Edit_Down_2.AutoSize = False
        Me.Edit_Down_2.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Down_2.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Down_2.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Down_2.Location = New System.Drawing.Point(208, 64)
        Me.Edit_Down_2.MaxLength = 0
        Me.Edit_Down_2.Name = "Edit_Down_2"
        Me.Edit_Down_2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Down_2.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Down_2.TabIndex = 8
        Me.Edit_Down_2.Text = "Edit"
        Me.Edit_Down_2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Edit_Down_1
        '
        Me.Edit_Down_1.AcceptsReturn = True
        Me.Edit_Down_1.AutoSize = False
        Me.Edit_Down_1.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Down_1.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Down_1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Down_1.Location = New System.Drawing.Point(164, 64)
        Me.Edit_Down_1.MaxLength = 0
        Me.Edit_Down_1.Name = "Edit_Down_1"
        Me.Edit_Down_1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Down_1.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Down_1.TabIndex = 7
        Me.Edit_Down_1.Text = "Edit"
        Me.Edit_Down_1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Edit_Down_0
        '
        Me.Edit_Down_0.AcceptsReturn = True
        Me.Edit_Down_0.AutoSize = False
        Me.Edit_Down_0.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Down_0.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Down_0.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Down_0.Location = New System.Drawing.Point(120, 64)
        Me.Edit_Down_0.MaxLength = 0
        Me.Edit_Down_0.Name = "Edit_Down_0"
        Me.Edit_Down_0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Down_0.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Down_0.TabIndex = 6
        Me.Edit_Down_0.Text = "Edit"
        Me.Edit_Down_0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Edit_Up_3
        '
        Me.Edit_Up_3.AcceptsReturn = True
        Me.Edit_Up_3.AutoSize = False
        Me.Edit_Up_3.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Up_3.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Up_3.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Up_3.Location = New System.Drawing.Point(252, 32)
        Me.Edit_Up_3.MaxLength = 0
        Me.Edit_Up_3.Name = "Edit_Up_3"
        Me.Edit_Up_3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Up_3.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Up_3.TabIndex = 5
        Me.Edit_Up_3.Text = "Edit"
        Me.Edit_Up_3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Edit_Up_2
        '
        Me.Edit_Up_2.AcceptsReturn = True
        Me.Edit_Up_2.AutoSize = False
        Me.Edit_Up_2.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Up_2.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Up_2.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Up_2.Location = New System.Drawing.Point(208, 32)
        Me.Edit_Up_2.MaxLength = 0
        Me.Edit_Up_2.Name = "Edit_Up_2"
        Me.Edit_Up_2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Up_2.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Up_2.TabIndex = 4
        Me.Edit_Up_2.Text = "Edit"
        Me.Edit_Up_2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Edit_Up_1
        '
        Me.Edit_Up_1.AcceptsReturn = True
        Me.Edit_Up_1.AutoSize = False
        Me.Edit_Up_1.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Up_1.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Up_1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Up_1.Location = New System.Drawing.Point(164, 32)
        Me.Edit_Up_1.MaxLength = 0
        Me.Edit_Up_1.Name = "Edit_Up_1"
        Me.Edit_Up_1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Up_1.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Up_1.TabIndex = 3
        Me.Edit_Up_1.Text = "Edit"
        Me.Edit_Up_1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Edit_Up_0
        '
        Me.Edit_Up_0.AcceptsReturn = True
        Me.Edit_Up_0.AutoSize = False
        Me.Edit_Up_0.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_Up_0.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_Up_0.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_Up_0.Location = New System.Drawing.Point(120, 32)
        Me.Edit_Up_0.MaxLength = 0
        Me.Edit_Up_0.Name = "Edit_Up_0"
        Me.Edit_Up_0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_Up_0.Size = New System.Drawing.Size(39, 20)
        Me.Edit_Up_0.TabIndex = 2
        Me.Edit_Up_0.Text = "Edit"
        Me.Edit_Up_0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label3
        '
        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(24, 64)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(80, 16)
        Me.Label3.TabIndex = 30
        Me.Label3.Text = "ダウンカウント："
        '
        'Label2
        '
        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(24, 32)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(72, 16)
        Me.Label2.TabIndex = 29
        Me.Label2.Text = "アップカウント："
        '
        'Button_DioInit
        '
        Me.Button_DioInit.BackColor = System.Drawing.SystemColors.Control
        Me.Button_DioInit.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button_DioInit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button_DioInit.Location = New System.Drawing.Point(352, 24)
        Me.Button_DioInit.Name = "Button_DioInit"
        Me.Button_DioInit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button_DioInit.Size = New System.Drawing.Size(113, 20)
        Me.Button_DioInit.TabIndex = 1
        Me.Button_DioInit.Text = "DioInit"
        '
        'Edit_DeviceName
        '
        Me.Edit_DeviceName.AcceptsReturn = True
        Me.Edit_DeviceName.AutoSize = False
        Me.Edit_DeviceName.BackColor = System.Drawing.SystemColors.Window
        Me.Edit_DeviceName.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Edit_DeviceName.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Edit_DeviceName.Location = New System.Drawing.Point(104, 24)
        Me.Edit_DeviceName.MaxLength = 0
        Me.Edit_DeviceName.Name = "Edit_DeviceName"
        Me.Edit_DeviceName.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Edit_DeviceName.Size = New System.Drawing.Size(97, 18)
        Me.Edit_DeviceName.TabIndex = 0
        Me.Edit_DeviceName.Text = "Edit"
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.SystemColors.Control
        Me.Label5.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label5.Location = New System.Drawing.Point(16, 224)
        Me.Label5.Name = "Label5"
        Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label5.Size = New System.Drawing.Size(48, 16)
        Me.Label5.TabIndex = 35
        Me.Label5.Text = "戻り値："
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(64, 17)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "デバイス名："
        '
        'InterruptCallback
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(512, 297)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Edit_ReturnCode, Me.Button_DioExit, Me.Button_Exit, Me.Frame1, Me.Button_DioInit, Me.Edit_DeviceName, Me.Label5, Me.Label1})
        Me.Location = New System.Drawing.Point(4, 23)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "InterruptCallback"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "割り込みコールバック"
        Me.Frame1.ResumeLayout(False)
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
#End Region

    Dim Id As Short                     'デバイスID
    Dim Ret As Integer                  '戻り値
    Dim szError As New StringBuilder("", 256)
    Dim UpCount(4) As Short             'アップカウント
    Dim DownCount(4) As Short           'ダウンカウント
    Dim Edit_Up(4) As TextBox
    Dim Edit_Down(4) As TextBox
    Dim gCh As GCHandle
    Dim pdelegate_func As PINTCALLBACK
    Dim pfunc As IntPtr

    Delegate Sub SetCountDelegate(ByVal BitNo As Integer, ByVal Kind As Integer)

    '---------------------------------------------------------
    ' ダイアログ初期化
    '---------------------------------------------------------
    Private Sub InterruptCallback_Load(ByVal eventSender As System.Object, ByVal eventArgs 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

        Edit_Up(0) = Edit_Up_0
        Edit_Up(1) = Edit_Up_1
        Edit_Up(2) = Edit_Up_2
        Edit_Up(3) = Edit_Up_3

        Edit_Down(0) = Edit_Down_0
        Edit_Down(1) = Edit_Down_1
        Edit_Down(2) = Edit_Down_2
        Edit_Down(3) = Edit_Down_3

        '--------------------------------------
        ' 画面表示の初期化
        '--------------------------------------
        Edit_DeviceName.Text = "DIO000"
        Edit_ReturnCode.Text = ""
        'アップカウント
        For i = 0 To 3
            Edit_Up(i).Text = ""
        Next i
        'ダウンカウント
        For i = 0 To 3
            Edit_Down(i).Text = ""
        Next i
        Radio_Rise.Checked = True
        Edit_ReturnCode.Text = ""
        '--------------------------------------
        ' 割り込み処理用デリゲート初期化
        '--------------------------------------
        pdelegate_func = New PINTCALLBACK(AddressOf CallBackProc)
        '--------------------------------------
        ' デリゲートが開放されないように設定します。
        '--------------------------------------
        If gCh.IsAllocated = False Then
            gCh = GCHandle.Alloc(pdelegate_func)
        End If
    End Sub

    '---------------------------------------------------------
    '  DioInit()
    '---------------------------------------------------------
    Private Sub Button_DioInit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_DioInit.Click

        Dim szDeviceName As String

        '--------------------------------------
        ' デバイス名取得
        '--------------------------------------
        szDeviceName = Edit_DeviceName.Text
        '--------------------------------------
        ' 初期化処理
        '--------------------------------------
        Ret = DioInit(szDeviceName, Id)
        '--------------------------------------
        ' エラー処理
        '--------------------------------------
        Call DioGetErrorString(Ret, szError)
        Edit_ReturnCode.Text = "DioInit Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '---------------------------------------------------------
    ' 割り込み開始
    '---------------------------------------------------------
    Private Sub Button_IntStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_IntStart.Click

        Dim i As Short
        Dim BitNo As Short
        Dim Kind As Short

        '--------------------------------------
        '割り込み処理用デリゲートの固定ポインタを取得
        '--------------------------------------
        pfunc = Marshal.GetFunctionPointerForDelegate(pdelegate_func)
        '--------------------------------------
        ' コールバックルーチン
        '--------------------------------------
        Dim Temp As IntPtr = New IntPtr(Id)
        Ret = DioSetInterruptCallBackProc(Id, pfunc, Temp)
        '--------------------------------------
        ' エラー処理
        '--------------------------------------
        Call DioGetErrorString(Ret, szError)
        Edit_ReturnCode.Text = "DioSetInterruptCallBackProc Ret = " & Ret & ":" & szError.ToString()
        '--------------------------------------
        ' パラメータ初期化
        '--------------------------------------
        For i = 0 To 3
            UpCount(i) = 0                       'アップカウント
            DownCount(i) = 0                       'ダウンカウント
        Next i
        If Radio_Rise.Checked = True Then
            Kind = DIO_INT_RISE
        Else
            Kind = DIO_INT_FALL
        End If
        '--------------------------------------
        ' 各ビットごとに
        '--------------------------------------
        For BitNo = 0 To 3
            '--------------------------------------
            ' 割り込みイベント設定
            '--------------------------------------
            Ret = DioNotifyInterrupt(Id, BitNo, Kind, 0)
            If (Ret <> DIO_ERR_SUCCESS) Then
                Exit For
            End If
        Next BitNo
        '--------------------------------------
        ' エラー処理
        '--------------------------------------
        Call DioGetErrorString(Ret, szError)
        Edit_ReturnCode.Text = "DioNotifyInterrupt Ret = " & Ret & ":" & szError.ToString()

    End Sub

    '---------------------------------------------------------
    ' 割り込み停止
    '---------------------------------------------------------
    Private Sub Button_IntStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_IntStop.Click

        Dim BitNo As Short

        '--------------------------------------
        ' 各ビットごとに
        '--------------------------------------
        For BitNo = 0 To 3
            '--------------------------------------
            ' 割り込みイベント停止
            '--------------------------------------
            Ret = DioNotifyInterrupt(Id, BitNo, DIO_INT_NONE, 0)
            If (Ret <> DIO_ERR_SUCCESS) Then
                Exit For
            End If
        Next BitNo
        '--------------------------------------
        ' エラー処理
        '--------------------------------------
        Call DioGetErrorString(Ret, szError)
        Edit_ReturnCode.Text = "DioNotifyInterrupt Ret = " & Ret & ":" & szError.ToString()

    End Sub

    '---------------------------------------------------------
    ' DioExit()
    '---------------------------------------------------------
    Private Sub Button_DioExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_DioExit.Click

        '--------------------------------------
        ' DioExit()
        '--------------------------------------
        Ret = DioExit(Id)
        '--------------------------------------
        ' エラー処理
        '--------------------------------------
        Call DioGetErrorString(Ret, szError)
        Edit_ReturnCode.Text = "DioExit Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '---------------------------------------------------------
    ' ダイアログExit
    '---------------------------------------------------------
    Private Sub Button_Exit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_Exit.Click

        '--------------------------------------
        ' DioExit()
        '--------------------------------------
        Ret = DioExit(Id)
        '--------------------------------------
        ' 割り込み処理用デリゲートのガベージコレクションハンドルを開放
        '--------------------------------------
        If gCh.IsAllocated = True Then
            gCh.Free()
        End If
        '--------------------------------------
        ' ダイアログExit
        '--------------------------------------
        End
    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

    '---------------------------------------------------------
    ' コントロール操作用同期関数
    '---------------------------------------------------------
    Sub SetCountText(ByVal BitNo As Integer, ByVal Kind As Integer)
        Edit_Up(BitNo).Text = CStr(UpCount(BitNo))
        Edit_Down(BitNo).Text = CStr(DownCount(BitNo))
    End Sub

    '---------------------------------------------------------
    ' コールバックルーチン
    '---------------------------------------------------------
    Protected Sub CallBackProc(ByVal Id As Short, ByVal wParam As Integer, ByVal lParam As Integer, ByVal Param As IntPtr)
        Dim BitNo As Short
        Dim Kind As Short

        BitNo = HiLoWord(lParam, 0)            '割り込みビット番号
        Kind = HiLoWord(lParam, 1)              '立ち上がり:1, 立ち下がり:2

        If (Kind And DIO_INT_RISE) Then
            UpCount(BitNo) = UpCount(BitNo) + 1           'アップカウント
        End If
        If (Kind And DIO_INT_FALL) Then
            DownCount(BitNo) = DownCount(BitNo) + 1         'ダウンカウント
        End If
        '--------------------------------------
        ' カウント値表示
        '--------------------------------------
        Invoke(New SetCountDelegate(AddressOf SetCountText), New Object() {BitNo, Kind})
    End Sub
End Class