FileDocCategorySizeDatePackage
PortWatcher.javaAPI DocExample1228Sun Mar 28 19:09:42 BST 1999None

PortWatcher

public class PortWatcher extends Object implements CommPortOwnershipListener

Fields Summary
String
portName
Constructors Summary
public PortWatcher(String portName)

    this.portName = portName;
    CommPortIdentifier portIdentifier = 
     CommPortIdentifier.getPortIdentifier(portName);
    portIdentifier.addPortOwnershipListener(this);
  
Methods Summary
public static voidmain(java.lang.String[] args)

    
    try {
      PortWatcher pw = new PortWatcher(args[0]);
    }
    catch (Exception e) {
      System.err.println("Usage: java PortWatcher port_name");
    }
  
  
public voidownershipChange(int type)

  
    switch (type) {
    
      case CommPortOwnershipListener.PORT_OWNED:
        System.out.println(portName + " has become unavailable");
        break;
      case CommPortOwnershipListener.PORT_UNOWNED:
        System.out.println(portName + " has become available");
        break;
      case CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED:
        System.out.println("An application has requested onwership of " 
         + portName);
        break;
      default: 
        System.out.println("Unknown port ownership event, type " + type);
    }