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
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
Comment