如何刷新Java串行InputStream? [英] How do you flush a Java serial InputStream?
问题描述
我正在使用JavaComm,并从串行端口对象获取inputStream.我有一个问题,就是有时在系统启动时,缓冲区中会出现一些我不想要的噪音字符.我想初始化串行端口,然后在开始处理之前以某种方式刷新所有数据的输入.
I'm using JavaComm, and getting the inputStream from the serial port object. I have a problem in that sometimes when the system starts up there are noise characters in the buffer that I do not want. I want to initialize the serial port then somehow flush the input of all data before I begin my processing.
有什么办法吗?
TY 弗雷德
推荐答案
"flush()"方法如何知道什么是垃圾,什么是真实数据?只有您知道,您的程序应该准备忽略引导垃圾.
How would a "flush()" method know what is garbage and what is real data? Only you know, and your program should be prepared to ignore leading garbage.
如果可以绝对确定发送请求之前输入缓冲区中的所有数据都是垃圾,那么只需读取直到没有更多输入数据为止-即自己刷新它.
If you can be absolutely certain that all data in the input buffer prior to sending the request is garbage, then just read until there is no more input data -- i.e. flush it yourself.
这篇关于如何刷新Java串行InputStream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!