tuwien.auto.calimero.serial
Class FT12Connection

java.lang.Object
  extended by tuwien.auto.calimero.serial.FT12Connection

public class FT12Connection
extends java.lang.Object

Connection based on the FT1.2 protocol for communication with a BCU2 device.

Currently, one log service is provided for all connection instances, with the log service named "FT1.2".


Field Summary
static int ACK_PENDING
          Status code of communication: waiting for acknowledge after send, no error, not ready to send.
static int CLOSED
          State of communication: in closed state, no send possible.
static int OK
          State of communication: in idle state, no error, ready to send.
 
Constructor Summary
FT12Connection(int portNumber)
          Creates a new connection to a BCU2 using the FT1.2 protocol.
FT12Connection(java.lang.String portID)
          Creates a new connection to a BCU2 using the FT1.2 protocol.
FT12Connection(java.lang.String portID, int baudrate)
          Creates a new connection to a BCU2 using the FT1.2 protocol, and set the baud rate for communication.
 
Method Summary
 void addConnectionListener(KNXListener l)
          Adds the specified event listener l to receive events from this connection.
 void close()
          Ends communication with the BCU2 as specified by the FT1.2 protocol.
 int getBaudRate()
          Returns the currently used baud rate.
 java.lang.String getPortID()
          Returns the port identifier used in this connection.
static java.lang.String[] getPortIdentifiers()
          Attempts to gets the available serial communication ports on the host.
 int getState()
          Returns information about the current FT1.2 communication state.
 void removeConnectionListener(KNXListener l)
          Removes the specified event listener l, so it does no longer receive events from this connection.
 void send(byte[] frame, boolean blocking)
          Sends an EMI frame to the BCU2 connected with this endpoint.
 void setBaudrate(int baud)
          Sets a new baud rate for this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACK_PENDING

public static final int ACK_PENDING
Status code of communication: waiting for acknowledge after send, no error, not ready to send.

See Also:
Constant Field Values

CLOSED

public static final int CLOSED
State of communication: in closed state, no send possible.

See Also:
Constant Field Values

OK

public static final int OK
State of communication: in idle state, no error, ready to send.

See Also:
Constant Field Values
Constructor Detail

FT12Connection

public FT12Connection(int portNumber)
               throws KNXException
Creates a new connection to a BCU2 using the FT1.2 protocol.

If the port to use can not be told just by the number, use FT12Connection(String).
The baud rate is set to 19200.

Parameters:
portNumber - port number of the serial communication port to use; mapped to the default port identifier using this number (device and platform specific)
Throws:
KNXException - on port not found or access error, initializing port settings failed, if reset of BCU2 failed

FT12Connection

public FT12Connection(java.lang.String portID)
               throws KNXException
Creates a new connection to a BCU2 using the FT1.2 protocol.

The baud rate is set to 19200.

Parameters:
portID - port identifier of the serial communication port to use
Throws:
KNXException - on port not found or access error, initializing port settings failed, if reset of BCU2 failed

FT12Connection

public FT12Connection(java.lang.String portID,
                      int baudrate)
               throws KNXException
Creates a new connection to a BCU2 using the FT1.2 protocol, and set the baud rate for communication.

If the requested baud rate is not supported, it may get substituted with a valid baud rate by default.

Parameters:
portID - port identifier of the serial communication port to use
baudrate - baud rate to use for communication, 0 < baud rate
Throws:
KNXException - on port not found or access error, initializing port settings failed, if reset of BCU2 failed
Method Detail

addConnectionListener

public void addConnectionListener(KNXListener l)
Adds the specified event listener l to receive events from this connection.

If l was already added as listener, no action is performed.

Parameters:
l - the listener to add

close

public void close()
Ends communication with the BCU2 as specified by the FT1.2 protocol.

The BCU is always switched back into normal mode.
All registered event listeners get notified. The close event is the last event the listeners receive.
If this connection endpoint is already closed, no action is performed.


getBaudRate

public final int getBaudRate()
Returns the currently used baud rate.

After closing the connection, the returned baud rate is 0 by default.

Returns:
baud rate in Bit/s

getPortID

public final java.lang.String getPortID()
Returns the port identifier used in this connection.

After the connection is closed, the returned ID will always be the empty string.

Returns:
port ID as string, or empty string

getPortIdentifiers

public static java.lang.String[] getPortIdentifiers()
Attempts to gets the available serial communication ports on the host.

At first, the Java system property "microedition.commports" is queried. If there is no property with that key, and Calimero itself has access to serial ports, the lowest 10 ports numbers are enumerated and checked if present.
The empty array is returned if no ports are discovered.

Returns:
array of strings with found port IDs

getState

public final int getState()
Returns information about the current FT1.2 communication state.

Returns:
state enumeration

removeConnectionListener

public void removeConnectionListener(KNXListener l)
Removes the specified event listener l, so it does no longer receive events from this connection.

If l was not added in the first place, no action is performed.

Parameters:
l - the listener to remove

send

public void send(byte[] frame,
                 boolean blocking)
          throws KNXAckTimeoutException,
                 KNXPortClosedException
Sends an EMI frame to the BCU2 connected with this endpoint.

In blocking mode, all necessary retransmissions of the sent frame will be done automatically according to the protocol specification (i.e. in case of timeout).
If a communication failure occurs on the port, close() is called. A send timeout does not lead to closing of this connection.
In blocking send mode, on successfully receiving a confirmation, all listeners are guaranteed to get notified before this method returns. The communication state (see getState()) is reset to OK when the notification completed, so to prevent another send call from a listener.

Parameters:
frame - EMI message to send, length of frame < 256 bytes
blocking - true to block for confirmation (ACK), false to immediately return after send
Throws:
KNXAckTimeoutException - in blocking mode, if a timeout regarding the acknowledge message was encountered
KNXPortClosedException - if no communication was established in the first place or communication was closed

setBaudrate

public void setBaudrate(int baud)
Sets a new baud rate for this connection.

Parameters:
baud - requested baud rate [Bit/s], 0 < baud rate