given as follows:
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: 92)
at org.smslib.modem.AModemDriver.connect (AModemDriver.java: 110)
at org.smslib.modem.ModemGateway.startGateway (ModemGateway.java: 126)
at org.smslib.Service $ 1Starter.run (Service.java: 222)
can only send one , send ah can not repeat , repeat , they reported sending port is occupied.
package com.huanrong.util;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;
import org.apache.log4j.Logger;
import org.smslib.AGateway;
import org.smslib.AGateway.Protocols;
import org.smslib.GatewayException;
import org.smslib.InboundMessage;
import org.smslib.Message.MessageEncodings;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
/ **
*
* @ ClassName: SendMsg
* @ Description: send SMS messages cat method
* @ author jay
* @ date 05:46:04 2012-10-17 pm
*
* Usage:
* SendMsg.sendMsg (" phone number" , "Send Content" ) ;
*
* /
public class SendMsg {
private static final Logger logger = Logger.getLogger (SendMsg.class);
private Service smsService;
/ **
* Send SMS
* /
public SendMsg (String com) {
smsService = Service.getInstance ();
String portName = com ;/ / "/ dev/ttyUSB0" ;/ / COM24
SerialModemGateway gateway = new SerialModemGateway (
"modem." + portName, ; portName, 9600, "wavecom", "PL2303");
gateway.setInbound (true);
gateway.setOutbound (true);
gateway.setProtocol (Protocols.PDU);
gateway.setSimPin ("0000");
try {
smsService.addGateway (gateway);
} catch (GatewayException ex) {
logger.error (ex.getMessage ());
}
}
/ **
*
* /
public void start () throws Exception {
logger.info ("SMS service start .....");
smsService.startService ();
}
/ **
*
* /
public void destroy () throws Exception {
smsService.stopService ();
logger.info ("SMS service stop");
}
/ **
* send SMS
* @ param msg
* @ return Boolean
* /
public Boolean sendSMS (OutboundMessage msg) throws Exception {
msg.setEncoding (MessageEncodings.ENCUCS2);
return smsService.sendMessage (msg);
}
private boolean isStarted () {
if (smsService.getServiceStatus () == Service.ServiceStatus.STARTED) {
for (AGateway gateway: smsService.getGateways ()) { ;
if (gateway.getStatus () == AGateway.GatewayStatuses.STARTED) {
return true;
}
}
}
return false;
}
/ **
* read SMS
* read SMS
* @ return List
* /
public List
List
if (! isStarted ()) {
return msgList;
}
try {
this.smsService.readMessages (msgList,
InboundMessage.MessageClasses.ALL) ;
logger.info ("read SMS size:" + msgList . size ());
} catch (Exception e) {
logger.error ("read error:", e);
}
return msgList;
}
/ **
* @ param args
* /
public static void main (String [] args) throws Exception {
SendMsg smsHandler = new SendMsg (com.huanrong.crm.Constant.COMM1);
OutboundMessage outMsg = new OutboundMessage ("*******", " Information Test 1 " ;) ;
smsHandler.start ();
/ / send SMS
smsHandler.sendSMS (outMsg);
System.out.println (" successfully sent one ! " ) ;
smsHandler.destroy ();
System.out.println ("-----------");
}
}
how do ah, always been this way , the collapse of the matter, we help out .
------ Solution ------------------------------------ --------
destroy () , there is no release of the serial connection. You can try the following method
connection independent, as an attribute . Send pseudo-code :
if (! connected ()) {
connection.connect ();
}
sendmsg (msg);
------ Solution ------------------------------------ --------
is not run to close
------ Solution ----------------------- ---------------------
service is a service , the port is the port , the port can not be judged according to the state of the service status , and certainly not by the end of the service to shut down the port . ..
A service can have multiple ports , each port before and after the increase should be deleted judgment port status.
------ For reference only -------------------------------------- -
Meirenhuida ah, hastily , online, their top .
------ For reference only -------------------------------------- -
how to release the serial connection it
------ For reference only ------------------------ Editor's Note ---------------
do not know , can not find the close approach , and finally I was solved , start tomcat service when the service starts sending messages only can be started once, it is a single case , then you can send a stop when the service tomcat stop sending SMS services. This can now be sent.
------ For reference only -------------------------------------- -
SerialModemGateway is your serial connection , have you its close approach
------ For reference only -------------------- -------------------
[ hair Assad happen ] [ / Assad issued ]
------ For reference I have encountered only ---------------------------------------
not send duplicate situation !
------ For reference only -------------------------------------- -
how to release port
------ For reference only ------------------------------- --------
Service smsService is static, starting just once , after texting again , not in this start , sendMessage sent directly transferred on the line
------ For reference only ---------------------------------------
landlord , and why I am here tomcat startup when started the SMS service , but the call sendMsg when sending SMS status is STOPED it ?
which I always wondered , can you tell me how you do it?
------ For reference only ---------------------------------- -----
you great God, my program always reported
[main] WARN org.smslib - sendMessage (): Gateway modem.com3 does not respond, marking for restart.
how to solve it , Jiqiu !
------ For reference only -------------------------------------- . -
in smsService stopService (); underneath sentence smsService removeGateway (gateway); try
.
没有评论:
发表评论