Skip to content

Commit

Permalink
Updated example code in SerialPort.isOpen()'s Javadoc to mention that…
Browse files Browse the repository at this point in the history
… there can be ONLY ONE DataListener
  • Loading branch information
jskubick committed Feb 22, 2024
1 parent 9be2e45 commit 987f58b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/fazecast/jSerialComm/SerialPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,16 @@ public final boolean closePort()
* // (atOverride annotations omitted to avoid confusing Javadoc generator, but necessary in actual use)
* public int getListeningEvents() {
* return SerialPort.LISTENING_EVENT_PORT_DISCONNECTED;
* // or, if you want to listen for multiple events (see warning below):
* // return SerialPort.LISTENING_EVENT_PORT_DISCONNECTED | SerialPort.LISTENING_EVENT_DATA_RECEIVED
* }
* public void serialEvent(SerialPortEvent serialPortEvent) {
* port.closePort();
* // or, if you're listening for two or more events:
* // if (serialPortEvent.getEventType() == SerialPort.LISTENING_EVENT_PORT_DISCONNECTED)
* // port.closePort();
* // else if (serialPortEvent.getEventType() == SerialPort.LISTENING_EVENT_DATA_RECEIVED)
* // ... you get the idea
* }
* });
* </pre>
Expand All @@ -682,6 +689,9 @@ public final boolean closePort()
* not work again until the SerialPort object's close() and open() methods have both been called to
* re-establish the connection.
*
* <p><b>WARNING!</b> There can be **only one** DataListener. To Listen for multiple SerialPortEvents,
* OR (|) them together in getListeningEvents(), and check to see which event fired in serialEvent().
*
* @return Whether the port is opened.
*/
public final boolean isOpen()
Expand Down

0 comments on commit 987f58b

Please sign in to comment.