博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 下的 USB HID 设备读写
阅读量:7063 次
发布时间:2019-06-28

本文共 1075 字,大约阅读时间需要 3 分钟。

  1. UsbInterface usbInterface = usbDevice.getInterface(0);  
  2. //USBEndpoint为读写数据所需的节点  
  3. UsbEndpoint inEndpoint = usbInterface.getEndpoint(0);  //读数据节点  
  4. UsbEndpoint outEndpoint = usbInterface.getEndpoint(1); //写数据节点  
  5. UsbDeviceConnection connection = usbManager.openDevice(usbDevice);  
  6. connection.claimInterface(usbInterface, true);  
  7.   
  8. //发送数据  
  9. byte[] byte2 = new byte[64];  
  10. int out = connection.bulkTransfer(outEndpoint, cmd, cmd.length, 3000);  
  11.   
  12. //读取数据1   两种方法读取数据  
  13. int ret = connection.bulkTransfer(inEndpoint, byte2, byte2.length, 3000);  
  14. Log.e("ret""ret:"+ret);  
  15. for(Byte byte1 : byte2){  
  16.     System.err.println(byte1);  
  17. }  
  18.   
  19. //读取数据2  
  20. /*int outMax = outEndpoint.getMaxPacketSize(); 
  21. int inMax = inEndpoint.getMaxPacketSize(); 
  22. ByteBuffer byteBuffer = ByteBuffer.allocate(inMax); 
  23. UsbRequest usbRequest = new UsbRequest(); 
  24. usbRequest.initialize(connection, inEndpoint); 
  25. usbRequest.queue(byteBuffer, inMax); 
  26. if(connection.requestWait() == usbRequest){
     
  27.     byte[] retData = byteBuffer.array(); 
  28.     for(Byte byte1 : retData){
     
  29.         System.err.println(byte1); 
  30.     } 
  31. }*/  

原文:

 

参考:

转载于:https://www.cnblogs.com/blueice-007/p/3534338.html

你可能感兴趣的文章
我的友情链接
查看>>
Linux下重启网络服务
查看>>
随笔-I/O流
查看>>
Cent OS下修改用户打开文件数限制
查看>>
我的友情链接
查看>>
java第六次作业
查看>>
Windows Server 2012 R2 DirectAccess功能测试(3)—App2服务器安装及配置
查看>>
VirtualBox修改CentOS系统的MAC地址
查看>>
Centos 6.7 安张nagios和cacti 并添加监控主机
查看>>
css reset
查看>>
pancake的排序- 1.3 一摞烙饼的排序 《编程之美》读书笔记03
查看>>
批量恢复zencart产品表所属分类master_categories_id为0的产品
查看>>
初识汇编(二)
查看>>
hihoCoder1044 (状态压缩DP)
查看>>
hdu2067 卡特兰数
查看>>
回档|忠诚2|zkw线段树
查看>>
P2456 - 膜拜神犇
查看>>
杭电1513--Palindrome(滚动数组+LCS)
查看>>
杭电1465--不容易系列之一
查看>>
上三角
查看>>