Class Rs232ControllerBuilder


  • public class Rs232ControllerBuilder
    extends java.lang.Object
    Creates an instance of a RS232 based controller to a given port, and connects it with the selected menu. This implements the standard builder pattern, an example of use would be along the lines of:
         controller = new Rs232ControllerBuilder()
                 .withRs232(portName, baud)
                 .withMenuTree(menuTree)
                 .withLocalName("myApp")
                 .build();
         controller.start();
     
    • Constructor Detail

      • Rs232ControllerBuilder

        public Rs232ControllerBuilder()
    • Method Detail

      • withRs232

        public Rs232ControllerBuilder withRs232​(java.lang.String port,
                                                int baud)
        Mandatory, specifies the port name and baud rate for rs232.
        Parameters:
        port - the name of the port
        baud - the baud rate
        Returns:
        itself, calls can be chained.
      • withClock

        public Rs232ControllerBuilder withClock​(java.time.Clock clock)
        Optional, defaults to system clock but can be overriden
        Parameters:
        clock - the clock to use
        Returns:
        itself, can be chained
      • withExecutor

        public Rs232ControllerBuilder withExecutor​(java.util.concurrent.ScheduledExecutorService executor)
        Optional, defaults to creating a suitable executor for single connectivity
        Parameters:
        executor - the executor which must implement ScheduledExecutorService
        Returns:
        itself, suitable for chaining.
      • withHeartbeatFrequency

        public Rs232ControllerBuilder withHeartbeatFrequency​(int frequency)
        Optional, defaults to 10 seconds between heartbeats. This must be the same at both sides.
        Parameters:
        frequency - the frequency, must align with remote device.
        Returns:
        itself, suitable for chaining.
      • withMenuTree

        public Rs232ControllerBuilder withMenuTree​(MenuTree tree)
        Mandatory, the menuTree instance to store the menu items retrieved from the remote side. this menuTree must only be used with one remote.
        Parameters:
        tree - the menu tree to be populated (only use a menu tree with one remote)
        Returns:
        itself, suitable for chaining.
      • withProtocol

        public Rs232ControllerBuilder withProtocol​(MenuCommandProtocol protocol)
        Optional, defaults to the standard protocol. Only use if changing the protocol which is not advised.
        Parameters:
        protocol - a protocol object.
        Returns:
        itself, suitable for chaining.
      • withLocalName

        public Rs232ControllerBuilder withLocalName​(java.lang.String name)
        Optional, Set the name of this connection, defaults to NoName
        Parameters:
        name - the name the remote will see.
        Returns:
        itself, suitable for chaining.
      • build

        public RemoteMenuController build()
        Once the above methods have been called to fill in the blanks, then call build to get the actual instance.
        Returns:
        the actual instance.