java and AT commands
hi all,i need some help in this code......
import java.io.*;
import java.util.*;
import javax.comm.*;
public class writeto {
static Enumeration portlist;
static CommPortIdentifier portid;
static String send1="AT\r\n";
//static String send2="\r\n";
static SerialPort serialport;
static OutputStream os;
static InputStream is;
public static void main(String args[])
{
boolean portfound=false;
String defport="COM3";
portlist=CommPortIdentifier.getPortIdentifiers();
while(portlist.hasMoreElements())
{
portid=(CommPortIdentifier)portlist.nextElement();
if(portid.getPortType()==CommPortIdentifier.PORT_SERIAL)
{
if(portid.getName().equals(defport))
{
System.out.println("port found at "+defport);
portfound=true;
try{
serialport=(SerialPort)portid.open("writeto",1000);
}catch(PortInUseException e){continue;}
try{
os=serialport.getOutputStream();
System.out.println("get output stream");
}catch(IOException e){}
try{
serialport.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
}catch(UnsupportedCommOperationException e){}
try{
os.write(send1.getBytes());
System.out.println("Send data");
}catch(IOException e){}
try{
System.out.println("wait for transfer");
Thread.sleep(4000);
}catch(InterruptedException e){}
try{
is=serialport.getInputStream();
}catch(IOException e){}
try
{
Thread.sleep(4000);
}catch(InterruptedException e){}
byte[] readbyte= new byte[20];
try{
while(is.available()>0)
{
int ch=is.read(readbyte);
}
System.out.println(new String(readbyte));
}catch(IOException e){}
}
}
}
}
}

