jamod at SF

net.wimpi.modbus.msg
Class ModbusMessageImpl

java.lang.Object
  extended bynet.wimpi.modbus.msg.ModbusMessageImpl
All Implemented Interfaces:
ModbusMessage, Transportable
Direct Known Subclasses:
ModbusRequest, ModbusResponse

public abstract class ModbusMessageImpl
extends java.lang.Object
implements ModbusMessage

Abstract class implementing a ModbusMessage. This class provides specialised implementations with the functionality they have in common.

Version:
1.2rc1 (09/11/2004)
Author:
Dieter Wimberger

Constructor Summary
ModbusMessageImpl()
           
 
Method Summary
 int getDataLength()
          Returns the length of the data appended after the protocol header.
 int getFunctionCode()
          Returns the function code of this ModbusMessage as int.
 java.lang.String getHexMessage()
          Returns the this message as hexadecimal string.
 int getOutputLength()
          Returns the number of bytes that will be written by 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()
          Tests if this message instance is headless.
abstract  void readData(java.io.DataInput din)
          Reads the subclass specific data from the given DataInput instance.
 void readFrom(java.io.DataInput din)
          Reads this Transportable from the given DataInput.
 void setDataLength(int length)
          Sets the length of the data appended after the protocol header.
protected  void setFunctionCode(int code)
          Sets the function code of this ModbusMessage.
 void setHeadless()
          Sets the flag that marks this ModbusMessage as headless (for serial transport).
protected  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.
abstract  void writeData(java.io.DataOutput dout)
          Writes the subclass specific data to the given DataOutput.
 void writeTo(java.io.DataOutput dout)
          Writes this message to the given DataOutput.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModbusMessageImpl

public ModbusMessageImpl()
Method Detail

isHeadless

public boolean isHeadless()
Tests if this message instance is headless.

Returns:
true if headless, false otherwise.

setHeadless

public void setHeadless()
Description copied from interface: ModbusMessage
Sets the flag that marks this ModbusMessage as headless (for serial transport).

Specified by:
setHeadless in interface ModbusMessage

setHeadless

protected void setHeadless(boolean b)
Sets the headless flag of this message.

Parameters:
b - true if headless, false otherwise.

getTransactionID

public int getTransactionID()
Description copied from interface: ModbusMessage
Returns the transaction identifier of this ModbusMessage as int.
The identifier is a 2-byte (short) non negative integer value valid in the range of 0-65535.

Specified by:
getTransactionID in interface ModbusMessage
Returns:
the transaction identifier as int.

setTransactionID

public void setTransactionID(int tid)
Sets the transaction identifier of this ModbusMessage.

The identifier should be a 2-byte (short) non negative integer value valid in the range of 0-65535.

Parameters:
tid - the transaction identifier as int.

getProtocolID

public int getProtocolID()
Description copied from interface: ModbusMessage
Returns the protocol identifier of this ModbusMessage as int.
The identifier is a 2-byte (short) non negative integer value valid in the range of 0-65535.

Specified by:
getProtocolID in interface ModbusMessage
Returns:
the protocol identifier as int.

setProtocolID

public void setProtocolID(int pid)
Sets the protocol identifier of this ModbusMessage.

The identifier should be a 2-byte (short) non negative integer value valid in the range of 0-65535.

Parameters:
pid - the protocol identifier as int.

getDataLength

public int getDataLength()
Description copied from interface: ModbusMessage
Returns the length of the data appended after the protocol header.

Specified by:
getDataLength in interface ModbusMessage
Returns:
the data length as int.

setDataLength

public void setDataLength(int length)
Sets the length of the data appended after the protocol header.

Note that this library, a bit in contrast to the specification, counts the unit identifier and the function code to the header, because it is part of each and every message. Thus this message will append two (2) to the passed in integer value.

Parameters:
length - the data length as int.

getUnitID

public int getUnitID()
Description copied from interface: ModbusMessage
Returns the unit identifier of this ModbusMessage as int.
The identifier is a 1-byte non negative integer value valid in the range of 0-255.

Specified by:
getUnitID in interface ModbusMessage
Returns:
the unit identifier as int.

setUnitID

public 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.

Parameters:
num - the unit identifier number to be set.

getFunctionCode

public int getFunctionCode()
Description copied from interface: ModbusMessage
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.
Function codes are ordered in conformance classes their values are specified in net.wimpi.modbus.Modbus.

Specified by:
getFunctionCode in interface ModbusMessage
Returns:
the function code as int.
See Also:
Modbus

setFunctionCode

protected void setFunctionCode(int code)
Sets the function code of this ModbusMessage.
The function code should be a 1-byte non negative integer value valid in the range of 0-127.
Function codes are ordered in conformance classes their values are specified in net.wimpi.modbus.Modbus.

Parameters:
code - the code of the function to be set.
See Also:
Modbus

writeTo

public void writeTo(java.io.DataOutput dout)
             throws java.io.IOException
Writes this message to the given DataOutput.

Specified by:
writeTo in interface Transportable
Parameters:
dout - a DataOutput instance.
Throws:
java.io.IOException - if an I/O related error occurs.

writeData

public abstract void writeData(java.io.DataOutput dout)
                        throws java.io.IOException
Writes the subclass specific data to the given DataOutput.

Parameters:
dout - the DataOutput to be written to.
Throws:
java.io.IOException - if an I/O related error occurs.

readFrom

public void readFrom(java.io.DataInput din)
              throws java.io.IOException
Description copied from interface: Transportable
Reads this Transportable from the given DataInput.

Specified by:
readFrom in interface Transportable
Parameters:
din - the DataInput to read from.
Throws:
java.io.IOException - if an I/O error occurs or the data is invalid.

readData

public abstract void readData(java.io.DataInput din)
                       throws java.io.IOException
Reads the subclass specific data from the given DataInput instance.

Parameters:
din - the DataInput to read from.
Throws:
java.io.IOException - if an I/O related error occurs.

getOutputLength

public int getOutputLength()
Description copied from interface: Transportable
Returns the number of bytes that will be written by Transportable.writeTo(DataOutput).

Specified by:
getOutputLength in interface Transportable
Returns:
the number of bytes that will be written as int.

getHexMessage

public java.lang.String getHexMessage()
Returns the this message as hexadecimal string.

Specified by:
getHexMessage in interface ModbusMessage
Returns:
the message as hex encoded string.

jamod at SF

Copyright © 2002-2004 jamod development team.