public abstract class ModbusMessageImpl extends Object implements ModbusMessage
| Constructor and Description |
|---|
ModbusMessageImpl() |
| Modifier and Type | Method and Description |
|---|---|
int |
getDataLength()
Returns the length of the data appended after the protocol header.
|
int |
getFunctionCode()
Returns the function code of this ModbusMessage as int.
The function code is a 1-byte non negative integer value valid in the range of 0-127. |
String |
getHexMessage()
Returns the raw message as String containing a
hexadecimal series of bytes.
|
int |
getOutputLength()
Returns the number of bytes that will
be written by
ModbusMessage.writeTo(DataOutput). |
int |
getProtocolID()
Returns the protocol identifier of this ModbusMessage as
int.
|
int |
getTransactionID()
Returns the transaction identifier of this ModbusMessage as
int.
|
int |
getUnitID()
Returns the unit identifier of this ModbusMessage as
int.
|
boolean |
isHeadless()
Check the flag which indicates that this ModbusMessage is for a
headless (serial, or headless networked) connection.
|
abstract void |
readData(DataInput din)
Reads the subclass specific data from the given DataInput instance.
|
void |
readFrom(DataInput din)
Reads this Transportable from the given
DataInput.
|
void |
setDataLength(int length)
Sets the length of the data appended after the protocol header.
|
void |
setHeadless()
Sets the flag that marks this ModbusMessage as headless (for
serial transport).
|
void |
setHeadless(boolean b)
Sets the headless flag of this message.
|
void |
setProtocolID(int pid)
Sets the protocol identifier of this ModbusMessage.
|
void |
setTransactionID(int tid)
Sets the transaction identifier of this ModbusMessage.
|
void |
setUnitID(int num)
Sets the unit identifier of this ModbusMessage.
The identifier should be a 1-byte non negative integer value valid in the range of 0-255. |
abstract void |
writeData(DataOutput dout)
Writes the subclass specific data to the given DataOutput.
|
void |
writeTo(DataOutput dout)
Writes this Transportable to the
given DataOutput.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetMessagepublic boolean isHeadless()
ModbusMessageisHeadless in interface ModbusMessagepublic void setHeadless()
ModbusMessagesetHeadless in interface ModbusMessagepublic int getTransactionID()
ModbusMessageThe identifier is a 2-byte (short) non negative integer value valid in the range of 0-65535.
getTransactionID in interface ModbusMessagepublic void setTransactionID(int tid)
The identifier must be a 2-byte (short) non negative integer value valid
in the range of 0-65535.
tid - the transaction identifier as int.public int getProtocolID()
ModbusMessageThe identifier is a 2-byte (short) non negative integer value valid in the range of 0-65535.
getProtocolID in interface ModbusMessagepublic void setProtocolID(int pid)
The identifier should be a 2-byte (short) non negative integer value
valid in the range of 0-65535.
pid - the protocol identifier as int.public int getDataLength()
ModbusMessagegetDataLength in interface ModbusMessagepublic void setDataLength(int length)
Note that this library, a bit in contrast to the specification, counts the unit identifier and the function code in the header, because it is part of each and every message. Thus this method will add two (2) to the passed in integer value.
This method does not include the length of a final CRC/LRC for those protocols which requirement.
length - the data length as int.public int getUnitID()
ModbusMessageThe identifier is a 1-byte non negative integer value valid in the range of 0-255.
getUnitID in interface ModbusMessagepublic void setUnitID(int num)
num - the unit identifier number to be set.public int getFunctionCode()
ModbusMessageFunction codes are ordered in conformance classes their values are specified in com.ghgande.j2mod.modbus.Modbus.
getFunctionCode in interface ModbusMessageModbuspublic String getHexMessage()
ModbusMessageThis method is specially for debugging purposes, allowing the user to log the communication in a manner used in the specification document.
getHexMessage in interface ModbusMessagepublic void setHeadless(boolean b)
b - true if headless, false otherwise.public int getOutputLength()
ModbusMessageModbusMessage.writeTo(DataOutput).getOutputLength in interface ModbusMessagepublic void writeTo(DataOutput dout) throws IOException
ModbusMessagewriteTo in interface ModbusMessagedout - the DataOutput to write to.IOException - if an I/O error occurs.public void readFrom(DataInput din) throws IOException
ModbusMessagereadFrom in interface ModbusMessagedin - the DataInput to read from.IOException - if an I/O error occurs or the data
is invalid.public abstract void writeData(DataOutput dout) throws IOException
dout - the DataOutput to be written to.IOException - if an I/O related error occurs.public abstract void readData(DataInput din) throws IOException
din - the DataInput to read from.IOException - if an I/O related error occurs.Copyright © 2025. All Rights Reserved.