-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关闭串口后,阻塞的read不会抛异常中止 #40
Comments
|
邮件已收到。 ——雨季余静
|
代码应该是没问题的,无非就是 open、read、close。或许跟环境和串口驱动有关吧,不太确定,我这里确实是有这个问题的。 Android 5以上版本的 FileInputStream 构造函数有个 isFdOwner的参数,通过反射将其改为true就是正常的,修改后,close 时会调用 |
关闭 串口后 , inputStream.read 是不会抛异常的。 所以要想办法关掉。
…------------------ 原始邮件 ------------------
发件人: ***@***.***>;
发送时间: 2022年1月11日(星期二) 下午5:37
收件人: ***@***.***>;
抄送: ***@***.***>; ***@***.***>;
主题: Re: [licheedev/Android-SerialPort-API] 关闭串口后,阻塞的read不会抛异常中止 (Issue #40)
我这里都会抛异常 read interrupted.应该是你代码写的不对吧。
代码应该是没问题的,无非就是 open、read、close。或许跟环境和串口驱动有关吧,不太确定,我这里确实是有这个问题的。
Android 5以上版本的 FileInputStream 构造函数有个 isFdOwner的参数,通过反射将其改为true就是正常的,修改后,close 时会调用 IoBridge.closeAndSignalBlockedThreads(fd) 就能抛出 Interrupt 异常。
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.Message ID: ***@***.***>
|
我也复现了你说的情况:关闭串口,仍然还在阻塞read |
@yutils 在每次
可以正常退出读线程 实际上这个问题我也遇到过,不止串口,写tcp的socket通信时候也遇到过。 |
使用 yutils 的方法基本能规避这个问题,当然也确实存在你说的 cpu 空转的情况。 另外,库里面初始化 InputStream 的时候,构造方法如果再加一个参数
|
我上面的方法都没不适用我这个应用,我现在的做法是,用一个全局的viewmodel 一直做阻塞读,读到就写到livedata中,然后要用的时候就在具体的UI界面observe全局的livedata。 |
InputStream.available() 始终为0 但实际有数据 |
关闭串口时,如果正在 read inputStream,串口和inputStream关闭后,read仍然处于阻塞状态不会终止
The text was updated successfully, but these errors were encountered: