android虚拟机串口使用问题

digiman 2016-10-22 10:52:30
首先我使用虚拟串口软件在windows上虚拟了两个串口COM5<--->COM6 两个虚拟串口可以互相收发

使用windows的串口5启动虚拟机
emulator @Nexus_5X_API_23 -qemu -serial COM5
使用adb shell 命令进入命令行
chmod 777 /dev/ttyS1
echo "test" >/dev/ttyS1
然后可以在COM6收到test字符

问题有两个:
1. 虽然已经用chmod 修改了ttyS1的权限,但是device.canRead()仍然返回false
2. 在虚拟机上执行这个命令就出现异常了,程序异常退出
su = Runtime.getRuntime().exec("/system/bin/su");

if (!device.canRead() || !device.canWrite()) {
try {
/* Missing read/write permission, trying to chmod the file */
Process su;
su = Runtime.getRuntime().exec("/system/bin/su");
String cmd = "chmod 777 " + device.getAbsolutePath() + "\n"
+ "exit\n";
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0) || !device.canRead()
|| !device.canWrite()) {
throw new SecurityException();
}
} catch (Exception e) {
e.printStackTrace();
throw new SecurityException();
}
...全文
919 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
digiman 2018-03-14
  • 打赏
  • 举报
回复
你这参数COM 要提定是哪一个COM 设备管理里去看下哪一 个COM可用
qq_39126738 2018-01-15
  • 打赏
  • 举报
回复

楼主这个问题怎么解决
邱金金 2017-03-12
  • 打赏
  • 举报
回复
楼主解决了吗,我也是遇到这个问题,一模一样,但我的是在真机上运行抛出的java.io.IOException: Error running exec(). Command: [/system/bin/su] Working Directory: null Environment: null,真不知道怎么搞了,
digiman 2016-10-22
  • 打赏
  • 举报
回复

执行/system/bin/su时异常信息为

java.io.IOException: Error running exec(). Command: [/system/bin/su] Working Directory: null Environment: null
digiman 2016-10-22
  • 打赏
  • 举报
回复
虚拟机串口权限已经是可读写的 crwxrwxrwx system system 4, 64 2016-10-22 02:15 ttyS0 crwxrwxrwx system system 4, 65 2016-10-22 02:15 ttyS1 crwxrwxrwx system system 4, 66 2016-10-22 02:15 ttyS2 crwxrwxrwx system system 4, 67 2016-10-22 02:15 ttyS3
digiman 2016-10-22
  • 打赏
  • 举报
回复
自已顶一下, 在真机上运行apk是可以的,可以正常open

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧