Why do the outputs differ when I run this code using Netbeans 6.8 and Eclipse?

Posted by Vimal Basdeo on Stack Overflow See other posts from Stack Overflow or by Vimal Basdeo
Published on 2010-12-26T05:12:57Z Indexed on 2010/12/26 7:54 UTC
Read the original article Hit count: 231

Filed under:
|
|
|
|

When I am running the following codes using Eclipse and Netbeans 6.8. I want to see the available COM ports on my computer. When running in Eclipse it is returning me all available COm ports but when running t in Netbeans, it does not seem to find any ports ..

public static void test(){

    Enumeration lists=CommPortIdentifier.getPortIdentifiers();

        System.out.println(lists.hasMoreElements());
        while (lists.hasMoreElements()){
            CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();

            if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())){
                System.out.println("Name is serail portzzzz "+cn.getName()+" Owned status "+cn.isCurrentlyOwned());

                try{
                    SerialPort port1=(SerialPort)cn.open("ComControl",800000);
                    port1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                    System.out.println("Before get stream");
                    OutputStream out=port1.getOutputStream();
                    InputStream input=port1.getInputStream();
                    System.out.println("Before write");
                    out.write("AT".getBytes());
                    System.out.println("After write");
                    int sample=0;
                    //while((( sample=input.read())!=-1)){
                    System.out.println("Before read");
                        //System.out.println(input.read() + "TEsting ");
                    //}
                        System.out.println("After read");
                    System.out.println("Receive timeout is "+port1.getReceiveTimeout());
                }catch(Exception e){
                    System.err.println(e.getMessage());
                }
            }

            else{
                System.out.println("Name is parallel portzzzz "+cn.getName()+" Owned status "+cn.isCurrentlyOwned()+cn.getPortType()+"    ");
            }
        }

}

Output with Netbeans

false

Output using Eclipse

true Name is serail portzzzz COM1 Owned status false Before get stream Before write After write Before read After read Receive timeout is -1 Name is serail portzzzz COM2 Owned status false Before get stream Before write After write Before read After read Receive timeout is -1 Name is parallel portzzzz LPT1 Owned status false2
Name is parallel portzzzz LPT2 Owned status false2

© Stack Overflow or respective owner

Related posts about java

Related posts about api