net.wimpi.modbus.io
Class ModbusSerialTransport

java.lang.Object
  extended by net.wimpi.modbus.io.ModbusSerialTransport
All Implemented Interfaces:
ModbusTransport
Direct Known Subclasses:
ModbusASCIITransport, ModbusBINTransport, ModbusRTUTransport

public abstract class ModbusSerialTransport
extends Object
implements ModbusTransport

Abstract base class for serial ModbusTransport implementations.

Version:
@version@ (@date@)
Author:
Dieter Wimberger, John Charlton

Constructor Summary
ModbusSerialTransport()
           
 
Method Summary
abstract  void close()
          The close method closes the serial input/output streams.
 boolean isEcho()
          isEcho method returns the output echo state.
abstract  void prepareStreams(InputStream in, OutputStream out)
          prepareStreams prepares the input and output streams of this ModbusSerialTransport instance.
 void readEcho(int len)
          Reads the own message echo produced in RS485 Echo Mode within the given time frame.
abstract  ModbusRequest readRequest()
          The readRequest method listens continuously on the serial input stream for master request messages and replies if the request slave ID matches its own set in ModbusCoupler.getUnitID().
abstract  ModbusResponse readResponse()
          readResponse reads a response message from the slave responding to a master writeMessage request.
 void setCommPort(javax.comm.CommPort cp)
          setCommPort sets the comm port member and prepares the input and output streams to be used for reading from and writing to.
 void setEcho(boolean b)
          setEcho method sets the output echo state.
 void setReceiveThreshold(int th)
          Describe setReceiveThreshold method here.
 void setReceiveTimeout(int ms)
          Describe setReceiveTimeout method here.
abstract  void writeMessage(ModbusMessage msg)
          The writeMessage method writes a modbus serial message to its serial output stream to a specified slave unit ID.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModbusSerialTransport

public ModbusSerialTransport()
Method Detail

prepareStreams

public abstract void prepareStreams(InputStream in,
                                    OutputStream out)
                             throws IOException
prepareStreams prepares the input and output streams of this ModbusSerialTransport instance.

Parameters:
in - the input stream to be read from.
out - the output stream to write to.
Throws:
IOException - if an I\O error occurs.

readResponse

public abstract ModbusResponse readResponse()
                                     throws ModbusIOException
readResponse reads a response message from the slave responding to a master writeMessage request.

Specified by:
readResponse in interface ModbusTransport
Returns:
a ModbusResponse value
Throws:
ModbusIOException - if an error occurs

readRequest

public abstract ModbusRequest readRequest()
                                   throws ModbusIOException
The readRequest method listens continuously on the serial input stream for master request messages and replies if the request slave ID matches its own set in ModbusCoupler.getUnitID().

Specified by:
readRequest in interface ModbusTransport
Returns:
a ModbusRequest value
Throws:
ModbusIOException - if an error occurs

writeMessage

public abstract void writeMessage(ModbusMessage msg)
                           throws ModbusIOException
The writeMessage method writes a modbus serial message to its serial output stream to a specified slave unit ID.

Specified by:
writeMessage in interface ModbusTransport
Parameters:
msg - a ModbusMessage value
Throws:
ModbusIOException - if an error occurs

close

public abstract void close()
                    throws IOException
The close method closes the serial input/output streams.

Specified by:
close in interface ModbusTransport
Throws:
IOException - if an error occurs

setCommPort

public void setCommPort(javax.comm.CommPort cp)
                 throws IOException
setCommPort sets the comm port member and prepares the input and output streams to be used for reading from and writing to.

Parameters:
cp - the comm port to read from/write to.
Throws:
IOException - if an I/O related error occurs.

isEcho

public boolean isEcho()
isEcho method returns the output echo state.

Returns:
a boolean value

setEcho

public void setEcho(boolean b)
setEcho method sets the output echo state.

Parameters:
b - a boolean value

setReceiveThreshold

public void setReceiveThreshold(int th)
Describe setReceiveThreshold method here.

Parameters:
th - an int value

setReceiveTimeout

public void setReceiveTimeout(int ms)
Describe setReceiveTimeout method here.

Parameters:
ms - an int value

readEcho

public void readEcho(int len)
              throws IOException
Reads the own message echo produced in RS485 Echo Mode within the given time frame.

Parameters:
len - is the length of the echo to read. Timeout will occur if the echo is not received in the time specified in the SerialConnection.
Throws:
IOException - if a I/O error occurred.


Copyright © 2010. All Rights Reserved.