Windows 中的 RXTX 困难
早上好,
我有一个 Java 程序 orderPrinter,它通过 USB 转串口通信与 POS 打印机进行通信。我按照说明安装了 RXTX 和 javax.comm 库,经过一番摆弄文件位置后,成功地让程序在我的计算机(Windows 7)上运行。
然而,我在让它在 Windows XP 中运行时遇到了困难(发行后,Windows XP 将成为主要平台,我认为其次是 Linux)。将 64 位 JAR 和 DLL 文件替换为各自的 32 位替代文件后(如 RXTX wiki),我遇到了几个问题:
1)RXTX 似乎无法找到正确的 COM 端口。通过 echo 测试[乱码]>> COMx 生成响应,因此我知道打印机位于 COM5。以下代码:
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
System.out.println("Port: "+((CommPortIdentifier)(portList.nextElement())).getName());
}
CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier(settings.port);
打印出“Port://./COM5”作为32位计算机上的唯一端口,而在Windows 7中我得到“Port:COM5”。我遇到的第一个问题是XP中调用CommPortIdentifier.getPortIdentifier(port)失败;我只能想象这是因为 CommPortIdentifier 与端口名称完全匹配。有没有办法修改 JAR 以允许更宽松的端口匹配?
2) 假设现在,作为临时修复,我硬编码了 Windows XP 的确切预期字符串。紧接着,当我调用 portID.open([正确的参数) 时,程序崩溃并出现以下错误:
Exception in thread "main" java.lang.VerifyError: (class: gnu/io/RXTXPort$SerialOutputStream, methd: flush signature: ()V) Illegal use of nonvirtual function call
我找到的每个解决方案都归结为使用旧版本的 RXTX;然而,如上所述,我使用的是 2.1-7r2,据我所知,这是最新的稳定版本。我对这个错误以及如何修复它完全感到困惑。有什么想法吗?
请记住,虽然我熟悉 Java 编程,但我对构建相关错误的理解却非常有限,情况似乎就是如此;我也希望能够解释一下这个问题,以便以后更容易解决这个问题。
感谢您抽出时间。
编辑:我相信我有解决问题1的方法;修改源码然后重新编译。不过,我确实没有时间调试为什么 javac 在提示符中不是有效命令,也没有找到可靠的方法在 Eclipse 中执行此操作。再说一次,这是我第一次做除了导入 JAR 之外的任何事情,所以至少可以说这是一次学习经历。或者此时进行火的审判。
Good morning,
I have a Java program, orderPrinter, that communicates to POS printer via USB-to-serial communication. I installed the RXTX and javax.comm libraries as per the instructions, and after some fiddling with file locations succeeded in getting the program running on my machine (Windows 7).
However, I'm running into difficulties getting it to work in Windows XP (which, after distribution, will be the primary platform, with secondary being Linux I presume). After substituting the 64-bit JAR and DLL files with their respective 32-bit substitutes (as found on the RXTX wiki), I've run into several issues:
1) RXTX seems to have trouble with locating the correct COM port. Testing via echo [gibberish] >> COMx generates a response, so I know that the printer is at COM5. The following code:
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
System.out.println("Port: "+((CommPortIdentifier)(portList.nextElement())).getName());
}
CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier(settings.port);
prints out "Port: //./COM5" as the only port on the 32-bit machine, whereas in Windows 7 I get back "Port: COM5". The first problem I encounter is that the call to CommPortIdentifier.getPortIdentifier(port) fails in XP; I can only imagine this is due to the CommPortIdentifier matching the port name exactly. Is there a way to modify the JAR to allow for more lenient port matching?
2) Assuming for now, as a temporary fix, I hard-code the exact expected string for Windows XP. Immediately afterwards, when I call portID.open([correct parameters), the program crashes with the following error:
Exception in thread "main" java.lang.VerifyError: (class: gnu/io/RXTXPort$SerialOutputStream, methd: flush signature: ()V) Illegal use of nonvirtual function call
Every solution I've found has boiled down to using an older version of RXTX; however, as stated, I'm using 2.1-7r2, which is to my knowledge the most recent stable release. I am completely baffled by this error and how to fix it. Any ideas?
Bear in mind, while I'm familiar with java programming, I'm much more limited in my understanding of build-related errors, which this seems to be the case; I would also like to be able to explain the issue so as to resolve this problem more easily in the future.
Thank you for your time.
EDIT: I believe I have a solution to problem 1; modifying the source and then recompiling. I don't really have time to debug why javac is not a valid command in the prompt, though, nor have I found a reliable way to do this in Eclipse. Again, this is my first time doing anything beyond importing a JAR, so it's a learning experience to say the least. Or a trial by fire at this point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论