Package eu.mihosoft.devcom
Enum Class PortScanner
- All Implemented Interfaces:
Serializable
,Comparable<PortScanner>
,Constable
COM-Port scanner. The purpose of this class is to notify about added and removed ports
as well as creating data connections for each available port. While real COM ports are
usually not added and removed during runtime, the growing popularity of USB/FTDI-based
COM-ports make this scanner a useful tool for discovering available ports and establishing
data connections.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Event exception that contains a list of causing exceptions during port scanning.Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionvjavax.observer.Subscription
addPortListener
(Consumer<PortEvent> consumer) Adds a port listener to this scanner.static <T> Optional<COMPortConnection<T>>
findPort
(List<PortInfo> portNames, Function<PortInfo, COMPortConnection<T>> connectionProvider, Function<COMPortConnection<T>, Boolean> tryConnect) Returns a port that can successfully be connected to according to the specified try-connect function.static <T> Optional<COMPortConnection<T>>
findPort
(List<PortInfo> portNames, Function<PortInfo, COMPortConnection<T>> connectionProvider, Function<COMPortConnection<T>, Boolean> tryConnect, long timeout) Returns a port that can successfully be connected to according to the specified try-connect function.static PortScanner
Returns the instance of this scanner.boolean
Indicates whether this scanner is currently running.void
start()
Starts this port scanner with the default period.void
start
(long period) Starts this port scanner with the specified period.void
stop()
Stops this scanner.static PortScanner
Returns the enum constant of this class with the specified name.static PortScanner[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
INSTANCE
The instance of this scanner.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getInstance
Returns the instance of this scanner.- Returns:
- the instance of this scanner
-
start
public void start()Starts this port scanner with the default period. -
start
public void start(long period) Starts this port scanner with the specified period.- Parameters:
period
- scanner period in milliseconds
-
isRunning
public boolean isRunning()Indicates whether this scanner is currently running.- Returns:
true
if this code is currently running;false
otherwise
-
stop
public void stop()Stops this scanner. -
findPort
public static <T> Optional<COMPortConnection<T>> findPort(List<PortInfo> portNames, Function<PortInfo, COMPortConnection<T>> connectionProvider, Function<COMPortConnection<T>, Boolean> tryConnect, long timeout) Returns a port that can successfully be connected to according to the specified try-connect function.- Type Parameters:
T
- data type used for communication (e.g., java.lang.String or a custom packet format)- Parameters:
portNames
- list of port names/infosconnectionProvider
- connection providertryConnect
- function that attempts to connect to the specified porttimeout
- timeout in ms- Returns:
- optional COM-port connection if a port that can be connected to could be found
-
findPort
public static <T> Optional<COMPortConnection<T>> findPort(List<PortInfo> portNames, Function<PortInfo, COMPortConnection<T>> connectionProvider, Function<COMPortConnection<T>, Boolean> tryConnect) Returns a port that can successfully be connected to according to the specified try-connect function.- Type Parameters:
T
- data type used for communication (e.g., java.lang.String or a custom packet format)- Parameters:
portNames
- list of port names/infosconnectionProvider
- connection providertryConnect
- function that attempts to connect to the specified port- Returns:
- optional COM-port connection if a port that can be connected to could be found
-
addPortListener
Adds a port listener to this scanner.- Parameters:
consumer
- port listener- Returns:
- a subscription that can be used to unsubscribe the specified listener from this port scanner
-