- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Jamod 1.2 在 Android 设备和 PLC 之间建立 Modbus TCP 连接。一切都很好,直到我被要求迁移到 Modbus RTU(通过 USB 连接)。 Jamod 有与 Modbus RTU 一起工作的类,但我遇到了一个特定的问题。要建立 Modbus RTU 连接,必须执行以下简单操作:
SerialParameters params = new SerialParameters();
params.setPortName(portname);
...
SerialConnection connection = new SerialConnection(params);
connection.open();
但是由于以下障碍,连接没有打开:
public class SerialConnection implements SerialPortEventListener {
...
public void open() throws Exception {
try {
this.m_PortIdentifier = CommPortIdentifier.getPortIdentifier(this.m_Parameters.getPortName());
} catch (NoSuchPortException var2) {
if(Modbus.debug) {
System.out.println(var2.getMessage());
}
throw new Exception(var2.getMessage());
}
...
}
...
}
这里的库尝试使用静态方法 CommPortIdentifier.getPortIdentifier(String portname) 获取 CommPortIdentifier 的实例。更深入:
public class CommPortIdentifier {
public static CommPortIdentifier getPortIdentifier(String var0) throws NoSuchPortException {
SecurityManager var1 = System.getSecurityManager();
if(var1 != null) {
var1.checkDelete(propfilename);
}
...
}
...
}
这就是罪恶的根源 - System.getSecurityManager()。它在 Android 中总是返回 null。 official doc
最后,问题:有没有办法在 Android 上生成 CommPortIdentifier?或者可能有人能想到另一种解决问题的方法?
P.S. 我想避免用其他东西替换 Jamod 或编写我自己的 Modbus RTU 包装器,因为很多代码都依赖于库。除非别无选择。
最佳答案
最终为 Android 编写了我自己的 Modbus RTU 包装器。它的基本实现可以在这里找到:https://github.com/dh-28/ModbusRtuConnect
关于java - 在 Android 上获取 CommPortIdentifier 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43975287/
我有一些可以在 Windows 7 中运行的代码,但是当我在 Windows 10 计算机上尝试相同的代码时,程序会关闭。代码如下: try { CommPortIdentifier port
我正在构建一个简单的应用程序,它使用 Java 通信 API javax.comm 通过串行端口进行通信。 这是我在 java main 方法中编写的一些代码: CommPortIdentifier
我试图首先列出 Ubuntu 14.04 LTS 上的所有端口,但并未检测到所有端口,它只显示 tty。我想访问 hidraw 一个,见下文。 我对每个人的锁文件都有读/写权限。 文件 RXTXcom
我正在尝试连接 ubuntu 上的串口。但是,它对我不起作用。我使用不同的驱动程序在 Windows 上成功运行了同一个项目。问题是我在使用它时无法加载任何端口: CommPortIdentifier
我是整个 modbus 和串行通信概念的新手,所以即使这是一个非常菜鸟的问题,也请耐心等待! 好的,所以我正在尝试使用 modbus 协议(protocol)和 RS 232 端口读取存储在寄存器中的
我正在使用 Jamod 1.2 在 Android 设备和 PLC 之间建立 Modbus TCP 连接。一切都很好,直到我被要求迁移到 Modbus RTU(通过 USB 连接)。 Jamod 有与
我试图从我的电脑串行端口读取数据,但我不断收到一组空端口。我在 stackoverflow、coderanch 和 oracle 论坛上查找了许多其他问题,所有这些问题都提到需要将 win32com.
我在 Raspberry PI 上安装了 Oracle 的 Java JDK 8 和 Tomcat 8。 我有一个独立应用程序和一个网络应用程序,它们都具有相同的功能(开放式串行通信)。两者都在我的
恐怕这可能不是严格意义上的编程问题,而是我需要解决更多问题才能继续我的编程。 我只是想编写一个程序来进行串行通信,特别是使用 javax.comm API,并且我在 Win7 上成功了,但是当我在我的
我是一名优秀的程序员,十分优秀!