FileDocCategorySizeDatePackage
SerialLogger.javaAPI DocExample2389Wed Mar 10 22:09:14 GMT 2004None

SerialLogger

public class SerialLogger extends Object
Read from multiple Serial ports, notifying when data arrives on any.
version
$Id: SerialLogger.java,v 1.4 2004/03/11 04:09:14 ian Exp $
author
Ian F. Darwin, http://www.darwinsys.com/

Fields Summary
Constructors Summary
public SerialLogger()

		
		// get list of ports available on this particular computer,
		// by calling static method in CommPortIdentifier.
		Enumeration pList = CommPortIdentifier.getPortIdentifiers();

		// Process the list, processing only serial ports.
		while (pList.hasMoreElements()) {
			CommPortIdentifier cpi = (CommPortIdentifier)pList.nextElement();
			String name = cpi.getName();
			System.out.print("Port " + name + " ");
			if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
				System.out.println("is a Serial Port: " + cpi);

				SerialPort thePort;
				try {
					thePort = (SerialPort)cpi.open("Logger", 1000);
				} catch (PortInUseException ev) {
					System.err.println("Port in use: " + name);
					continue;
				}

				// Tell the Comm API that we want serial events.
				thePort.notifyOnDataAvailable(true);
				try {
					thePort.addEventListener(new Logger(cpi.getName(), thePort));
				} catch (TooManyListenersException ev) {
					// "CantHappen" error
					System.err.println("Too many listeners(!) " + ev);
					System.exit(0);
				}
			}
		}
	
Methods Summary
public static voidmain(java.lang.String[] argv)


		new SerialLogger();