Need help i have no idea, how to make serial modem reconnected again when i am disconnect, this is my code connecting to serial modem :
public void connectToPort() throws GatewayException, IOException, TimeoutException, InterruptedException, SMSLibException{
try {
String port=portList.getSelectedItem().toString();
gateway = new SerialModemGateway("Modem "+port, port, 115200, "Wavecom", "M1206B");
Service.getInstance().addGateway(gateway);
gateway.setProtocol(AGateway.Protocols.PDU);
gateway.setInbound(true);
gateway.setOutbound(true);
USSDNotification ussdNotification = new USSDNotification();
Service.getInstance().setUSSDNotification(ussdNotification);
Service.getInstance().startService();
Service.getInstance().S.SERIAL_TIMEOUT=6000;
Service.getInstance().S.MASK_IMSI=false;
btnStart.setEnabled(true);
txtOutput.append("Modem status : "+gateway.getStatus().toString());
this.repaint();
this.revalidate();
// Service.getInstance().S.AT_WAIT_AFTER_RESET=2000;
// System.out.println("IMSI Smslib"+gateway.sendCustomATCommand("AT+CIMI"));
} catch (SMSLibException ex) {
Logger.getLogger(FormDMT.class.getName()).log(Level.SEVERE, null, ex);
}
}
my code to disconnect modem :
try {
Service.getInstance().stopService();
Service.getInstance().removeGateway(gateway);
txtOutput.append("Modem status : "+gateway.getStatus().toString());
this.repaint();
this.revalidate();
} catch (GatewayException ex) {
Logger.getLogger(FormDMT.class.getName()).log(Level.SEVERE, null, ex);
} catch (SMSLibException ex) {
Logger.getLogger(FormDMT.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(FormDMT.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(FormDMT.class.getName()).log(Level.SEVERE, null, ex);
}
if i calling method connectToPort() the connection is running fine, and then i call disconect and runing fine too, but when i try to reconnect and call connectToPort() again i am getting this error :
java.io.IOException: write error
at com.sun.comm.Win32SerialPort.write(Win32SerialPort.java:677)
at com.sun.comm.Win32SerialOutputStream.write(Win32SerialOutputStream.java:38)
at org.smslib.modem.SerialModemDriver.write(SerialModemDriver.java:166)
at org.smslib.modem.AModemDriver.write(AModemDriver.java:302)
at org.smslib.modem.athandler.ATHandler_Wavecom.done(ATHandler_Wavecom.java:52)
at org.smslib.modem.ModemGateway.stopGateway(ModemGateway.java:201)
at org.smslib.Service.stopService(Service.java:355)
please help.,.what should i do??