net.wimpi.modbus.io
Class ModbusTCPTransport

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

public class ModbusTCPTransport
extends Object
implements ModbusTransport

Class that implements the Modbus transport flavor.

Version:
1.2 (@date@)
Author:
Dieter Wimberger

Field Summary
private  BytesInputStream m_ByteIn
           
private  DataInputStream m_Input
           
private  DataOutputStream m_Output
           
 
Constructor Summary
ModbusTCPTransport(Socket socket)
          Constructs a new ModbusTransport instance, for a given Socket.
 
Method Summary
 void close()
          Closes the raw input and output streams of this ModbusTransport.
private  void prepareStreams(Socket socket)
          Prepares the input and output streams of this ModbusTCPTransport instance based on the given socket.
 ModbusRequest readRequest()
          Reads a ModbusRequest from the input stream of this ModbusTransport.
 ModbusResponse readResponse()
          Reads a ModbusResponse from the input stream of this ModbusTransport.
 void setSocket(Socket socket)
          Sets the Socket used for message transport and prepares the streams used for the actual I/O.
 void writeMessage(ModbusMessage msg)
          Writes a to the output stream of this ModbusTransport.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Input

private DataInputStream m_Input

m_Output

private DataOutputStream m_Output

m_ByteIn

private BytesInputStream m_ByteIn
Constructor Detail

ModbusTCPTransport

public ModbusTCPTransport(Socket socket)
Constructs a new ModbusTransport instance, for a given Socket.

Parameters:
socket - the Socket used for message transport.
Method Detail

setSocket

public void setSocket(Socket socket)
               throws IOException
Sets the Socket used for message transport and prepares the streams used for the actual I/O.

Parameters:
socket - the Socket used for message transport.
Throws:
IOException - if an I/O related error occurs.

close

public void close()
           throws IOException
Description copied from interface: ModbusTransport
Closes the raw input and output streams of this ModbusTransport.

Specified by:
close in interface ModbusTransport
Throws:
IOException - if a stream cannot be closed properly.

writeMessage

public void writeMessage(ModbusMessage msg)
                  throws ModbusIOException
Description copied from interface: ModbusTransport
Writes a to the output stream of this ModbusTransport.

Specified by:
writeMessage in interface ModbusTransport
Parameters:
msg - a ModbusMessage.
Throws:
ModbusIOException - data cannot be written properly to the raw output stream of this ModbusTransport.

readRequest

public ModbusRequest readRequest()
                          throws ModbusIOException
Description copied from interface: ModbusTransport
Reads a ModbusRequest from the input stream of this ModbusTransport.

Specified by:
readRequest in interface ModbusTransport
Returns:
req the ModbusRequest read from the underlying stream.
Throws:
ModbusIOException - data cannot be read properly from the raw input stream of this ModbusTransport.

readResponse

public ModbusResponse readResponse()
                            throws ModbusIOException
Description copied from interface: ModbusTransport
Reads a ModbusResponse from the input stream of this ModbusTransport.

Specified by:
readResponse in interface ModbusTransport
Returns:
res the ModbusResponse read from the underlying stream.
Throws:
ModbusIOException - data cannot be read properly from the raw input stream of this ModbusTransport.

prepareStreams

private void prepareStreams(Socket socket)
                     throws IOException
Prepares the input and output streams of this ModbusTCPTransport instance based on the given socket.

Parameters:
socket - the socket used for communications.
Throws:
IOException - if an I/O related error occurs.


Copyright © 2012. All Rights Reserved.