Class Iec21Port.Builder

java.lang.Object
org.openmuc.j62056.Iec21Port.Builder
Enclosing class:
Iec21Port

public static class Iec21Port.Builder extends Object
A builder for Iec21Ports.
  • Constructor Details

    • Builder

      public Builder(String serialPortName)
      Create an Iec21Port builder.
      Parameters:
      serialPortName - examples for serial port identifiers on Linux are "/dev/ttyS0" or "/dev/ttyUSB0" and on Windows "COM1"
  • Method Details

    • setBaudRateChangeDelay

      public Iec21Port.Builder setBaudRateChangeDelay(int baudRateChangeDelay)
      Set the time in ms to wait before changing the baud rate during message exchange. This parameter can usually be set to zero for regular serial ports. If a USB to serial converter is used, you might have to use a delay of around 250ms because otherwise the baud rate is changed before the previous message (i.e. the acknowledgment) has been completely sent.

      The default value is 0.

      Parameters:
      baudRateChangeDelay - the baud rate change delay
      Returns:
      the builder
    • setInitialBaudrate

      public Iec21Port.Builder setInitialBaudrate(int initialBaudrate)
      Set the initial baud rate.

      The default is 300 baud for modes A, B, and C and 2400 baud for mode D. This function allows to change the initial baud rate in case the meter does not use the default initial baud rate.

      Parameters:
      initialBaudrate - the initial baud rate
      Returns:
      the builder
    • setTimeout

      public Iec21Port.Builder setTimeout(int timeout)
      Set the maximum time in ms to wait for new data from the remote device. A timeout of zero is interpreted as an infinite timeout.

      The default value is 5000 (= 5 seconds).

      Parameters:
      timeout - the maximum time in ms to wait for new data.
      Returns:
      the builder
    • setDeviceAddress

      public Iec21Port.Builder setDeviceAddress(String deviceAddress)
      Set the device address which is transmitted as part of the request message that is sent to the meter.

      The default value is the empty string.

      Parameters:
      deviceAddress - the device address
      Returns:
      the builder
    • setRequestStartCharacters

      public Iec21Port.Builder setRequestStartCharacters(String requestStartCharacters)
      Sets the RequestMessage start characters.

      Default value is: /?

      Parameters:
      requestStartCharacters - characters at the start of a RequestMessage
      Returns:
      the builder
    • setSelectManufacturerData

      public Iec21Port.Builder setSelectManufacturerData(String selectManufacturerData)
      Sets the Manufacturer Data for select.
      Parameters:
      selectManufacturerData - payload for select message
      Returns:
      the builder
    • setSelectExpectData

      public Iec21Port.Builder setSelectExpectData(String selectExpectData)
      Sets the Manufacturer Data for expected select response.
      Parameters:
      selectExpectData - payload for expected select reply
      Returns:
      the builder
    • setAcknowledgeMode

      public Iec21Port.Builder setAcknowledgeMode(char acknowledgeMode)
      Sets the acknowledgeMode character
      Parameters:
      acknowledgeMode - value for Acknowledge Mode
      Returns:
      the builder
    • enableVerboseMode

      public Iec21Port.Builder enableVerboseMode(boolean verbose)
      Enable or disable verbose output to standard out.

      Default is disabled.

      Parameters:
      verbose - if true enable verbose mode
      Returns:
      the builder
    • enableFixedBaudrate

      public Iec21Port.Builder enableFixedBaudrate(boolean fixedBaudRate)
      Enable a fixed baud rate.

      In mode C communication starts with baud rate 300 and then by default changes to a baud rate suggested by the meter. Enable a fixed baud rate if the baud rate shall NOT change.

      Parameters:
      fixedBaudRate - if true enable fixed baud rate
      Returns:
      the builder
    • buildAndOpen

      public Iec21Port buildAndOpen() throws IOException
      Build and open the Iec21Port.
      Returns:
      the opened Iec21Port
      Throws:
      IOException - if an error occurs while opening the associated serial port (e.g. when the serial port is occupied).