Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 17-Mar-22 11:13am
Comments
Nagy Vilmos 23-Aug-11 8:17am    
Where is your code hanging?
Please edit the question and add a code snippet to give us mortals a chance.

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:

Java
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.
 
Share this answer
 
Comments
Sudhakar Shinde 17-May-13 4:09am    
How did you assume the problem asked is the same problem you faced? There can be multiple reasons for a program to hang.
nameJulian 17-May-13 6:43am    
I didn't assume...I just gave a solution in case it's a problem like mine. And I know there can be multiple reasons.
I solve this hang chosing the time out port, works normaly that way, but hangs:
port.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
Change this seting at the routine of closing port ading this line code:
port.setComPortTimeouts(SerialPort.TIMEOUT_NONBLOCKING, 0, 0);
The port will close without hang the program, but you will cant reopen the port used, only restarting the program.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900