有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java连接和断开SerialModemGateway SmsLib

需要帮助我不知道如何在断开连接时重新连接串行调制解调器,这是我连接串行调制解调器的代码:

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(),则连接运行正常,然后调用disconnect和running也正常,但当我尝试重新连接并再次调用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)

请帮忙。,。我该怎么办


共 (0) 个答案