You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Only one listener can be registered at a time; however, that listener can be used to detect multiple types of serial port events.
1155
1158
* Refer to {@link SerialPortDataListener}, {@link SerialPortDataListenerWithExceptions}, {@link SerialPortPacketListener}, {@link SerialPortMessageListener}, and {@link SerialPortMessageListenerWithExceptions} for more information.
1159
+
* <p>
1160
+
* Note that if you register to listen for {@link SerialPort#LISTENING_EVENT_PORT_DISCONNECTED} events, you <b>CANNOT</b> call <code>openPort()</code> to re-open a disconnected port from within the <code>serialEvent()</code>
1161
+
* handler. Port re-opening <b>must</b> be done within your own application context.
1156
1162
*
1157
1163
* @param listener A {@link SerialPortDataListener}, {@link SerialPortDataListenerWithExceptions}, {@link SerialPortPacketListener}, {@link SerialPortMessageListener}, or {@link SerialPortMessageListenerWithExceptions} implementation to be used for event-based serial port communications.
1158
1164
* @return Whether the listener was successfully registered with the serial port.
@@ -2207,9 +2213,17 @@ else if (dataPacket.length == 0)
2207
2213
}
2208
2214
if (eventListenerRunning && !isShuttingDown && (event != SerialPort.LISTENING_EVENT_TIMED_OUT))
* Two or more events may be OR'd together to listen for multiple events; however, if {@link SerialPort#LISTENING_EVENT_DATA_AVAILABLE} is OR'd with {@link SerialPort#LISTENING_EVENT_DATA_RECEIVED}, the {@link SerialPort#LISTENING_EVENT_DATA_RECEIVED} flag will take precedence.
56
+
* Two or more events may be OR'd together to listen for multiple events; however, if {@link SerialPort#LISTENING_EVENT_DATA_AVAILABLE} is OR'd with
57
+
* {@link SerialPort#LISTENING_EVENT_DATA_RECEIVED}, the {@link SerialPort#LISTENING_EVENT_DATA_RECEIVED} flag will take precedence.
57
58
* <p>
58
59
* Note that event-based <i>write</i> callbacks are only supported on Windows operating systems. As such, the {@link SerialPort#LISTENING_EVENT_DATA_WRITTEN}
59
60
* event will never be called on a non-Windows system.
@@ -83,7 +84,23 @@ public interface SerialPortDataListener extends EventListener
83
84
/**
84
85
* Called whenever one or more of the serial port events specified by the {@link #getListeningEvents()} method occurs.
85
86
* <p>
86
-
* Note that your implementation of this function should always perform as little data processing as possible, as the speed at which this callback will fire is at the mercy of the underlying operating system. If you need to collect a large amount of data, application-level buffering should be implemented and data processing should occur on a separate thread.
87
+
* Note that your implementation of this function should always perform as little data processing as possible,
88
+
* as the speed at which this callback will fire is at the mercy of the underlying operating system. If you need to collect a large amount of data,
89
+
* application-level buffering should be implemented and data processing should occur on a separate thread.
90
+
* <p>
91
+
* Also note that if you are listening for multiple types of events (for instance, {@link SerialPort#LISTENING_EVENT_DATA_AVAILABLE} and
92
+
* {@link SerialPort#LISTENING_EVENT_PORT_DISCONNECTED}) at the same time, this callback <i>may<i> be invoked only once for multiple event
93
+
* types. As such, you should test for your event of interest by bit-masking and not by testing for equivalence. The following code shows
94
+
* the correct way to do this:
95
+
* <pre>
96
+
* {@literal @}Override
97
+
* public void serialEvent(SerialPortEvent serialPortEvent) {
98
+
* if ((serialPortEvent.getEventType() & SerialPort.LISTENING_EVENT_PORT_DISCONNECTED) > 0)
99
+
* port.closePort();
100
+
* else if ((serialPortEvent.getEventType() & SerialPort.LISTENING_EVENT_DATA_AVAILABLE) > 0)
101
+
* // ... you get the idea
102
+
* }
103
+
* </pre>
87
104
*
88
105
* @param event A {@link SerialPortEvent} object containing information and/or data about the serial events that occurred.
0 commit comments