SSPC-Tester/Driver/急停报警相关资料/PCI2312 Samples/VB.net/Simple/INT/Module1.vb

61 lines
1.6 KiB
VB.net
Raw Normal View History


Module Module1
Dim hDevice As Integer
Dim hEventInt As Integer
Dim DeviceID As Int32
Dim inIntCount As Int32 = 0 ' 内部中断计数
Dim outIntCount As Int32 = 0 ' 外部中断计数
Dim Flag As Int32
Dim key As IntPtr
Sub Main()
DeviceID = 0
hDevice = PCI2312_CreateDevice(DeviceID)
If (hDevice = INVALID_HANDLE_VALUE) Then
Console.WriteLine("CreateDevice Error...")
_getch()
Return
End If
hEventInt = PCI2312_CreateSystemEvent()
If (hEventInt = INVALID_HANDLE_VALUE) Then
Console.WriteLine("CreateSystemEvent Error...")
_getch()
Return
End If
If (PCI2312_InitDeviceInt(hDevice, hEventInt) = False) Then ' 初始化中断
Console.WriteLine("Wait....\n")
End If
While (_kbhit() = 0)
While (True)
If (WaitForSingleObject(hEventInt, 100) = 0) Then ' 等待中断发生
GoTo Read
End If
If (_kbhit() <> 0) Then
GoTo Exit1
End If
End While
Read:
outIntCount = outIntCount + 1 '外部中断计数
inIntCount = PCI2312_GetDeviceIntCount(hDevice) ' 获得内部中断计数
Console.WriteLine("outIntCount={0}, inIntCount={1}", outIntCount, inIntCount)
End While
Exit1:
PCI2312_ReleaseDeviceInt(hDevice) ' 释放中断资源
PCI2312_ReleaseDevice(hDevice) ' 释放设备对象
Return
End Sub
End Module