wavecome短信猫开发

最近在做wavecome短信猫开发,参考的很多资料终于搞定了,拿出来分享一下:
1、32位系统下:
环境的配置:
1、把smslib-3.3.0.jar、comm.jar与log4j-1.2.11.jar,放入到工程的lib中;
2、把javax.comm.properties放到%JAVA_HOME%/jre/lib下;
3、把win32com.dll放到%JAVA_HOME%/jre/bin下;
4 把comm.jar放到%JAVA_HOME%/jre/ext下

读取短信的代码:

package examples.modem;

import java.util.ArrayList;
import java.util.List;
import org.smslib.ICallNotification;
import org.smslib.IInboundMessageNotification;
import org.smslib.InboundMessage;
import org.smslib.Library;
import org.smslib.Service;
import org.smslib.InboundMessage.MessageClasses;
import org.smslib.Message.MessageTypes;
import org.smslib.modem.SerialModemGateway;

public class ReadMessages
{
	Service srv;

	public void doIt() throws Exception
	{
		List<InboundMessage> msgList;
		// Create the notification callback method for Inbound & Status Report
		// messages.
		InboundNotification inboundNotification = new InboundNotification();
		// Create the notification callback method for inbound voice calls.
		CallNotification callNotification = new CallNotification();
		try
		{
			System.out.println("Example: Read messages from a serial gsm modem.");
			System.out.println(Library.getLibraryDescription());
			System.out.println("Version: " + Library.getLibraryVersion());
			// Create new Service object - the parent of all and the main interface
			// to you.
			this.srv = new Service();
			// Create the Gateway representing the serial GSM modem.
			SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 115200, "WAVECOM MODEM", "MULTIBAND  900E  1800");
			// Do we want the Gateway to be used for Inbound messages? If not,
			// SMSLib will never read messages from this Gateway.
			gateway.setInbound(true);
			// Do we want the Gateway to be used for Outbound messages? If not,
			// SMSLib will never send messages from this Gateway.
			gateway.setOutbound(true);
			gateway.setSimPin("0000");
			// Set up the notification methods.
			gateway.setInboundNotification(inboundNotification);
			gateway.setCallNotification(callNotification);
			// Add the Gateway to the Service object.
			this.srv.addGateway(gateway);
			// Similarly, you may define as many Gateway objects, representing
			// various GSM modems, add them in the Service object and control all of them.
			//
			// Start! (i.e. connect to all defined Gateways)
			this.srv.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() + "%");
			System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
			System.out.println();
			// Read Messages. The reading is done via the Service object and
			// affects all Gateway objects defined. This can also be more directed to a specific
			// Gateway - look the JavaDocs for information on the Service method calls.
			msgList = new ArrayList<InboundMessage>();
			this.srv.readMessages(msgList, MessageClasses.ALL);
			for (InboundMessage msg : msgList)
				System.out.println(msg);
			// Sleep now. Emulate real world situation and give a chance to the notifications
			// methods to be called in the event of message or voice call reception.
			System.out.println("Now Sleeping - Hit <enter> to terminate.");
			System.in.read();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			this.srv.stopService();
		}
	}

	public class InboundNotification implements IInboundMessageNotification
	{
		public void process(String gatewayId, MessageTypes msgType, InboundMessage msg)
		{
			if (msgType == MessageTypes.INBOUND) System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId);
			else if (msgType == MessageTypes.STATUSREPORT) System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gatewayId);
			System.out.println(msg);
			try
			{
				// Uncomment following line if you wish to delete the message upon arrival.
				// srv.deleteMessage(msg);
			}
			catch (Exception e)
			{
				System.out.println("Oops!!! Something gone bad...");
				e.printStackTrace();
			}
		}
	}

	public class CallNotification implements ICallNotification
	{
		public void process(String gatewayId, String callerId)
		{
			System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
		}
	}

	public static void main(String args[])
	{
		ReadMessages app = new ReadMessages();
		try
		{
			app.doIt();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}

其中这里的配置要看具体的串口号:
SerialModemGateway gateway = new SerialModemGateway(“modem.com4”, “COM4”, 115200, “WAVECOM MODEM”, “MULTIBAND 900E 1800”);

windows下可以直接在“设备管理器”中查看:
在这里插入图片描述
2、64位系统下
按照以上开发32位系统下是没什么问题了,但是到64位系统下就不支持:win32com.dll

这时需要替换为RxTx
windows和串口通讯还需要依赖操作系统的功能,所以 RxTx还需要将rxtxParallel.dll和rxtxSerial.dll放到jdk目录中,官方的安装说明非常详细了。
rxtxSerial.dll —> <JAVA_HOME>\jre\bin
rxtxParallel.dll —> <JAVA_HOME>\jre\bin
RXTXcomm.jar只要放到classpath下就行,不用非得放到jre\lib\ext下面

这时工程需要的包为:
RXTXcomm.jar
log4j-1.2.11.jar
smslib-3.3.0.jar
commons-lang3-3.1.jar

参考文章:https://blog.csdn.net/xuepiaohan2006/article/details/38172495

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值