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.

SerialCommSession

SerialCommSession

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).

setSerialCommParameters

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.