java から wavecom のような GSM モデムにメッセージを送信しようとしていますが、次の投稿を見つけました: Swing (netbeans) を使用して SMSlib sendmessage に進行状況バーを追加する
クラスを実行するとsendMessage
、次の例外が発生します。
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)
at org.smslib.Service.startService(Service.java:234)
at org.smslib.Service.startService(Service.java:196)
at consoledmt.SendMessage.sendMessage(SendMessage.java:42)
at consoledmt.SendMessage.main(SendMessage.java:86)
コードは次のとおりです。
import java.net.URL;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.OutboundWapSIMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
public class SendMessage {
public void sendMessage() throws Exception {
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Sample of Send message from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
SerialModemGateway gateway = new SerialModemGateway("modem.com16", "COM16", 115200, "Wavecom", "M1206B");
gateway.setInbound(false);
gateway.setOutbound(true);
// gateway.setSimPin("");
Service.getInstance().setOutboundMessageNotification(
outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
System.out.println();
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel()+ " dBm");
System.out.println(" Battery Level: " + gateway.getBatteryLevel()+ "%");
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("+6283806120618",
"SMS test: sample message from StackOverflow");
Service srvice = Service.getInstance();
// Service.getInstance().sendMessage(msg);
System.out.println(msg);
// Or, send out a WAP SI message.
OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("+6283806120618",
new URL("https://stackoverflow.com/"),
"WAP test: sample message from StackOverflow!");
// gateway.setFrom("chandpriyankara");
// wapMsg.setFrom("chandpriyankara");
srvice.queueMessage(wapMsg);
Service.getInstance().stopService();
}
/**
* Outbound Message informations handler
*
* @author chandpriyankara
*
*/
public class OutboundNotification implements IOutboundMessageNotification {
public void process(AGateway gateway, OutboundMessage msg) {
System.out.println("Outbound handler called from Gateway: "+ gateway.getGatewayId());
System.out.println(msg);
}
}
public static void main(String args[]) {
SendMessage app = new SendMessage();
try {
app.sendMessage();
} catch (Exception e) {
e.printStackTrace();
}
}
}