java监听多个串口_smslib使用的问题,监听一个串口没问题,监听多个串口JVM就异常退出了...

win10 64位 jdk7 64位,集成测试监听一个串口没问题,可以收发短信,当监听多个的时候启动就报异常的,不解,请问有人遇到过吗?貌似是底层调用的rxtxSerial.dll出的问题。

看API监听多个很简单,add进去就可以了,不知道为何会出错

gateway.setInbound(true);//先循环new gateway然后add进去service.addGateway方法里面是一个list所以应该是支持多个的

gateway.setOutbound(true);

gateway.setProtocol(Protocols.PDU);

//加入到网关服务队列

service.setInboundMessageNotification(inboundNotification);

service.setCallNotification(callNotification);

service.setGatewayStatusNotification(statusNotification);

service.setOrphanedMessageNotification(orphanedMessageNotification);

service.addGateway(gateway);

然后service.startService();

[thread 16080 also had an error][thread 16080 also had an error]

#

# A fatal error has been detected by the Java Runtime Environment:

#

#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000180008790, pid=5272, tid=14664

#

# JRE version: Java(TM) SE Runtime Environment (7.0_80-b15) (build 1.7.0_80-b15)

# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.80-b11 mixed mode windows-amd64 compressed oops)

# Problematic frame:

# C  [rxtxSerial.dll+0x8790]

#

# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

#

# An error report file with more information is saved as:

# G:\Soft\mytest\smslibProject\hs_err_pid5272.log

#

# If you would like to submit a bug report, please visit:

#   http://bugreport.java.com/bugreport/crash.jsp

# The crash happened outside the Java Virtual Machine in native code.

# See problematic frame for where to report the bug.

#

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用JavaSMSLib库来读取短信内容并实现API接口。 以下是一个简单的示例代码: ```java import org.smslib.*; import org.smslib.modem.SerialModemGateway; public class SMSReader { public static void main(String[] args) { try { // 初始化SMSLibService service = Service.getInstance(); // 创建串口短信猫网关 SerialModemGateway gateway = new SerialModemGateway("modem", "COM3", 9600, "", ""); // 设置短信猫网关属性 gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin("<PIN>"); // 添加短信猫网关到库中 service.addGateway(gateway); // 启动库 service.startService(); // 等待短信 while (true) { // 获取收到的短信 if (service.getUnreadMessages().size() > 0) { // 获取最新的一条短信 InboundMessage msg = service.getUnreadMessages().get(0); // 打印短信内容 System.out.println(msg.getText()); // 设置短信为已读 msg.setRead(true); // 更新短信状态 service.updateMessage(msg); } // 暂停1秒钟 Thread.sleep(1000); } } catch (Exception e) { e.printStackTrace(); } } } ``` 在上面的代码中,我们使用SMSLib库来读取短信内容。我们先初始化SMSLib库,然后创建一个串口短信猫网关,并将其添加到库中。然后,我们使用一个死循环来等待收到短信。如果收到了短信,我们就打印出短信内容,并将其设置为已读。 您可以将上面的代码封装成API接口并在应用程序中使用。请注意,您需要替换COM3为您的串口号,并将<PIN>替换为您的短信猫的PIN码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值