arduino java 串行通信不工作

arduino java serial communication not working

我正在尝试使用 eclipse 从我的 arduino 与 java 进行通信。我正在使用本教程 arduino -> java,唯一的问题是我收到一条消息 "could not find com port",但我不知道如何解决这个问题。我想这和我在代码中没有选择正确的端口有关。

Sceenshot

在这里你可以看到我从 eclipse 得到的消息,arduino 正在使用 com 3 并且串行通信正在工作。

我可能错了,但 java 代码应该获取字符串 "Hello world" 并将其显示在控制台中,对吧?

在此先感谢您的帮助。

使用以下 arduino 示例,很容易在您的控制台中获取 hello world 消息。您只需要正确设置串行端口并在您的 java 项目中包含 rxtx 库.

如果您不知道您的 arduino 使用的 com 端口,请转到您的 arduino 编辑器并转到工具->端口并为其设置一个 com 端口。并在您的 java 代码

中添加相同的端口

如果您在 windows 中,那么您的 PORT_NAMES[] 数组应该如下所示。 private static final String PORT_NAMES[] = { "COM3"};

对于您的情况,它可能是 COM3COM4COM6 或任何其他端口,只需设置正确的端口即可。

当然要先连接你的arduino。