FileDocCategorySizeDatePackage
PhoneListener.javaAPI DocExample1161Sun Mar 28 19:09:36 BST 1999None

PhoneListener

public class PhoneListener extends Object implements SerialPortEventListener

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

  
    String portName = "COM1";
    if (args.length > 0) portName = args[0];
    
    PhoneListener pl = new PhoneListener();
    
    try {
      CommPortIdentifier cpi = CommPortIdentifier.getPortIdentifier(portName);
      if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        SerialPort modem = (SerialPort) cpi.open("Phone Listener", 1000);
        modem.notifyOnRingIndicator(true);
        modem.addEventListener(pl);
      }
    }
    catch (NoSuchPortException e) {
      System.err.println("Usage: java PhoneListener port_name");
    }
    catch (TooManyListenersException e) {
      // shouldn't happen in this example
    }
    catch (PortInUseException e) {
      System.err.println(e);
    }

  
public voidserialEvent(SerialPortEvent evt)

  
    System.err.println(evt.getEventType());
    if (evt.getEventType() == SerialPortEvent.RI) {
      System.out.println("The phone is ringing");
    }