net.wimpi.modbus.net
Class SerialConnection

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

public class SerialConnection
extends Object
implements javax.comm.SerialPortEventListener

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

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

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.
 javax.comm.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(javax.comm.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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 javax.comm.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(javax.comm.SerialPortEvent e)
Specified by:
serialEvent in interface javax.comm.SerialPortEventListener


Copyright © 2010. All Rights Reserved.