图中指令说明如下:at+csq是测试信号的。AT&F,是将MODEM恢复到出厂默认状态;AT+CMGF=1,是将MODEM设置为TEXT格式,即发送英文格式。AT+CMGS=13713582925回车,设置接收号码(输入号码回车后自动换行后产生“>”,“>”的后面可以输入短信内容),how are you,为发送短信的内容。注意:输入内容后按Ctrl+z,确认发送,其中不含“+”号。返回OK,发送成功。
然后记住一定要断开超级终端的连接,不然然后用程序测会出现端口占用的问题。
org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)
at org.smslib.Service$1Starter.run(Service.java:227)
复制代码
再次用上述程序测试就不会出现问题.可以正常发送短信。
但是我们是需要连续发送短信的,结果出现了发送成功了一条,但发第二条就报错,出现了如下异常
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.PortInUseException: Port currently owned by org.smslib
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:276)
<p>org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException</p><p> at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)</p><p> at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)</p><p> at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)</p><p></p><p> at org.smslib.Service$1Starter.run(Service.java:227)</p>