yinlong416 发表于 2008-11-10 15:48

关于HID设备的读写问题,求助高手?

   一个类似传感器的设备,用usb线连接到电脑上,在windows下通过查看资源管理器可以看到被识别为人体学输入设备。
在Mac(10.4.9的系统)下通过Xcode自带的USB Prober和IORegistryExplorer都可以看到设备的注册信息,部分注册信息是:
VendorID / ProductID : 0x10C4 / 0x0001
Usage Page : 65280(0xFF00)
Usage : 1(0x1)

比如一个串口设备,首先调用open()函数打开设备文件,然后调用write()函数来发送数据,如发送一个‘r‘,只需要write(fd,"r",1),就可以了,读取数据调用read()函数。

   此设备接入电脑后也需要发送一个指令,一个字节的数据(比如'm'),使其开始工作,然后它会把采集到的数据传回。
   我在苹果官网上下了一个HID Manager Basics的示例代码,改下usage page为62580、usage为1就可以读到这个设备的所有信息,但是无法发送数据和接收数据。请问哪位高手能够告诉我,通过调用哪些函数可以向其发送数据(比如一个字符“m”)和接收数据,不胜感激!

sinoman 发表于 2008-11-10 15:58

一,你需要看apple 的驱动程序支持usage page 62580这种设备吗?
二,你的设备是否是标准设备,没有任何自定义的数据格式?
如果一和二都不满足,你需要写一个hid的驱动程序来支持。应用层对设备进行访问的基础是驱动程序已经提供了对设备的访问支持。

sinoman 发表于 2008-11-10 15:59

注册一年发一贴,潜的够深的:mrgreen:

yinlong416 发表于 2008-11-10 16:10

你好,我看了mac下IOKit.framwork/hid/IOHIDUsageTables.h中Usage Pages的定义有:
/* Reserved 0x92 - 0xFEFF */
/* VendorDefined 0xFF00 - 0xFFFF */
kHIDPage_VendorDefinedStart = 0xFF00
   0xFF00在十进制下就等于62580,不知道这个是什么意思,这个设备以前用的就是USBtoUART的芯片CP2102,装上驱动后就可以直接在/dev目录下直接读写串口文件,所以我也不知道有没有自定义的数据格式。现在改为了转HID的芯片,比如常用的向设备发送数据的方法是什么样的,谢谢。

yinlong416 发表于 2008-11-10 16:13

原帖由 sinoman 于 2008-11-10 15:59 发表 http://bbs2.chinaunix.net/images/common/back.gif
注册一年发一贴,潜的够深的:mrgreen:



不好意思,以前还是学生啊,遇到的问题不多,老师就可以解答了,主要是来学习为主,现在不一样了,呵呵...

sinoman 发表于 2008-11-10 16:19

原帖由 yinlong416 于 2008-11-10 16:10 发表 http://bbs3.chinaunix.net/images/common/back.gif
你好,我看了mac下IOKit.framwork/hid/IOHIDUsageTables.h中Usage Pages的定义有:
/* Reserved 0x92 - 0xFEFF */
/* VendorDefined 0xFF00 - 0xFFFF */
kHIDPage_VendorDefinedStart = 0xFF00
   0xFF00 ...
装上驱动后,你装的什么驱动呢?是mac os x的吗?以前可以在mac os x下读出来吗?你用IORegistryExplorer这个工具看下你的设备加载的哪个系统驱动。

sinoman 发表于 2008-11-10 16:22

你贴一下usb probe里关于设备的信息和驱动的信息。

yinlong416 发表于 2008-11-10 16:28

Full Speed device @ 2 (0x50100000): .............................................   Composite device: "C8051F320 Development Board"
    Device Descriptor   
      Descriptor Version Number:       0x0110
      Device Class:      0   (Composite)
      Device Subclass:   0
      Device Protocol:      0
      Device MaxPacketSize:    64
      Device VendorID/ProductID:   0x10C4/0x0001   (Cygnal Integrated Products, Inc.)
      Device Version Number:   0x0000
      Number of Configurations:   1
      Manufacturer String:      1 "SILICON LABORATORIES"
      Product String:      2 "C8051F320 Development Board"
      Serial Number String:   0 (none)
    Configuration Descriptor   
      Length (and contents):   41
            Raw Descriptor (hex)      0000: 09 02 29 00 01 01 00 8020 09 04 00 00 02 03 00
            Raw Descriptor (hex)      0010: 00 00 09 21 01 01 00 0122 1B 00 07 05 81 03 08
            Raw Descriptor (hex)      0020: 00 01 07 05 02 03 08 0001
      Number of Interfaces:   1
      Configuration Value:   1
      Attributes:       0x80 (bus-powered)
      MaxPower:       64 ma
      Interface #0 - HID   
            Alternate Setting      0
            Number of Endpoints   2
            Interface Class:      3   (HID)
            Interface Subclass;   0
            Interface Protocol:      0
            HID Descriptor   
                Descriptor Version Number:    0x0101
                Country Code:      0
                Descriptor Count:   1
                Descriptor 1   
                  Type:       0x22(Report Descriptor)
                  Length (and contents):    27
                        Raw Descriptor (hex)   0000: 06 00 FF 09 01 A1 01 0901 95 08 75 08 26 FF 00
                        Raw Descriptor (hex)   0010: 15 00 09 01 81 02 09 0191 02 C0
                  Parsed Report Descriptor:   
                        Usage Page      (65280)
                        Usage 1 (0x1)   
                              Collection (Application)   
                              Usage 1 (0x1)   
                              Report Count............    (8)
                              Report Size.............   (8)
                              Logical Maximum........(255)
                              Logical Minimum.........(0)
                              Usage 1 (0x1)   
                              Input...................    (Data, Variable, Absolute, No Wrap, Linear, Preferred State, No Null Position, Bitfield)
                              Usage 1 (0x1)   
                              Output..................    (Data, Variable, Absolute, No Wrap, Linear, Preferred State, No Null Position, Nonvolatile, Bitfield)
                              End Collection   
            Endpoint 0x81 - Interrupt Input   
                Address:       0x81(IN)
                Attributes:      0x03(Interrupt no synchronization data endpoint)
                Max Packet Size:   8
                Polling Interval:      1 ms
            Endpoint 0x02 - Interrupt Output   
                Address:       0x02(OUT)
                Attributes:      0x03(Interrupt no synchronization data endpoint)
                Max Packet Size:   8
                Polling Interval:      1 ms
      IORegistryExplorer
IOUSB->Root->UHCI Root Hub Simulation->C8051F320 Development Board@50100000
object: Class:C8051F320 Development Board@50100000 : IOUSBDevice
Inheritance:    OSObject:IORegistryEntry : IOService : IOUSBNub : IOUSBDevice
Attributes:    registered, matched, active, busy 0, retain 9
Key   TypeValue
bDeviceSubClass   Number 0 (0)
idVendor    Number 4292 (0x10c4)
PortNum    Number 1 (0x1)
bDeviceSbuClass   Number 0 (0)
Bus Power AvailableNumber 250 (0xfa)
IOGeneralInterest   StringIOCommand is not serializable
bDeviceSubClass   Number 0 (0)
USB Product Name   StringC8051F320 Development Board
PortNum    Number 1 (0x1)
PortNum    Number 1 (0x1)
USB Vendor Name   StringSILICON LABORATORIES
          >IOCFPlugInTypes   Dictionary (1 Key/Value Pair)
         9dc7b780-9ec0-11d4-a54f-000a27052861 String   IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle
bDeviceSubClass   Number 0 (0)
bDeviceSubClass   Number 0 (0)
sessionID    Number 7564671950386(0x6e149959e32)
iProduct    Number 2 (0x2)
bMaxPacketSize0   Number 64 (0x40)
locationID    Number 1343225856(0x50100000)
Need comtiguous memory for isoch BooleanYes
PortNum    Number0 (0x1)
IOUserClientClass   StringIOUSBDeviceUserClient
PortNum    Number 1 (0x1)
USB Address   Number 3 (0x3)

yinlong416 发表于 2008-11-10 16:30

下面是IORegistry里的信息,这个设备不是标准设备,usage page是厂商设定的,数据类型应该是无格式的。

sinoman 发表于 2008-11-10 16:35

如果只是简单的HID设备输入输出的话,去apple网站找应用程序访问指定的usb设备pipe的方法,我见过相关的文档。
页: [1] 2
查看完整版本: 关于HID设备的读写问题,求助高手?