Interface SerialPortDataListener
-
- All Superinterfaces:
EventListener
- All Known Subinterfaces:
SerialPortDataListenerWithExceptions
,SerialPortMessageListener
,SerialPortMessageListenerWithExceptions
,SerialPortPacketListener
public interface SerialPortDataListener extends EventListener
This interface must be implemented to enable simple event-based serial port I/O.- See Also:
EventListener
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
getListeningEvents()
Must be overridden to return one or more desired event constants for which theserialEvent(SerialPortEvent)
callback should be triggered.void
serialEvent(SerialPortEvent event)
Called whenever one or more of the serial port events specified by thegetListeningEvents()
method occurs.
-
-
-
Method Detail
-
getListeningEvents
int getListeningEvents()
Must be overridden to return one or more desired event constants for which theserialEvent(SerialPortEvent)
callback should be triggered.Valid event constants are:
SerialPort.LISTENING_EVENT_DATA_AVAILABLE
SerialPort.LISTENING_EVENT_DATA_RECEIVED
SerialPort.LISTENING_EVENT_DATA_WRITTEN
SerialPort.LISTENING_EVENT_PORT_DISCONNECTED
SerialPort.LISTENING_EVENT_BREAK_INTERRUPT
SerialPort.LISTENING_EVENT_CARRIER_DETECT
SerialPort.LISTENING_EVENT_CTS
SerialPort.LISTENING_EVENT_DSR
SerialPort.LISTENING_EVENT_RING_INDICATOR
SerialPort.LISTENING_EVENT_FRAMING_ERROR
SerialPort.LISTENING_EVENT_FIRMWARE_OVERRUN_ERROR
SerialPort.LISTENING_EVENT_SOFTWARE_OVERRUN_ERROR
SerialPort.LISTENING_EVENT_PARITY_ERROR
Two or more events may be OR'd together to listen for multiple events; however, if
SerialPort.LISTENING_EVENT_DATA_AVAILABLE
is OR'd withSerialPort.LISTENING_EVENT_DATA_RECEIVED
, theSerialPort.LISTENING_EVENT_DATA_RECEIVED
flag will take precedence.Note that event-based write callbacks are only supported on Windows operating systems. As such, the
SerialPort.LISTENING_EVENT_DATA_WRITTEN
event will never be called on a non-Windows system.It is recommended to only use the
SerialPort.LISTENING_EVENT_DATA_AVAILABLE
,SerialPort.LISTENING_EVENT_DATA_RECEIVED
,SerialPort.LISTENING_EVENT_DATA_WRITTEN
, and/orSerialPort.LISTENING_EVENT_PORT_DISCONNECTED
listening events in production or cross-platform code since underlying differences and lack of support for the control line status and error events among the various operating systems and device drivers make it unlikely that code listening for these events will behave similarly across different serial devices or OS's, if it works at all.- Returns:
- The event constants that should trigger the
serialEvent(SerialPortEvent)
callback. - See Also:
SerialPort.LISTENING_EVENT_DATA_AVAILABLE
,SerialPort.LISTENING_EVENT_DATA_RECEIVED
,SerialPort.LISTENING_EVENT_DATA_WRITTEN
,SerialPort.LISTENING_EVENT_PORT_DISCONNECTED
,SerialPort.LISTENING_EVENT_BREAK_INTERRUPT
,SerialPort.LISTENING_EVENT_CARRIER_DETECT
,SerialPort.LISTENING_EVENT_CTS
,SerialPort.LISTENING_EVENT_DSR
,SerialPort.LISTENING_EVENT_RING_INDICATOR
,SerialPort.LISTENING_EVENT_FRAMING_ERROR
,SerialPort.LISTENING_EVENT_FIRMWARE_OVERRUN_ERROR
,SerialPort.LISTENING_EVENT_SOFTWARE_OVERRUN_ERROR
,SerialPort.LISTENING_EVENT_PARITY_ERROR
-
serialEvent
void serialEvent(SerialPortEvent event)
Called whenever one or more of the serial port events specified by thegetListeningEvents()
method occurs.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.
- Parameters:
event
- ASerialPortEvent
object containing information and/or data about the serial events that occurred.- See Also:
SerialPortEvent
-
-