Java 串行通信 API - 如果发生超时,inputstream.read() 返回什么?
有人知道串行驱动程序超时时返回的确切值吗?我在Win XP 上运行Java1.5。
Anyone know the exact value returned when the serial driver times out? I'm running Java1.5 on Win XP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
javadoc 说什么?
read()
read(byte[])
read(byte[], int, int)
本机,InputStream 没有超时,因此这取决于司机如何报告结果。如果驱动程序报告 EOF,您只会得到 -1。如果驱动程序报告错误,您应该收到 IOException。
What does the javadoc say?
read()
read(byte[])
read(byte[], int, int)
Natively, the InputStream does not have timeouts, so it depends upon how the driver reports the results. If the driver reports EOF, you'll just get a -1. If the driver reports an error, you should get an IOException.
我不能说出确切的值,但我认为会抛出某种 IOException 。
如果您从通信端口获取输入流并从中读取,文档指出,如果“如果由于文件末尾以外的任何原因无法读取第一个字节,如果输入流已关闭,或者发生其他 I/O 错误。”
I can't speak for exact values, but I would have thought some sort of IOException would be thrown.
If you're getting the input stream from the comm port and reading from that, the docs state that an IOException will be thrown if "If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs."