Why the COMS4 status is free when my phone modem is using it..
Below is the sample codes I am using
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SMS {
public static void main(String[] args) {
Enumeration lists=CommPortI dentifier.getPo rtIdentifiers() ;
System.out.prin tln(CommPortIde ntifier.PORT_SE RIAL);
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.isCurrentl yOwned());
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(Exceptio n e){
System.err.prin tln(e.getMessag e());
}
}
else{
System.out.prin tln("Name is parallel portzzzz "+cn.getName()+ " Owned status "+cn.isCurrentl yOwned()+cn.get PortType()+" ");
}
}
}
}
My output ::
1
true
Name is serail portzzzz COM1 Owned status true
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail portzzzz COM2 Owned status true
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
Any1 can sort this out for me
Below is the sample codes I am using
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SMS {
public static void main(String[] args) {
Enumeration lists=CommPortI dentifier.getPo rtIdentifiers() ;
System.out.prin tln(CommPortIde ntifier.PORT_SE RIAL);
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.isCurrentl yOwned());
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(Exceptio n e){
System.err.prin tln(e.getMessag e());
}
}
else{
System.out.prin tln("Name is parallel portzzzz "+cn.getName()+ " Owned status "+cn.isCurrentl yOwned()+cn.get PortType()+" ");
}
}
}
}
My output ::
1
true
Name is serail portzzzz COM1 Owned status true
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail portzzzz COM2 Owned status true
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
Any1 can sort this out for me