Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.elexis.rs232
Class Connection

java.lang.Object
  extended by ch.elexis.rs232.Connection
All Implemented Interfaces:
PortEventListener

public class Connection
extends java.lang.Object
implements PortEventListener


Nested Class Summary
static interface Connection.ComPortListener
           
 
Field Summary
 
Fields inherited from interface ch.elexis.rs232.PortEventListener
CR, ETX, LF, NAK, STX, XOFF, XON
 
Constructor Summary
Connection(java.lang.String portName, java.lang.String port, java.lang.String settings, Connection.ComPortListener l)
           
 
Method Summary
 void awaitFrame(int start, int end, int following, int timeout)
          Wait for a frame of the device to be sent.
 void close()
           
 boolean connect()
           
static java.lang.String[] getComPorts()
           
 boolean isOpen()
          Reports the open status of the port.
 void openConnection(SerialParameters parameters)
          Attempts to open a serial connection and streams using the parameters in the SerialParameters object.
 void readLine(byte delimiter, int timeout)
          Read a line of input from the serial port.
 boolean send(java.lang.String data)
           
 void sendBreak()
          Send a one second break signal.
 void serialEvent(SerialPortEvent e)
          Handles SerialPortEvents.
 void setConnectionParameters(SerialParameters parameters)
          Sets the connection parameters to the setting in the parameters object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection(java.lang.String portName,
                  java.lang.String port,
                  java.lang.String settings,
                  Connection.ComPortListener l)
Method Detail

connect

public boolean connect()

openConnection

public void openConnection(SerialParameters parameters)
                    throws SerialConnectionException
Attempts to open a serial connection and streams using the parameters in the SerialParameters object. If it is unsuccesfull at any step it returns the port to a closed state, throws a SerialConnectionException, and returns. Gives a timeout of 30 seconds on the portOpen to allow other applications to reliquish the port if have it open and no longer need it.

Throws:
SerialConnectionException

setConnectionParameters

public void setConnectionParameters(SerialParameters parameters)
                             throws SerialConnectionException
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:
SerialConnectionException

awaitFrame

public void awaitFrame(int start,
                       int end,
                       int following,
                       int timeout)
Wait for a frame of the device to be sent. Ignores all input until a start byte is found. collects all bytes from that point until an end byte was received or the timeout happened.

Parameters:
start - character defining the start of a frame
end - character singalling end of frame
following - number of bytes after end to wait for (e.g. checksum)
timeout - number of seconds to wait for a frame to complete before givng up

readLine

public void readLine(byte delimiter,
                     int timeout)
Read a line of input from the serial port. A line is defined as a series of bytes delimited by the given delimiter (e.g. \n).

Parameters:
delimiter - The delimiter to recognize the end of line
timeout - number of seconds to wait at most before giving up

serialEvent

public void serialEvent(SerialPortEvent e)
Handles SerialPortEvents. The two types of SerialPortEvents that this program is registered to listen for are DATA_AVAILABLE and BI. During DATA_AVAILABLE the port buffer is read until it is drained, when no more data is availble and 30ms has passed the method returns. When a BI event occurs the words BREAK RECEIVED are written to the messageAreaIn.


close

public void close()

isOpen

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

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

sendBreak

public void sendBreak()
Send a one second break signal.


send

public boolean send(java.lang.String data)

getComPorts

public static java.lang.String[] getComPorts()

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis