部分程序如下:
Declare Function CreateFile Lib "coredll.dll" Alias "CreateFile" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As UInteger, ByVal hTemplateFile As IntPtr) As IntPtr
Declare Function DeviceIoControl Lib "coredll.dll" Alias "DeviceIoControl" (ByVal hDevice As System.IntPtr, ByVal dwIoControlCode As UInteger, ByVal lpInBuffer() As Byte, ByVal nInBufferSize As UInteger, ByVal lpOutBuffer() As Byte, ByVal nOutBufferSize As UInteger, ByVal lpBytesReturned As UInteger, ByVal lpOverlapped As System.IntPtr) As Boolean
Declare Function CloseHandle Lib "coredll.dll" Alias "CloseHandle" (ByVal hDevice As System.IntPtr) As Boolean
Const OPEN_EXISTING = 3
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const INVALID_HANDLE_VALUE = -1
' Constant from GPIO Driver
Const PORT_A = &H0
Const PORT_B = &H10
Const PORT_C = &H20
Const PORT_D = &H30
Const PORT_E = &H40
Const PORT_F = &H50
Const PORT_G = &H60
Const PORT_H = &H70
Const PORT_J = &H80
Const SET_OUTPUT = &H4
Const SET_INPUT = &H3
Const GET_PIN = &H2
Const SET_PIN_ON = &H1
Const SET_PIN_OFF = &H0
'初始化
hPort = CreateFile("KEY1:", GENERIC_READ Or GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
If (hPort = INVALID_HANDLE_VALUE) Then
MsgBox("Open GIO1 Driver Fail")
End If
'接收
If (hPort <> INVALID_HANDLE_VALUE) Then
' Get value from PORT F
DeviceIoControl(hPort, PORT_F Or GET_PIN, Nothing, 0, rBuf, rLen, 0, IntPtr.Zero)
' Convert rBuf(Array of Byte) to rOutput(UInt32)
rOutput = BitConverter.ToInt32(rBuf, 0)
' Loop pin position in PORT F
End If
rOutput始终为0,不管按那个键