使用 Rxtx 库向 USB 连接的手机发送消息会导致计算机锁定/崩溃 ߞ为什么?

发布于 2024-10-29 08:52:02 字数 502 浏览 0 评论 0原文

最终,我想使用 Java 程序从通过 USB 插入的手机发送和接收消息。我可以使用 C# 程序来完成此操作,但是我想要发送和接收消息的程序是用 Java 编写的。为此,我使用 Rxtx 库(但使用 Cloudhopper 的 Windows x64 编译版本) 。但每当我尝试通过 USB 向手机发送任何命令时,我的计算机就会完全锁定,我必须硬重启它。

我正在运行的代码在这里:与串行端口的双向通信。我认为它成功建立了一个链接,因为它到达了从控制台接受输入的阶段,尽管当我按 Enter 键并发送输入时,计算机会锁定。

我正在运行 Windows 7 x64,使用 Eclipse。感谢您的帮助。

Ultimately I would like to use a Java program to send and receive messages from a phone that I have plugged in via USB. I can do this using a C# program, however the program I want to send and receive messages is written in Java. To do this I am using the Rxtx library (but using the Windows x64 compiled version from Cloudhopper). But whenever I try and send any commands to the phone via USB my computer completely locks up and I have to hard-restart it.

The code I am running is here: Two way communication with the serial port. I think that it successfully establishes a link since it gets to the stage where it accepts input from the console, though when I press enter, and the input is sent, the computer locks up.

I am running Windows 7 x64, using Eclipse. Thank you for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-11-05 08:52:02

从代码中很难看出,但这里有一些调试技巧:

  • 尝试使用调试器逐行单步调试代码,并单步进入库本身,看看是否可以找到问题。
  • 不要从控制台读取/写入,而是尝试以编程方式发送字符代码。控制台的操作与直接访问有很大不同。即代替 System.in.read()) 只需尝试传入已知的良好字符串。
  • 请记住,Java 在内部使用 UCS-16,但控制台通常使用不同的字符编码(例如 Windows 的 cp1252)。因此,您的“输入”可能是与系统期望的完全不同的字符。如果您的设备需要 ASCII 13,而您的键盘正在生成 ASCII 12,这可能足以造成混乱。
  • 这次崩溃使得本机库很可能出现问题。如果您发现 Java 调试不断陷入 JNI 边界,您可能需要使用 C/C++ 工具集进行调试。

祝你好运!

A little hard to tell from the code, but here are some debugging tips:

  • Try stepping through the code with the debugger line by line, and step in to the library itself to see if you can find the problem.
  • Instead of reading/writing from the console, try sending character codes programmatically. The console operates very differently from direct access. i.e. instead of System.in.read()) just try passing in a known good String.
  • Keep in mind that Java works with UCS-16 internally, but that consoles typically work with different character encodings (e.g. cp1252 for Windows). So, your "enter" may be a completely different character from what the system is expecting. If your device is expecting ASCII 13 and your keyboard is generating ASCII 12, that could be enough to confuse things.
  • The crash makes it seem very likely that there is something going on with the native library. If you find that the Java debugging keeps dropping you into the JNI boundary, you may need to debug with a C/C++ toolset.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文