错误:您没有串行端口的读/写权限

时间:2014-08-22 09:29:41

标签: android serial-port

我有一个示例应用程序,可以从here的串口读取。

我已将设备设置为ttyUSB1(usbserial),波特率设置为9600

但是当我点击控制台时,我得到了Error: You do not have read/write permission to the serial port

我的logcat是

  08-22 15:01:25.210: W/System.err(14524): java.io.IOException: Error running exec(). Command:   
  [/system/bin/su] Working Directory: null Environment: null
  08-22 15:01:25.210: W/System.err(14524):  at   
  java.lang.ProcessManager.exec(ProcessManager.java:211)

   08-22 15:01:25.211: W/System.err(14524):     at java.lang.Runtime.exec(Runtime.java:168)
   08-22 15:01:25.211: W/System.err(14524):     at java.lang.Runtime.exec(Runtime.java:241)
   08-22 15:01:25.212: W/System.err(14524):     at java.lang.Runtime.exec(Runtime.java:184)
   08-22 15:01:25.212: W/System.err(14524):     at android_serialport_api.SerialPort.<init>  
   (SerialPort.java:47)
  08-22 15:01:25.212: W/System.err(14524):  at   
  android_serialport_api.sample.Application.getSerialPort(Application.java:46)
  08-22 15:01:25.213: W/System.err(14524):  at  
  android_serialport_api.sample.SerialPortActivity.onCreate(SerialPortActivity.java:78)
  08-22 15:01:25.213: W/System.err(14524):  at   
  android_serialport_api.sample.Sending01010101Activity.onCreate(Sending01010101Activity.java:31)
  08-22 15:01:25.214: W/System.err(14524):  at   
  android.app.Activity.performCreate(Activity.java:5020)
  08-22 15:01:25.214: W/System.err(14524):  at   
  android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  08-22 15:01:25.214: W/System.err(14524):  at   
   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
   08-22 15:01:25.214: W/System.err(14524):     at  
  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
 08-22 15:01:25.215: W/System.err(14524):   at   
 android.app.ActivityThread.access$600(ActivityThread.java:149)
 08-22 15:01:25.215: W/System.err(14524):   at  
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
 08-22 15:01:25.215: W/System.err(14524):   at   
 android.os.Handler.dispatchMessage(Handler.java:99)
  08-22 15:01:25.216: W/System.err(14524):  at android.os.Looper.loop(Looper.java:153)
  08-22 15:01:25.216: W/System.err(14524):  at  
  android.app.ActivityThread.main(ActivityThread.java:4987)
  08-22 15:01:25.216: W/System.err(14524):  at java.lang.reflect.Method.invokeNative(Native   
 Method)
 08-22 15:01:25.216: W/System.err(14524):   at java.lang.reflect.Method.invoke(Method.java:511)
 08-22 15:01:25.217: W/System.err(14524):   at   
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
  08-22 15:01:25.217: W/System.err(14524):  at    
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
     08-22 15:01:25.217: W/System.err(14524):   at dalvik.system.NativeStart.main(Native Method)
     08-22 15:01:25.217: W/System.err(14524): Caused by: java.io.IOException: No such file or          
    directory
    08-22 15:01:25.218: W/System.err(14524):    at java.lang.ProcessManager.exec(Native Method)
   08-22 15:01:25.219: W/System.err(14524):     at  
   java.lang.ProcessManager.exec(ProcessManager.java:209)
   08-22 15:01:25.219: W/System.err(14524):     ... 21 more

我该如何解决这个问题。

请帮助解决这个问题。

2 个答案:

答案 0 :(得分:1)

如果您使用串口应用程序,请转到文件SerialPort.java

更改行:

su = Runtime.getRuntime().exec("/system/bin/su");

su = Runtime.getRuntime().exec("/system/xbin/su");

答案 1 :(得分:0)

  

错误:您没有串行端口的读/写权限

只需将bin更改为xbin

像这样,Runtime.getRuntime().exec("/system/xbin/su");