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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpuser123
    New Member
    • Dec 2009
    • 108

    #1

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

    When I am running the following code 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 it in NetBeans, it does not seem to find any ports ..

    public static void test(){
    Enumeration lists=CommPortI dentifier.getPo rtIdentifiers() ;

    System.out.prin tln(lists.hasMo reElements());
    while (lists.hasMoreE lements()) {
    CommPortIdentif ier cn=(CommPortIde ntifier)lists.n extElement();

    if ((CommPortIdent ifier.PORT_SERI AL==cn.getPortT ype())) {
    System.out.prin tln(
    "Name is serail portzzzz " +
    cn.getName() +
    " Owned status " +
    cn.isCurrentlyO wned());

    try{
    SerialPort port1=(SerialPo rt)cn.open("Com Control",800000 );
    port1.setSerial PortParams(
    9600,
    SerialPort.DATA BITS_8,
    SerialPort.STOP BITS_1,
    SerialPort.PARI TY_NONE);
    System.out.prin tln("Before get stream");
    OutputStream out=port1.getOu tputStream();
    InputStream input=port1.get InputStream();
    System.out.prin tln("Before write");
    out.write("AT". getBytes());
    System.out.prin tln("After write");
    int sample=0;
    //while((( sample=input.re ad())!=-1)){
    System.out.prin tln("Before read");
    //System.out.prin tln(input.read( ) + "TEsting ");
    //}
    System.out.prin tln("After read");
    System.out.prin tln("Receive timeout is "+port1.getRece iveTimeout());
    }
    catch(Exception e) {
    System.err.prin tln(e.getMessag e());
    }
    }
    else {
    System.out.prin tln(
    "Name is parallel portzzzz " +
    cn.getName() +
    " Owned status " +
    cn.isCurrentlyO wned() +
    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
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Please do not double post the question.

    Are you using external Java or the Java bundled with the IDE's?

    Regards
    Dheeraj Joshi

    Comment

    • phpuser123
      New Member
      • Dec 2009
      • 108

      #3
      I am using an external java bundle..
      Do you think that's what making the problem?
      I tried finding the java bundle in the IDE but could n't find it.

      Comment

      • phpuser123
        New Member
        • Dec 2009
        • 108

        #4
        I am using an external java bundle..
        Do you think that's what making the problem?
        I tried finding the java bundle in the IDE but could n't find it.

        Comment

        • Dheeraj Joshi
          Recognized Expert Top Contributor
          • Jul 2009
          • 1129

          #5
          Not sure what may be the issue. If you post the whole code we can try to execute it and figure out the problem.

          Regards
          Dheeraj Joshi
          Last edited by Dheeraj Joshi; Dec 30 '10, 07:41 AM. Reason: Sentence modified

          Comment

          • phpuser123
            New Member
            • Dec 2009
            • 108

            #6
            Code:
            import java.io.*;
            import java.util.*;
            import javax.comm.*;
            
            public class SMS {
            
            	
            	public static void main(String[] args) {
            		Enumeration lists=CommPortIdentifier.getPortIdentifiers();
            		System.out.println(CommPortIdentifier.PORT_SERIAL);
            		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(input.available());
            					
            					//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()+"    ");
            			}
            		}
            	}
            
            }
            Here is the whole code..

            Comment

            Working...