需要帮助我不知道,当我断开连接时如何让串行调制解调器重新连接,这是我连接到串行调制解调器的代码:
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);
}
}
我断开调制解调器的代码:
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);
}
如果我调用方法 connectToPort() 连接运行正常,然后我调用断开连接并且运行正常,但是当我尝试重新连接并再次调用 connectToPort() 时,我收到此错误:
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)
请帮忙.,.我该怎么办??