树莓派的无法USB调式
2016-01-21 17:08
190 查看
问题简介:
由于香蕉派某芯片停产,要换为使用树莓派,但是树莓派连接电脑调试时,数据线插入电脑一直没有反应。折腾了半天无果,(下载驱动,360手机助手,豌豆荚都试过了)。
找到原因:
和做硬件的哥们请教了一下,发现是端口默认设置成了OTG模式,导致无法连接数据线调试。解决方案:
public void change2usb(){ File fileOTG = new File("/sys/devices/platform/sunxi_otg/otg_role"); File fileUDC = new File("/sys/bus/platform/devices/sunxi_usb_udc/otg_role"); if(fileOTG.exists()) { Log.i("USB_SWITCH", "note is /sys/devices/platform/sunxi_otg/otg_role"); usb_role = "/sys/devices/platform/sunxi_otg/otg_role"; } else if(fileUDC.exists()) { Log.i("USB_SWITCH", "note is /sys/bus/platform/devices/sunxi_usb_udc/otg_role"); usb_role = "/sys/bus/platform/devices/sunxi_usb_udc/otg_role"; } try { state = execCommand("cat " + usb_role); } catch(IOException e) { e.printStackTrace(); } Log.i("USB_SWITCH", "try to set usb as device"); try { FileWriter wr = new FileWriter(usb_role); wr.write("2"); wr.close(); return; } catch(IOException e) { Log.i("USB_SWITCH", " write \" error: " + e.getMessage()); return; } Log.i("USB_SWITCH", "try to set usb as host"); try { FileWriter wr = new FileWriter(usb_role); wr.write("1"); wr.close(); return; } catch(IOException e) { Log.i("USB_SWITCH", " write \" error: " + e.getMessage()); } public String execCommand(String command) throws IOException { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(command); InputStream inputstream = proc.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); while(line != null) { sb.append(line); sb.append(0xa); } Log.i("USB_SWITCH", "exec \"" + command + "\""); Log.i("USB_SWITCH", "output: ".append((line)).toString()); try { if(proc.waitFor() != 0) { Log.e("USB_SWITCH", "exec \"" + command + "\" fail! exit value = " + proc.exitValue()); } } catch(InterruptedException e) { System.err.println(e); } return sb.toString(); }
apk下载地址:
USBModeSwitch APK下载相关文章推荐
- 通过批处理来启动各种数据库服务的小技巧
- php_strip_whitespace和trim的搭配使用
- MySQL性能优化的最佳经验,随时补充
- maven 下载 源码和javadoc命令
- MYSQL存储过程:批量更新数据2(产品品牌)
- SNS 背后的技术: 消息流的推拉模式选择
- Android异步加载AsyncTask详解
- Codeforces 612E - Square Root of Permutation
- springmvc请求流程
- Android .so相关
- geoserver 问题解决
- Shell小记:lsmod
- 多线程运行方法
- 【那些年遇到过的面试题】关键字volatile
- 对抽象工厂模式的理解
- Linux驱动设计中相关知识点记录
- nginx tomcat 自动部署python脚本
- elasticsearch常用的概念整理
- UITableView的优化
- SQL提高查询效益之in、not in、between、like等条件讲述