主题 : 6410 的GPIO怎么收不到东西呢? 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 118888
精华: 0
发帖: 7
金钱: 35 两
威望: 7 点
贡献值: 0 点
综合积分: 14 分
注册时间: 2015-09-11
最后登录: 2015-12-23
楼主  发表于: 2015-10-17 12:29

 6410 的GPIO怎么收不到东西呢?

部分程序如下:

    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,不管按那个键
级别: 新手上路
UID: 118888
精华: 0
发帖: 7
金钱: 35 两
威望: 7 点
贡献值: 0 点
综合积分: 14 分
注册时间: 2015-09-11
最后登录: 2015-12-23
1楼  发表于: 2015-10-17 12:52
我用
ReadFile(hPort, rBuf, 4, rLen, IntPtr.Zero)
可以收到按键,但这只是只读