Serial Communication Provider

 

This topic discusses the various factors that need to be considered while developing Serial communication applications.

 

The com.adventnet.cli.serial package contains the implementation of CLITransportProvider and CLIProtocolOptions for Serial communication.

 

SerialCommProviderImpl

 

The SerialCommProviderImpl class is for communicating with the CLI device through serial port (RS232 interface). To communicate with devices using serial port, the cliTransport.conf file in <CLI Home>/conf has to be modified as:

 

com.adventnet.cli.transport.SerialCommProviderImpl

 

SerialCommOptionsImpl

 

The SerialCommOptionsImpl class provides the Serial port options implementation of the CLIProtocolOptions Interface. It contains parameters such as the baud rate, data bits, parity, stop bits, and flow control mode. In order to establish a CLI session over serial port with a particular device, the appropriate parameters have to be set on an instance of this class and passed to the CLISession's constructor.

 

A subsequent call to the open method in CLISession will establishes the serial connection based on the parameters set here.

 

SerialCommOptionsImpl sp = new SerialCommOptionsImpl();

sp.setSerialCommParameters(9600,8,1,0);

sp.setPortId("COM1");

CLISession clisession = new CLISession(sp);

clisession.setTransportProviderClassName

(com.adventnet.cli.transport.SerialCommProviderImpl);

clisession.open();

 

SerialCommSession

 

You can use SerialCommSession class to establish Serial connections with the desired device. A Serial connection is established after you connect to the device with appropriate options.

 

SerialCommSession API provides the following methods to set various connection options:

 

Method Purpose

open()

This method can be used to open a serial port connection through the port identifier already set.

open(java.lang.String portId)

This method can be used to open a serial port connection through the specified port identifier.

setPortId(String portId)

This method can be used to set the serial port ID.

setSerialCommParameters(int baudRate, int dataBits, int stopBits,int parity)

This method can be used to set the communication parameters such as baud rate, data bits, stop bits, and parity.

setFlowControlMode(int flowcontrol)

This method can be used to set the flow control mode.

 

The SerialCommProviderImpl implementation class is used to establish a CLI session for communicating with the device through serial port (RS232 interface).

The following code snippet explains how to establish a Serial session with a device.

 

SerialCommSession serial = new SerialCommSession();

serial.open("COM1");

serial.setSerialCommParameters(9600,8,1,0);

serial.setFlowControlMode( SerialCommOptionsImpl.FLOWCONTROL_NONE );

 

Note:

  1. If you are running the applications using the Serial communication API on Windows and Solaris, make sure you set the comm.jar in the jdk CLASSPATH, which can be downloaded from http://java.sun.com/products/javacomm/. Please refer to the instructions given in javacomm20-win32 for details.

  2. To run Serial communication applications on Linux OS, please install JCL, which is available at the following URL: http://www.interstice.com/kevinh/linuxcomm.html

 

Please refer to Java documentation for complete details.