net.wimpi.modbus.net
Class SerialConnection

java.lang.Object
  extended by net.wimpi.modbus.net.SerialConnection
All Implemented Interfaces:
gnu.io.SerialPortEventListener, EventListener

public class SerialConnection
extends Object
implements gnu.io.SerialPortEventListener

Class that implements a serial connection which can be used for master and slave implementations.

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

Field Summary
private  boolean m_Open
           
private  SerialParameters m_Parameters
           
private  gnu.io.CommPortIdentifier m_PortIdentifyer
           
private  InputStream m_SerialIn
           
private  gnu.io.SerialPort m_SerialPort
           
private  ModbusSerialTransport m_Transport
           
 
Constructor Summary
SerialConnection(SerialParameters parameters)
          Creates a SerialConnection object and initilizes variables passed in as params.
 
Method Summary
 void close()
          Close the port and clean up associated elements.
 ModbusTransport getModbusTransport()
          Returns the ModbusTransport instance to be used for receiving and sending messages.
 gnu.io.SerialPort getSerialPort()
          Returns the reference to the SerialPort instance.
 boolean isOpen()
          Reports the open status of the port.
 void open()
          Opens the communication port.
 void serialEvent(gnu.io.SerialPortEvent e)
           
 void setConnectionParameters()
          Sets the connection parameters to the setting in the parameters object.
 void setReceiveTimeout(int ms)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Parameters

private SerialParameters m_Parameters

m_Transport

private ModbusSerialTransport m_Transport

m_PortIdentifyer

private gnu.io.CommPortIdentifier m_PortIdentifyer

m_SerialPort

private gnu.io.SerialPort m_SerialPort

m_Open

private boolean m_Open

m_SerialIn

private InputStream m_SerialIn
Constructor Detail

SerialConnection

public SerialConnection(SerialParameters parameters)
Creates a SerialConnection object and initilizes variables passed in as params.

Parameters:
parameters - A SerialParameters object.
Method Detail

getSerialPort

public gnu.io.SerialPort getSerialPort()
Returns the reference to the SerialPort instance.

Returns:
a reference to the SerialPort.

getModbusTransport

public ModbusTransport getModbusTransport()
Returns the ModbusTransport instance to be used for receiving and sending messages.

Returns:
a ModbusTransport instance.

open

public void open()
          throws Exception
Opens the communication port.

Throws:
Exception - if an error occurs.

setReceiveTimeout

public void setReceiveTimeout(int ms)

setConnectionParameters

public void setConnectionParameters()
                             throws Exception
Sets the connection parameters to the setting in the parameters object. If set fails return the parameters object to origional settings and throw exception.

Throws:
Exception - if the configured parameters cannot be set properly on the port.

close

public void close()
Close the port and clean up associated elements.


isOpen

public boolean isOpen()
Reports the open status of the port.

Returns:
true if port is open, false if port is closed.

serialEvent

public void serialEvent(gnu.io.SerialPortEvent e)
Specified by:
serialEvent in interface gnu.io.SerialPortEventListener


Copyright © 2012. All Rights Reserved.