Class UserModbusFunction

java.lang.Object
net.solarnetwork.io.modbus.UserModbusFunction
All Implemented Interfaces:
ModbusFunction

public final class UserModbusFunction extends Object implements ModbusFunction
A user-defined Modbus function.
  • Constructor Details

    • UserModbusFunction

      public UserModbusFunction(byte code)
      Constructor.
      Parameters:
      code - the function code
    • UserModbusFunction

      public UserModbusFunction(String displayName, byte code)
      Constructor.
      Parameters:
      displayName - the display name
      code - the function code
    • UserModbusFunction

      public UserModbusFunction(String displayName, byte code, ModbusBlockType blockType, boolean readFunction, ModbusFunction oppositeFunction)
      Constructor.
      Parameters:
      displayName - the display name
      code - the function code
      blockType - the block type
      readFunction - the read function flag
      oppositeFunction - the opposite function
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface ModbusFunction
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface ModbusFunction
      Overrides:
      equals in class Object
    • getCode

      public byte getCode()
      Description copied from interface: ModbusFunction
      Get the function code.
      Specified by:
      getCode in interface ModbusFunction
      Returns:
      the code
    • blockType

      public ModbusBlockType blockType()
      Description copied from interface: ModbusFunction
      Get the register block type related to this function.
      Specified by:
      blockType in interface ModbusFunction
      Returns:
      the block type
    • isReadFunction

      public boolean isReadFunction()
      Description copied from interface: ModbusFunction
      Return true if this function represents a read operation.
      Specified by:
      isReadFunction in interface ModbusFunction
      Returns:
      true if this function represents a read operation, false if a write operation
    • oppositeFunction

      public ModbusFunction oppositeFunction()
      Description copied from interface: ModbusFunction
      Get an "opposite" function from this function.

      This method is used to get a read function for a given write function, and a write function for a given read function. Note that not all functions have exact opposites, such that:

       
       ModbusFunction a = myFunction();
       ModbusFunction b = a.oppositeFunction();
       ModbusFunction c = b.oppositeFunction();
       // at this stage c is not necessarily equal to a
       
       
      Specified by:
      oppositeFunction in interface ModbusFunction
      Returns:
      the function, or null if not applicable
    • toDisplayString

      public String toDisplayString()
      Description copied from interface: ModbusFunction
      Get a friendly display string for this function.
      Specified by:
      toDisplayString in interface ModbusFunction
      Returns:
      a display string