1
votes

I've written a code in java to communicate with my Arduino board. It works well. Also I can use the serial monitor to communicate with the Arduino board.

But when I try to open serial monitor, while the java program is running (listening on the port which is connected to thee board, PORT 32), it fails saying,

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

This is the complete message (just for the sake of completeness)

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)

Yeah I know, its my java program which is using the port. But does that mean that I can't use both programs at the same time to access PORT32?

Hope someone will show me a way around this. Any help is greatly appreciated. Thanks!

1

1 Answers

1
votes

Your observation is correct, serial ports can only be opened by one application at a time. There are software solutions available to split serial ports, or monitor them, but I am not experienced enough with those to give any recommendations.