public interface ModbusMessage
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
equals(Object obj) |
|
ModbusError |
getError() |
Get the Modbus error code.
|
ModbusFunction |
getFunction() |
Get the Modbus function code.
|
int |
getUnitId() |
Get the device unit ID.
|
int |
hashCode() |
|
default boolean |
isException() |
Test if this message is an exception (error).
|
boolean |
isSameAs(ModbusMessage obj) |
Compare the "sameness" of this message to another.
|
<T extends ModbusMessage> |
unwrap(Class<T> msgType) |
Unwrap this message as a specific message type, if possible.
|
default ModbusMessage |
validate() |
Validate this message in some way.
|
int getUnitId()
Modbus allows only values from 0-255 for the unit ID.
ModbusFunction getFunction()
ModbusError getError()
default boolean isException()
getError() it not null<T extends ModbusMessage> T unwrap(Class<T> msgType)
This method should be used instead of relying on a direct
instanceof operator, because the actual Modbus message may be
encapsulated in some way. For example, instead of trying this:
// WRONG WAY: DO NOT TRY THIS
ModbusMessage msg = getMessageFromSomewhere();
if ( msg instanceof RegistersModbusMessage ) {
RegistersModbusMessage r = (RegistersModbusMessage)msg;
// do something with registers...
}
try this instead:
ModbusMessage msg = getMessageFromSomewhere();
RegistersModbusMessage r = msg.unwrap(RegistersModbusMessage.class);
if ( r != null ) {
// do something with registers...
}
T - the message type to unwrapmsgType - the class to unwrap asmsgTypeboolean isSameAs(ModbusMessage obj)
obj - the message to compare to this messageother is the same as this class, and the
properties are the samedefault ModbusMessage validate() throws ModbusValidationException
This method might validate a checksum or the overall structure of the message for correctness, throwing an exception if any validation fails.
ModbusValidationException - if any validation failure occurs