安卓串口编程中遇到的坑

安卓串口编程中遇到的坑

Long monitor contention with owner Thread-7 (3600) at int libcore.io.Posix.readBytes(java.io.FileDescriptor, java.lang.Object, int, int)
(Posix.java:-2) waiters=0 in void com.kongqw.serialportlibrary.thread.SerialPortReadThread.closeRevData() for 2.950s

2019-06-05 10:04:34.076 26076-26161/com.gpinfo.chuanyisoft W/System.err: java.lang.InterruptedException
2019-06-05 10:04:34.076 26076-26161/com.gpinfo.chuanyisoft W/System.err: at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1218)
2019-06-05 10:04:34.076 26076-26161/com.gpinfo.chuanyisoft W/System.err: at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:312)

莫名其妙的串口的读写线程出现了异常,添加了判断机制,每次判断读写线程是否存在,不存在则重启,并且是tcflush()清空缓冲区,记得一定要清空。不然会出现数据叠包,因为读写线程虽然被中断了,但是有些数据还停留在缓冲区中,如果不清空的话,一定会扰乱程序的逻辑,叠包等情况的出现。一直没有查到中断读写线程的根源,不过能使程序正常的跑起来。

你可能感兴趣的:(安卓串口编程中遇到的坑)