com.alien.enterpriseRFID.util
Class SerialManager

java.lang.Object
  extended bycom.alien.enterpriseRFID.util.SerialManager

public class SerialManager
extends java.lang.Object

SerialManager in an interface to the javax.comm Serial routines. Sometimes these classes will not be present (i.e. Applets that communicate only via the Network) and in these instances we need to be able to shut off Serial functionality and stop the code from crashing with ClassNotFound exceptions.

Normal instancing this class will work fine. If serial classes are not present instancing this class will cause problems. So before instancing, use the following code:

   try {
     Class.forName("javax.comm.SerialPort");
     SerialManager serialManager = new SerialManager();
   } catch(ClassNotFoundException cnfe) {
     //Serial Classes not present on the JVM
   }
 

Version:
1.4 January 2013
Author:
David Krull

Constructor Summary
SerialManager()
          Constructs a SerialManager object.
 
Method Summary
static void addPortName(java.lang.String portName)
          Adds the named serial port to the list of ports known to the serial libraries.
 void close()
          Closes the connection to the serial port managed by this SerialManager.
 java.io.InputStream getInputStream()
          Returns the InputStream object for the serial port managed by this SerialManager.
 java.io.OutputStream getOutputStream()
          Returns the OutputStream object for the serial port managed by this SerialManager.
 int getSerialBaudRate()
          Returns the communication rate of the serial port managed by this SerialManager.
 javax.comm.SerialPort getSerialPort()
          Returns the SerialPort object managed by this SerialManager.
 javax.comm.SerialPort getSerialPort(java.lang.String serialPortName)
          Returns a SerialPort object associated with the given serialPortName.
static java.util.Vector getSerialPortList()
          Returns a list of available serial ports on this host.
 java.lang.String getSerialPortName()
          Returns the name of the serial port managed by this SerialManager.
 int getSerialPortTimeout()
          Returns the communication timeout value for the serial port managed by this SerialManager.
static void main(java.lang.String[] args)
           
 void openSerialConnection()
          Opens a connection to the serial port managed by this SerialManager.
 void setInputStream(java.io.InputStream inputStream)
          Sets the InputStream object for the serial port managed by this SerialManager.
 void setOutputStream(java.io.OutputStream outputStream)
          Sets the OutputStream object for the serial port managed by this SerialManager.
 void setSerialBaudRate(int serialBaudRate)
          Sets the communication rate of the serial port managed by this SerialManager.
 void setSerialPort(javax.comm.SerialPort serialPort)
          Sets the SerialPort object managed by this SerialManager.
 void setSerialPortName(java.lang.String serialPortName)
          Sets the name of the serial port managed by this SerialManager.
 void setSerialPortTimeout(int serialPortTimeout)
          Sets the communication timeout value for the serial port managed by this SerialManager.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialManager

public SerialManager()
Constructs a SerialManager object.

Method Detail

getSerialPortName

public java.lang.String getSerialPortName()
Returns the name of the serial port managed by this SerialManager.

Returns:
the name of this managed serial port
See Also:
setSerialPortName(String)

setSerialPortName

public void setSerialPortName(java.lang.String serialPortName)
Sets the name of the serial port managed by this SerialManager.

Parameters:
serialPortName - the name of this managed serial port
See Also:
getSerialPortName()

getSerialBaudRate

public int getSerialBaudRate()
Returns the communication rate of the serial port managed by this SerialManager.

Returns:
the communication rate of this managed serial port
See Also:
setSerialBaudRate(int)

setSerialBaudRate

public void setSerialBaudRate(int serialBaudRate)
Sets the communication rate of the serial port managed by this SerialManager.

Parameters:
serialBaudRate - the communication rate of this managed serial port

getSerialPort

public javax.comm.SerialPort getSerialPort()
Returns the SerialPort object managed by this SerialManager.

Returns:
the SerialPort object being managed

setSerialPort

public void setSerialPort(javax.comm.SerialPort serialPort)
Sets the SerialPort object managed by this SerialManager.

Parameters:
serialPort - the SerialPort object to manage

getSerialPortTimeout

public int getSerialPortTimeout()
Returns the communication timeout value for the serial port managed by this SerialManager.

Returns:
the timeout value of this managed serial port

setSerialPortTimeout

public void setSerialPortTimeout(int serialPortTimeout)
Sets the communication timeout value for the serial port managed by this SerialManager.

Parameters:
serialPortTimeout - the timeout value of this managed serial port

getInputStream

public java.io.InputStream getInputStream()
Returns the InputStream object for the serial port managed by this SerialManager.

Returns:
InputStream object of this managed serial port

setInputStream

public void setInputStream(java.io.InputStream inputStream)
Sets the InputStream object for the serial port managed by this SerialManager.

Parameters:
inputStream - the InputStream object of this managed serial port

getOutputStream

public java.io.OutputStream getOutputStream()
Returns the OutputStream object for the serial port managed by this SerialManager.

Returns:
OutputStream object of this managed serial port

setOutputStream

public void setOutputStream(java.io.OutputStream outputStream)
Sets the OutputStream object for the serial port managed by this SerialManager.

Parameters:
outputStream - the OutputStream object of this managed serial port

openSerialConnection

public void openSerialConnection()
                          throws java.lang.Exception
Opens a connection to the serial port managed by this SerialManager.

Throws:
java.lang.Exception - if serial communication fails

close

public void close()
Closes the connection to the serial port managed by this SerialManager.


getSerialPortList

public static java.util.Vector getSerialPortList()
Returns a list of available serial ports on this host. The list will evaluate to null if there are no serial ports available.

Returns:
a list of serial ports

getSerialPort

public javax.comm.SerialPort getSerialPort(java.lang.String serialPortName)
                                    throws java.io.IOException,
                                           javax.comm.NoSuchPortException,
                                           javax.comm.PortInUseException
Returns a SerialPort object associated with the given serialPortName.

Parameters:
serialPortName - the name of the serial port
Returns:
a SerialPort object for the named serial port
Throws:
java.io.IOException - if serial classes aren't loaded or the port doesn't exist
javax.comm.PortInUseException - if the named serial port is already in use
javax.comm.NoSuchPortException

addPortName

public static void addPortName(java.lang.String portName)
Adds the named serial port to the list of ports known to the serial libraries. The name is first checked to see if it already exists in the list, in which case it is ignored. Some OSes (Linux) don't offer port-discovery services, so any serial ports that you want to connect to must first be added to the list with this method.

Parameters:
portName - the name of the serial port to be added

main

public static void main(java.lang.String[] args)