FileDocCategorySizeDatePackage
SerialReadByEvents.javaAPI DocExample1855Sun Apr 11 19:50:40 BST 2004None

SerialReadByEvents

public class SerialReadByEvents extends CommPortOpen implements javax.comm.SerialPortEventListener
Read from a Serial port, notifying when data arrives. Simulation of part of an event-logging service.
version
$Id: SerialReadByEvents.java,v 1.4 2004/04/11 23:50:40 ian Exp $
author
Ian F. Darwin, http://www.darwinsys.com/

Fields Summary
Constructors Summary
public SerialReadByEvents(JFrame f)

		
		super(f);
	
Methods Summary
protected voidconverse()
Hold the conversation.


		if (!(thePort instanceof SerialPort)) {
			System.err.println("But I wanted a SERIAL port!");
			System.exit(1);
		}
		// Tell the Comm API that we want serial events.
		((SerialPort)thePort).notifyOnDataAvailable(true);
		try {
			((SerialPort)thePort).addEventListener(this);
		} catch (TooManyListenersException ev) {
			// "CantHappen" error
			System.err.println("Too many listeners(!) " + ev);
			System.exit(0);
		}
	
		
	
public static voidmain(java.lang.String[] argv)


		new SerialReadByEvents(null).converse();
	
public voidserialEvent(javax.comm.SerialPortEvent ev)

		String line;
		try {
			line = is.readLine();
			if (line == null) {
				System.out.println("EOF on serial port.");
				System.exit(0);
			}
			os.println(line);
		} catch (IOException ex) {
			System.err.println("IO Error " + ex);
		}