com.adventnet.cli.serial
Class SerialCommSession

java.lang.Object
  |
  +--com.adventnet.cli.serial.SerialCommSession

public class SerialCommSession
extends java.lang.Object
implements javax.comm.SerialPortEventListener

This class can be used to establish CLI session with the desired device over Serial port. The Session can be established by passing the port Identifier as argument to open() or the portId can be set and later the open() method without any argument can be called.


Constructor Summary
SerialCommSession()
          Default constructor
SerialCommSession(java.lang.String portId)
          This creates a SerialCommSession with the portId set.
 
Method Summary
 void close()
          Closes the Serial port session.
 int getFlowControlMode()
          Gets the flow control mode set.
 java.lang.String getPortId()
          Gets the portId set.
 int getReadTimeout()
          Gets the Read Timeout.
 void open()
          Opens a Serial Port connection through the port identifier already set using setPortId.
 void open(java.lang.String portId)
          Opens a Serial Port connection through the port identifier specified.
 byte[] read()
          Reads the data over the opened Serial Port connection.
 void serialEvent(javax.comm.SerialPortEvent event)
          This method is called if any Serial Port Event occurs.
 void setFlowControlMode(int flowcontrol)
          Sets the flow control mode.
 void setPortId(java.lang.String portId)
          Sets the portId through which the session is to be established.
 void setReadTimeout(int timeout)
          Sets the Read Timeout.
 void setSerialCommParameters(int baudRate, int dataBits, int stopBits, int parity)
          Sets the various Communication parameters.
 void write(byte[] data)
          Writes the data over the opened Serial Port connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialCommSession

public SerialCommSession()
Default constructor

SerialCommSession

public SerialCommSession(java.lang.String portId)
This creates a SerialCommSession with the portId set. The portId can be set to COM1, COM2 etc on windows systems. It can be set to /dev/ttyS0, /dev/ttyS1 etc on Unix based systems.
Parameters:
portId - the port Identifier as a String
Method Detail

open

public void open()
          throws java.lang.Exception
Opens a Serial Port connection through the port identifier already set using setPortId.

open

public void open(java.lang.String portId)
          throws java.lang.Exception
Opens a Serial Port connection through the port identifier specified. The portId argument specifies the port through which the communication needs to be established ( for systems containing more than one serial port).
Parameters:
portId - the port Identifier as a String

setSerialCommParameters

public void setSerialCommParameters(int baudRate,
                                    int dataBits,
                                    int stopBits,
                                    int parity)
                             throws javax.comm.UnsupportedCommOperationException
Sets the various Communication parameters. The parameters that can be set using this method are the Baud rate, the no of Data bits, the no of Stop bits and parity.
Parameters:
baudRate - the baud rate
dataBits - the number of data bits to be used
stopBits - the number of stop bits to be used
parity - the parity type

setFlowControlMode

public void setFlowControlMode(int flowcontrol)
Sets the flow control mode. No flow control is set by default.
Parameters:
flowcontrol - the flow control mode.

getFlowControlMode

public int getFlowControlMode()
Gets the flow control mode set.
Returns:
the flow control mode.

serialEvent

public void serialEvent(javax.comm.SerialPortEvent event)
This method is called if any Serial Port Event occurs. These events could be generated for CTS, DSR and other signals or conditions. The API user need not call this method. It is automatically called by the SerialPort class to which an instance of this class is registered for receiving the SerialPort events.
Specified by:
serialEvent in interface javax.comm.SerialPortEventListener
Parameters:
event - the SerialPortEvent.

write

public void write(byte[] data)
           throws java.io.IOException
Writes the data over the opened Serial Port connection.
Parameters:
data - the byte array containing the data to be written.

read

public byte[] read()
            throws java.io.IOException
Reads the data over the opened Serial Port connection.
Returns:
the read data as a byte array

close

public void close()
           throws java.lang.Exception
Closes the Serial port session.

setReadTimeout

public void setReadTimeout(int timeout)
Sets the Read Timeout. This is the timeout in milliseconds for which the read() call blocks when there is no data available to read.
Parameters:
timeout - the read timeout in milliseconds.

getReadTimeout

public int getReadTimeout()
Gets the Read Timeout.
Returns:
the read timeout in milliseconds.

setPortId

public void setPortId(java.lang.String portId)
Sets the portId through which the session is to be established.
Parameters:
portId - the port Identifier as a String.

getPortId

public java.lang.String getPortId()
Gets the portId set.
Returns:
the port Identifier that is set.


Copyright (c)AdventNet Inc., 1996-2003