通过串行监视器和Java同时读取Arduino

时间:2012-08-14 15:36:35

标签: java serial-port port arduino serial-communication

我在java中编写了一个代码来与我的Arduino板进行通信。它运作良好。我也可以使用串行监视器与Arduino板进行通信。

但是当我尝试打开串口监视器时,当java程序正在运行时(监听连接到该板的端口, PORT 32 ),它无法说,

Serial port 'COM 32' already in use. Try quitting any programs that may be using it.

这是完整的信息(仅为了完整性)

Binary sketch size: 3,994 bytes (of a 258,048 byte maximum)
processing.app.SerialException: Serial port 'COM32' already in use. Try quiting any programs that may be using it.
    at processing.app.Serial.<init>(Serial.java:171)
    at processing.app.Serial.<init>(Serial.java:92)
    at processing.app.SerialMonitor.openSerialPort(SerialMonitor.java:207)
    at processing.app.Editor.handleSerial(Editor.java:2447)
    at processing.app.EditorToolbar.mousePressed(EditorToolbar.java:353)
    at java.awt.Component.processMouseEvent(Component.java:6260)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6028)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2475)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

是的,我知道,我的java程序正在使用该端口。但这是否意味着我不能同时使用这两个程序来访问PORT32?

希望有人能告诉我解决这个问题的方法。任何帮助是极大的赞赏。谢谢!

1 个答案:

答案 0 :(得分:1)

您的观察是正确的,串行端口一次只能由一个应用程序打开。有一些软件解决方案可用于拆分串口或监控它们,但我没有足够的经验来提供任何建议。