com.alien.enterpriseRFID.discovery
Class SerialDiscoveryListenerService

java.lang.Object
  extended bycom.alien.enterpriseRFID.discovery.SerialDiscoveryListenerService
All Implemented Interfaces:
java.lang.Runnable

public class SerialDiscoveryListenerService
extends java.lang.Object
implements java.lang.Runnable

SerialDiscoveryListenerService checks each serial port for a Reader. When the SerialDiscoveryListenerService object is instantiated and started, it automatically gets a list of all the serial ports on the host computer and then proceeds to interrogate each port, looking for a reader. If a reader is found the class calls the readerAdded() method of any registered DiscoveryListeners. If a reader has already been found and a subsequent search finds it again, the readerRenew() method is called. Finally, if a reader was found and now cannot be found, the readerRemoved() method is called.

In all instances, the DiscoveryListener methods will be passed a DiscoveryItem, which provides details on the reader that was discovered, renewed, or removed.

Additionally, an ActionListener can be registered with the SerialDiscoveryListenerService. The actionPerformed() method is called when the SerialDiscoveryListenerService scans each port, and can be used as a progress monitor. See the example code in the Developer's Kit for more information.

In addition to listening for events, the SerialDiscoveryListenerService has a method, getDiscoveryItems(), which returns an array of all currently known readers available on the serial ports.

The setSerialPortList(String) method is useful in limiting which serial ports to scan, or to scan ports that aren't automatically detected.

This service operates slightly differently that the NetworkDiscoveryListenerService: The NetworkDiscoveryListenerService constantly listens for readers via UDP protocol. This service will scan the serial ports, but only on demand. It cannot constantly run in the background for fear of interrupting with the use of a serial port; it cannot keep opening and closing serial ports in case another application wants to use it

Version:
1.6 Nov 2013 Serial discovery is a little more lenient with extra connection messages on the serial port (Bluetooth adapters announcing themselves, etc.). Also remove the code that turns AutoMode off (and back on again) before asking for ReaderType. This was only an issue in the very old readers., 1.5 Dec 2012
Author:
David Krull

Field Summary
 boolean isDebug
           
static int SCANNING_END
          Used to identify within an ActionListener that all of the ports have been scanned.
static int SCANNING_PORT
          Used to identify within an ActionListener just what the action being reported is.
static int SCANNING_PORTBUSY
          Used to identify within an ActionListener that a scanned port was busy.
 
Constructor Summary
SerialDiscoveryListenerService()
          Creates a new SerialDiscoveryListenerService.
 
Method Summary
 void allDiscoveryItemsExpired()
           
 void checkSerialPort(java.lang.String serialPortName)
          Checks a given serial port for a Reader.
 void discoveryItemExpired(DiscoveryItem discoveryItem)
          Removes a DiscoveryItem from the hashtable, and notifies listeners.
 java.awt.event.ActionListener getActionListener()
          Returns the object that has been registered by this SerialDiscoveryListenerService to receive messages about the progress of the serial port scanning.
 DiscoveryItem[] getDiscoveryItems()
          Returns an array of DiscoveryItems representing all of the readers that this SerialDiscoveryListenerService knows about.
 DiscoveryListener getDiscoveryListener()
          Returns the object that has been registered by this SerialDiscoveryListenerService to receive messages when readers are discovered, renewed, or removed on the serial ports.
 int getMaxSerialPort()
          Deprecated. use getSerialPortList() instead
 int getSerialBaudRate()
          Returns the serial baud rate used to discover serially-connected readers.
 java.lang.String getSerialPortList()
          Returns the list of serial ports that will be scanned.
 boolean isRunning()
          Returns true if this SerialDiscoveryListenerService is running, and false if it is not.
 void run()
          This SerialDiscoveryListenerService will scan all the serial ports for Readers.
 void setActionListener(java.awt.event.ActionListener actionListener)
          Registers an object with this SerialDiscoveryListenerService to receive messages about the progress of the serial port scanning.
 void setDiscoveryListener(DiscoveryListener discoveryListener)
          Registers an object with this SerialDiscoveryListenerService to receive messages when readers are discovered, renewed, or removed on the serial ports.
 void setMaxSerialPort(int maxPort)
          Deprecated. use setSerialPortList(String) instead
 void setSerialBaudRate(int serialBaudRate)
          Sets the hserial baud rate used to discover serially-connected readers.
 void setSerialPortList(java.lang.String portList)
          Specifies which serial ports will be scanned.
 void startService()
          Starts up this SerialDiscoveryListenerService.
 void stopService()
          Stops this SerialDiscoveryListenerService.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCANNING_PORT

public static final int SCANNING_PORT
Used to identify within an ActionListener just what the action being reported is. In this case, that a particular port is being scanned.

See Also:
Constant Field Values

SCANNING_END

public static final int SCANNING_END
Used to identify within an ActionListener that all of the ports have been scanned.

See Also:
Constant Field Values

SCANNING_PORTBUSY

public static final int SCANNING_PORTBUSY
Used to identify within an ActionListener that a scanned port was busy.

See Also:
Constant Field Values

isDebug

public boolean isDebug
Constructor Detail

SerialDiscoveryListenerService

public SerialDiscoveryListenerService()
                               throws AlienDiscoverySerialException
Creates a new SerialDiscoveryListenerService.

Throws:
AlienDiscoverySerialException - if serial classes are not present
Method Detail

getDiscoveryListener

public DiscoveryListener getDiscoveryListener()
Returns the object that has been registered by this SerialDiscoveryListenerService to receive messages when readers are discovered, renewed, or removed on the serial ports. Registered listeners must implement the DiscoveryListener interface.

Returns:
the registered discovery listener object

setDiscoveryListener

public void setDiscoveryListener(DiscoveryListener discoveryListener)
Registers an object with this SerialDiscoveryListenerService to receive messages when readers are discovered, renewed, or removed on the serial ports. Registered listeners must implement the DiscoveryListener interface.

Parameters:
discoveryListener - the listening object

getActionListener

public java.awt.event.ActionListener getActionListener()
Returns the object that has been registered by this SerialDiscoveryListenerService to receive messages about the progress of the serial port scanning.

Returns:
the registered ActionListener object

setActionListener

public void setActionListener(java.awt.event.ActionListener actionListener)
Registers an object with this SerialDiscoveryListenerService to receive messages about the progress of the serial port scanning. Registered listeners must implement the ActionListener interface.

Parameters:
actionListener - the listening object

getMaxSerialPort

public int getMaxSerialPort()
Deprecated. use getSerialPortList() instead

Returns the highest-numbered serial port to scan to. Serial ports higher that this maximum will not be scanned for readers. In some cases, some PCs with USB-Serial converters and other similar devices cause the comm libraries to think there are more serial ports than in reality. This parameters lets you limit the range of serial port scanning to just the lower values.

The default value for maxSerialPort is 8.

Returns:
the port number of the highest port to scan for readers

setMaxSerialPort

public void setMaxSerialPort(int maxPort)
Deprecated. use setSerialPortList(String) instead

Sets the highest-numbered serial port to scan to. Serial ports higher that this maximum will not be scanned for readers. In some cases, some PCs with USB-Serial converters and other similar devices cause the comm libraries to think there are more serial ports than in reality. This parameters lets you limit the range of serial port scanning to just the lower values.

The default value for maxSerialPort is 8.

Parameters:
maxPort - the port number of the highest port to scan for readers

getSerialBaudRate

public int getSerialBaudRate()
Returns the serial baud rate used to discover serially-connected readers. This setting will apply to all serial discovery attempts, so all of your readers should be communicating at the same baud rate.

The default value for serialBaudRate is 115200, which is the default communication rate of all Alien readers.

Returns:
the serial baud rate used when scanning for readers

setSerialBaudRate

public void setSerialBaudRate(int serialBaudRate)
Sets the hserial baud rate used to discover serially-connected readers. This setting will apply to all serial discovery attempts, so all of your readers should be communicating at the same baud rate.

The default value for serialBaudRate is 115200, which is the default communication rate of all Alien readers.

Parameters:
serialBaudRate - the baud rate at which to scan for readers

getSerialPortList

public java.lang.String getSerialPortList()
Returns the list of serial ports that will be scanned. The list is a comma- separated string of integers. For example, "1,2,3" means only COM1, COM2, and COM3 ports will be scanned. An empty string indicates all discovered serial ports will be scanned.

Returns:
comma-separated list of valid serial ports
See Also:
setSerialPortList(String)

setSerialPortList

public void setSerialPortList(java.lang.String portList)
Specifies which serial ports will be scanned. portList is a comma-separated string of integers. For example, "1,2,3" indicates only COM1, COM2, and COM3 serial ports should be scanned.

To scan all detected serial ports, use an empty or null string.

Parameters:
portList - comma-separated list of valid serial ports
See Also:
getSerialPortList()

startService

public void startService()
Starts up this SerialDiscoveryListenerService. This service will run until all of the serial ports have been scanned, or until its stopService() method is called.


stopService

public void stopService()
Stops this SerialDiscoveryListenerService.


run

public void run()
This SerialDiscoveryListenerService will scan all the serial ports for Readers.

Specified by:
run in interface java.lang.Runnable

isRunning

public boolean isRunning()
Returns true if this SerialDiscoveryListenerService is running, and false if it is not.

Returns:
a boolean to indicate if this service is running

checkSerialPort

public void checkSerialPort(java.lang.String serialPortName)
Checks a given serial port for a Reader. It identifies a valid reader by instantiating an AlienClass1Reader object at the port and tries to call its open() method.

Parameters:
serialPortName - the name of the serial port to scan (ex: "COM1")

discoveryItemExpired

public void discoveryItemExpired(DiscoveryItem discoveryItem)
Removes a DiscoveryItem from the hashtable, and notifies listeners. This method is public so that external sources can cancel leases... for example if an external source tries to connect and fails, it can cancel the lease that way.

Parameters:
discoveryItem - the item that has expired

allDiscoveryItemsExpired

public void allDiscoveryItemsExpired()

getDiscoveryItems

public DiscoveryItem[] getDiscoveryItems()
Returns an array of DiscoveryItems representing all of the readers that this SerialDiscoveryListenerService knows about. Items that were discovered by a NetworkDiscoveryListenerService are not included in this list.

Returns:
an array of DiscoveryItems