本文介绍了HIDDevice与Teensy的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


我有一个问题连接Teensy 3.2到通用应用程序HID设备。我有以下代码:

 Public NotInheritable Class MainPage 
Inherits Page
Public Sub New()

'Dieser Aufrufistfürden设计师erforderlich。
InitializeComponent()
$ b $b'FügenSieInitialisierungen nach dem InitializeComponent() - Aufruf hinzu。
EnumerateHidDevices()
End Sub


Public Async Sub EnumerateHidDevices()

Dim VID As UShort =& H16C0
Dim PID As UShort =& H486
Dim usagePage As UShort =& HFFAB
Dim usageID As UShort =& H200

Dim selector As String = HidDevice.GetDeviceSelector( usagePage,usageID,VID,PID)

Dim devices = Await DeviceInformation.FindAllAsync(selector)


if devices.Count> 0然后
For Each item in devices
Debug.WriteLine(String.Format(" Device found:{0} {1}",item.Name,item.Id))
下一个
device = Await HidDevice.FromIdAsync(devices.ElementAt(0).Id,FileAccessMode.ReadWrite).AsTask
Dim deviceAccessStatus = DeviceAccessInformation.CreateFromId(devices.ElementAt(0).Id)。CurrentStatus
'tpt = ThreadPoolTimer.CreatePeriodicTimer(AddressOf TimerTick,New TimeSpan(0,0,30))
Else
Debug.WriteLine("未找到USB HID设备")

End if
End Sub

Private Sub TimerTick(timer As ThreadPoolTimer)
Dim data(144 * 40 * 3 + 1)As Byte
data( 0)= Encoding.ASCII.GetBytes(" *")。First
For i As Integer = 1 To data.Count - 1
data(i)= 20
Next
ReadWriteToHidDevice()
Debug.WriteLine ("HID数据:")


结束Sub

Public Sub ReadWriteToHidDevice()
Dim sResult As String = String.Empty
如果Not device is Nothing则
Dim dw As DataWriter = New DataWriter


'dw.WriteBytes(data)

'outReport.Data = dw.DetachBuffer
'等待device.SendOutputReportAsync(outReport)
''发送完成



''现在回读数据
'Dim inReport As HidInputReport = Await device.GetInputReportAsync

'如果Not inReport Is Nothing则
'Dim id As UInt16 = inReport.Id
'Dim dr As DataReader = DataReader。 FromBuffer(inReport.Data)
'昏暗的结果(CInt(dr.UnconsumedBufferLength))As Byte
'dr.ReadBytes(result)
' sResult = BitConverter.ToString(result)
'Else
'Debug.WriteLine(""收到的输入无效")
'结束如果
否则
Debug.WriteLine( "Device is NULL")
结束如果
'返回sResult
结束Sub
私有设备As HidDevice
私人tpt As ThreadPoolTimer


结束等级



并且另外还有appmanifest

<! -  HID设备 - > 
< DeviceCapability Name =" humaninterfacedevice">
< Device Id =" vidpid:16c0 0486 usb">
<功能类型="用法:0200 *" />
< / Device>
< / DeviceCapability>

因此,如果我启动应用程序,现场设备将只找到一个控制器。我觉得没关系。但是,当我想打开连接字段"设备"时,保持空白。


我还尝试了很多不同的设置。查看Windows设备管理器并使用usbview工具。我无法找到错误。 


Teensy的HID Raw描述如下:  https://www.pjrc.com/teensy/rawhid.html



主要目标是在RaspberryPi3和Teensy之间进行沟通。对于测试使用我的Surface Pro。但事情发生了。感谢您的帮助!



问候




解决方案

Hello!

I have a Problem Connection a Teensy 3.2 to a Universal App HID Device. I have the following Code:

Public NotInheritable Class MainPage
    Inherits Page
    Public Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        EnumerateHidDevices()
    End Sub


    Public Async Sub EnumerateHidDevices()

        Dim VID As UShort = &H16C0
        Dim PID As UShort = &H486
        Dim usagePage As UShort = &HFFAB
        Dim usageID As UShort = &H200

        Dim selector As String = HidDevice.GetDeviceSelector(usagePage, usageID, VID, PID)

        Dim devices = Await DeviceInformation.FindAllAsync(selector)


        If devices.Count > 0 Then
            For Each item In devices
                Debug.WriteLine(String.Format("Device found: {0}{1}", item.Name, item.Id))
            Next
            device = Await HidDevice.FromIdAsync(devices.ElementAt(0).Id, FileAccessMode.ReadWrite).AsTask
            Dim deviceAccessStatus = DeviceAccessInformation.CreateFromId(devices.ElementAt(0).Id).CurrentStatus
            '            tpt = ThreadPoolTimer.CreatePeriodicTimer(AddressOf TimerTick, New TimeSpan(0, 0, 30))
        Else
            Debug.WriteLine("No USB HID device found")

        End If
    End Sub

    Private Sub TimerTick(timer As ThreadPoolTimer)
        Dim data(144 * 40 * 3 + 1) As Byte
        data(0) = Encoding.ASCII.GetBytes("*").First
        For i As Integer = 1 To data.Count - 1
            data(i) = 20
        Next
        ReadWriteToHidDevice()
        Debug.WriteLine("HID Data: ")


    End Sub

    Public Sub ReadWriteToHidDevice()
        Dim sResult As String = String.Empty
        If Not device Is Nothing Then
            Dim dw As DataWriter = New DataWriter


            '    dw.WriteBytes(data)

            '    outReport.Data = dw.DetachBuffer
            '    Await device.SendOutputReportAsync(outReport)
            '    'Sending done



            '    'Now read back data
            '    Dim inReport As HidInputReport = Await device.GetInputReportAsync

            '    If Not inReport Is Nothing Then
            '        Dim id As UInt16 = inReport.Id
            '        Dim dr As DataReader = DataReader.FromBuffer(inReport.Data)
            '        Dim result(CInt(dr.UnconsumedBufferLength)) As Byte
            '        dr.ReadBytes(result)
            '        sResult = BitConverter.ToString(result)
            '    Else
            '        Debug.WriteLine("Invalid input received")
            '    End If
        Else
            Debug.WriteLine("Device is NULL")
        End If
        'Return sResult
    End Sub
    Private device As HidDevice
    Private tpt As ThreadPoolTimer


End Class


and in Addition the appmanifest

 <!-- HID Device -->
    <DeviceCapability Name="humaninterfacedevice">
      <Device Id="vidpid:16c0 0486 usb">
        <Function Type="usage:0200 *"/>
      </Device>
    </DeviceCapability>

So if i start the app the field devices will find exactly one Controller. I think thats ok. But when i want to open the Connection the field "device" stays empty.

I still have tried many different Settings. Took a look into Windows device Manager and used the usbview-tool. I cant find the error. 

The HID Raw description for Teensy is here: https://www.pjrc.com/teensy/rawhid.html

The main Goal is to communicate between RaspberryPi3 and Teensy. For testing is used my Surface Pro. But anything happens. Thanks for helping!

Greetings

解决方案


这篇关于HIDDevice与Teensy的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:49