tuwien.auto.calimero.serial
Class LibraryAdapter

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

public abstract class LibraryAdapter
extends java.lang.Object

Adapter to access a serial communication port using some serial I/O library.

Subtypes of this class implementing the access to a specific library have to declare a public constructor expecting a String and an int argument:
Ctor(String portID, int baudrate)
Invoking this constructor will open the serial port according the supplied arguments.

After closing a library adapter, method behavior is undefined.


Field Summary
protected static LogService logger
          The same logger as used for the FT1.2 connection.
 
Constructor Summary
protected LibraryAdapter()
          Creates a new library adapter.
 
Method Summary
abstract  void close()
          Closes an open serial port.
 int getBaudRate()
          Returns the currently used baud rate.
abstract  java.io.InputStream getInputStream()
          Returns the input stream for the opened serial communication port.
abstract  java.io.OutputStream getOutputStream()
          Returns the output stream for the opened serial communication port.
protected  java.lang.Object invoke(java.lang.Object obj, java.lang.String method, java.lang.Object[] args)
          Invokes method name on object obj with arguments args.
 void setBaudRate(int baudrate)
          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

logger

protected static final LogService logger
The same logger as used for the FT1.2 connection.

Constructor Detail

LibraryAdapter

protected LibraryAdapter()
Creates a new library adapter.

Method Detail

close

public abstract void close()
                    throws java.io.IOException
Closes an open serial port.

Throws:
java.io.IOException - on error during close

getBaudRate

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

Returns:
baud rate in Bit/s

getInputStream

public abstract java.io.InputStream getInputStream()
Returns the input stream for the opened serial communication port.

Subsequent invocations might return the same or a new stream object.

Returns:
InputStream

getOutputStream

public abstract java.io.OutputStream getOutputStream()
Returns the output stream for the opened serial communication port.

Subsequent invocations might return the same or a new stream object.

Returns:
OutputStream

invoke

protected java.lang.Object invoke(java.lang.Object obj,
                                  java.lang.String method,
                                  java.lang.Object[] args)
                           throws java.lang.NoSuchMethodException,
                                  java.lang.IllegalAccessException,
                                  java.lang.reflect.InvocationTargetException
Invokes method name on object obj with arguments args.

Arguments wrapped in an object of type Integer are replaced with the primitive int type when looking up the method name.

Parameters:
obj - object on which to invoke the method
method - method name
args - list of arguments
Returns:
the result of the invoked method
Throws:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
See Also:
Class.getMethod(String, Class[]), Method.invoke(Object, Object[])

setBaudRate

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

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