jamod at SF

net.wimpi.modbus.io
Class ModbusSerialTransport

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

public abstract class ModbusSerialTransport
extends java.lang.Object
implements ModbusTransport

Abstract base class for serial ModbusTransport implementations.

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

Field Summary
protected  javax.comm.CommPort m_CommPort
           
protected  boolean m_Echo
           
 
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(java.io.InputStream in, java.io.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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_CommPort

protected javax.comm.CommPort m_CommPort

m_Echo

protected boolean m_Echo
Constructor Detail

ModbusSerialTransport

public ModbusSerialTransport()
Method Detail

prepareStreams

public abstract void prepareStreams(java.io.InputStream in,
                                    java.io.OutputStream out)
                             throws java.io.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:
java.io.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 java.io.IOException
The close method closes the serial input/output streams.

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

setCommPort

public void setCommPort(javax.comm.CommPort cp)
                 throws java.io.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:
java.io.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 java.io.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:
java.io.IOException - if a I/O error occurred.

jamod at SF

Copyright © 2002-2004 jamod development team.