When I try to write something to the COM port via the command line in the android, I just write in the shell: echo 123abc > /dev/ttyO0 and get it in the terminal. It's simple. If I try to do the same in android:
final byte[] request = {0x0A, 0x10, 0, (byte)0x99, 0, 0x01, (byte)0xD0, (byte)0x9D}; final String comPortAddress = "/dev/ttyO0"; final OutputStream fileOutputStream = new FileOutputStream(comPortAddress); fileOutputStream.write(request); fileOutputStream.flush(); fileOutputStream.close(); That get an exception:
W/System.err: java.io.FileNotFoundException: /dev/ttyO0: open failed: EACCES (Permission denied) W/System.err: at libcore.io.IoBridge.open(IoBridge.java:416) W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:88) W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:128) W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:117) W/System.err: at keppowertesting.com.modbustesterapp.TryStreams.go(TryStreams.java:15) W/System.err: at keppowertesting.com.modbustesterapp.MainActivity.button2Click(MainActivity.java:49) W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) W/System.err: at java.lang.reflect.Method.invoke(Method.java:511) W/System.err: at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) W/System.err: at android.view.View.performClick(View.java:4204) W/System.err: at android.view.View$PerformClick.run(View.java:17355) W/System.err: at android.os.Handler.handleCallback(Handler.java:725) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:92) W/System.err: at android.os.Looper.loop(Looper.java:137) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5041) W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) W/System.err: at java.lang.reflect.Method.invoke(Method.java:511) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) W/System.err: at dalvik.system.NativeStart.main(Native Method) W/System.err: **Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)** W/System.err: at libcore.io.Posix.open(Native Method) W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) W/System.err: at libcore.io.IoBridge.open(IoBridge.java:400) W/System.err: ... 19 more I have a line in the manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="25"/> But it is clearly not enough. Root access on the device is present.