java代码在关闭串口时挂起 [英] java code hang in closing serial port
问题描述
嗨所有,
i为java中的自动端口读取编写代码它在窗口和linux(红帽)中工作正常但是当我用suse linux测试它时它特别悬挂端口(COM3和COM4)在关闭端口时有70个COM端口显示当我正在滑动这两个端口然后它正在检查所有其他端口但仅在这两个端口打开端口发送数据关闭输入/输出流,但当它关闭串口然后代码挂起,即使它没有给出任何例外
所以请帮助我尝试谷歌这么多但仍然问题是相同的/>
谢谢
hi All,
i wrote code for auto port reading in java it is working fine in window as well as linux(red hat) but when i am testing it with suse linux it is hanging for particular port(COM3 and COM4)at the time of closing the port there is 70 com port showing when i am skiping these two port then it is checking all other port but only in case these two it is opening port sending the data closing input /output stream but when it coming closing serial port then code got hang even it is not giving any exception
so please help i tried google so much but still problem is same
thanks
推荐答案
我记得有某种相同的问题。每次我尝试关闭端口,我的程序就会挂起。然后我发现我的关闭方法必须同步。做了类似的事情:
I remember having somehow the same problem. Each time i would try and close the port, my program would just hang. Then i figured out that my closing method had to be synchronized. And did something like this:
synchronized void closePort(){
if(serialPort!=null){
try{
output.close(); //the streams need to be closed
input.close();
}catch(IOException ex){
//display whatever error message i want
}
serialport.close();
serialport.removeEventListener();
}
}
这实际上对我有用。它并不多,但我希望它也适合你。
祝你好运。
And this actually worked for me. It''s not much, but i hope it will also work for you.
Best regards.
这篇关于java代码在关闭串口时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!