Enum Class PortScanner

java.lang.Object
java.lang.Enum<PortScanner>
eu.mihosoft.devcom.PortScanner
All Implemented Interfaces:
Serializable, Comparable<PortScanner>, Constable

public enum PortScanner extends Enum<PortScanner>
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.
  • Enum Constant Details

    • INSTANCE

      public static final PortScanner INSTANCE
      The instance of this scanner.
  • Method Details

    • values

      public static PortScanner[] 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

      public static PortScanner valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getInstance

      public static PortScanner 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/infos
      connectionProvider - connection provider
      tryConnect - function that attempts to connect to the specified port
      timeout - 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/infos
      connectionProvider - connection provider
      tryConnect - 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

      public vjavax.observer.Subscription addPortListener(Consumer<PortEvent> consumer)
      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