net.wimpi.modbus.io
Class ModbusRTUTransport

java.lang.Object
  extended by net.wimpi.modbus.io.ModbusSerialTransport
      extended by net.wimpi.modbus.io.ModbusRTUTransport
All Implemented Interfaces:
ModbusTransport

public class ModbusRTUTransport
extends ModbusSerialTransport

Class that implements the ModbusRTU transport flavor.

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

Field Summary
private  byte[] lastRequest
           
private  BytesInputStream m_ByteIn
           
private  BytesOutputStream m_ByteInOut
           
private  BytesOutputStream m_ByteOut
           
private  byte[] m_InBuffer
           
private  InputStream m_InputStream
           
private  OutputStream m_OutputStream
           
 
Fields inherited from class net.wimpi.modbus.io.ModbusSerialTransport
m_CommPort, m_Echo
 
Constructor Summary
ModbusRTUTransport()
           
 
Method Summary
 void clearInput()
          Clear the input if characters are found in the input stream.
 void close()
          The close method closes the serial input/output streams.
private  void getResponse(int fn, BytesOutputStream out)
           
 void prepareStreams(InputStream in, OutputStream out)
          Prepares the input and output streams of this ModbusRTUTransport instance.
 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().
 ModbusResponse readResponse()
          readResponse reads a response message from the slave responding to a master writeMessage request.
 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 net.wimpi.modbus.io.ModbusSerialTransport
isEcho, readEcho, setCommPort, setEcho, setReceiveThreshold, setReceiveTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_InputStream

private InputStream m_InputStream

m_OutputStream

private OutputStream m_OutputStream

m_InBuffer

private byte[] m_InBuffer

m_ByteIn

private BytesInputStream m_ByteIn

m_ByteInOut

private BytesOutputStream m_ByteInOut

m_ByteOut

private BytesOutputStream m_ByteOut

lastRequest

private byte[] lastRequest
Constructor Detail

ModbusRTUTransport

public ModbusRTUTransport()
Method Detail

writeMessage

public void writeMessage(ModbusMessage msg)
                  throws ModbusIOException
Description copied from class: ModbusSerialTransport
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
Specified by:
writeMessage in class ModbusSerialTransport
Parameters:
msg - a ModbusMessage value
Throws:
ModbusIOException - if an error occurs

readRequest

public ModbusRequest readRequest()
                          throws ModbusIOException
Description copied from class: ModbusSerialTransport
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
Specified by:
readRequest in class ModbusSerialTransport
Returns:
a ModbusRequest value
Throws:
ModbusIOException - if an error occurs

clearInput

public void clearInput()
                throws IOException
Clear the input if characters are found in the input stream.

Throws:
IOException

readResponse

public ModbusResponse readResponse()
                            throws ModbusIOException
Description copied from class: ModbusSerialTransport
readResponse reads a response message from the slave responding to a master writeMessage request.

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

prepareStreams

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

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

close

public void close()
           throws IOException
Description copied from class: ModbusSerialTransport
The close method closes the serial input/output streams.

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

getResponse

private void getResponse(int fn,
                         BytesOutputStream out)
                  throws IOException
Throws:
IOException


Copyright © 2012. All Rights Reserved.