Package gnu.io

Examples of gnu.io.CommPortIdentifier


  @Override
  public void open() throws IOException {
    if (port == null) {
      try {
        CommPortIdentifier identifier = findCommPortIdentifier(comPort);
        if (identifier == null) {
          throw new RuntimeException("ComPort not found: " + comPort);
        }

        port = (SerialPort)identifier.open(SerialPortNfcDevice.class.getName() + "." + comPort,
            TIMEOUT_FOR_OPEN);

        port.setInputBufferSize(SERIAL_PORT_BUFFER_SIZE);
        //        initSerialPortEventListener();
View Full Code Here


  @SuppressWarnings("unchecked")
  private CommPortIdentifier findCommPortIdentifier(String name) {
    Enumeration<CommPortIdentifier> enumeration = CommPortIdentifier.getPortIdentifiers();

    CommPortIdentifier port = null;

    while (enumeration.hasMoreElements()) {
      CommPortIdentifier identifier = enumeration.nextElement();
      if (identifier.getName().equalsIgnoreCase(name)) {
        port = identifier;
      }
    }
    return port;
  }
View Full Code Here

  // post: adds all the found ports to a combo box on the GUI
  public void searchForPorts() {
    ports = CommPortIdentifier.getPortIdentifiers();

    while (ports.hasMoreElements()) {
      CommPortIdentifier curPort = (CommPortIdentifier) ports
          .nextElement();

      // get only serial ports
      if (curPort.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        window.cBoxPorts.addItem(curPort.getName());
        portMap.put(curPort.getName(), curPort);
      }
    }
  }
View Full Code Here

    @Override
    protected ConnectFuture connect0(
            SocketAddress remoteAddress, SocketAddress localAddress,
            IoSessionInitializer<? extends ConnectFuture> sessionInitializer) {

        CommPortIdentifier portId;
        Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();

        SerialAddress portAddress = (SerialAddress) remoteAddress;

        // looping around found ports
        while (portList.hasMoreElements()) {
            portId = (CommPortIdentifier) portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                if (log.isDebugEnabled()) {
                    log.debug("Serial port discovered : " + portId.getName());
                }
                if (portId.getName().equals(portAddress.getName())) {
                    try {
                        if (log.isDebugEnabled()) {
                            log
                                    .debug("Serial port found : "
                                            + portId.getName());
                        }

                        SerialPort serialPort = initializePort("Apache MINA",
                                portId, portAddress);
View Full Code Here

  SerialPort s;

  public SerialConnector(String com) throws UnknownHostException,
      IOException, NoSuchPortException, PortInUseException,
      UnsupportedCommOperationException {
    CommPortIdentifier portIdentifier = CommPortIdentifier
        .getPortIdentifier(com);
    // if (portIdentifier.isCurrentlyOwned()) {
    // System.out.println("Error: Port is currently in use");
    // } else {
    CommPort commPort = portIdentifier
        .open(this.getClass().getName(), 2000);
    if (commPort instanceof SerialPort) {
      s = (SerialPort) commPort;
      s.setSerialPortParams(115200, SerialPort.DATABITS_8,
          SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
View Full Code Here

  @Override
  protected void openHardware() throws CULDeviceException {
    log.debug("Opening serial CUL connection for " + deviceName);
    try {
      CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(deviceName);
      if (portIdentifier.isCurrentlyOwned()) {
        throw new CULDeviceException("The port " + deviceName + " is currenty used by "
            + portIdentifier.getCurrentOwner());
      }
      CommPort port = portIdentifier.open(this.getClass().getName(), 2000);
      if (!(port instanceof SerialPort)) {
        throw new CULDeviceException("The device " + deviceName + " is not a serial port");
      }
      serialPort = (SerialPort) port;
      serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, parityMode);
View Full Code Here

       
        this.inputBuffer = new StringBuilder();
       
        boolean returnCode;

        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(name);
          
        if (portIdentifier.isCurrentlyOwned()) {
            throw new Exception(Localization.getString("connection.exception.inuse"));
        } else {
            this.commPort = portIdentifier.open(this.getClass().getName(), 2000);

            SerialPort serialPort = (SerialPort) this.commPort;
            serialPort.setSerialPortParams(baud,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);

            this.in = serialPort.getInputStream();
View Full Code Here

        java.util.List<CommPortIdentifier> returnList =
                new java.util.ArrayList<CommPortIdentifier>();
       
        while ( portEnum.hasMoreElements() )
        {
            CommPortIdentifier portIdentifier = portEnum.nextElement();
            if (portIdentifier.getPortType() == type) {
                returnList.add(portIdentifier);
            }
        }
        return returnList;
    }
View Full Code Here

            //java.util.Collections.sort(portList);

            java.util.Iterator<CommPortIdentifier> portIter = portList.iterator();

            while ( portIter.hasNext() ) {
                CommPortIdentifier portIdentifier = portIter.next();
                commPortComboBox.addItem(portIdentifier.getName());
            }

            commPortComboBox.setSelectedIndex(0);
        }
    }
View Full Code Here

    }

    // parse ports and if the default port is found, initialized the reader
    Enumeration portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
      CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
      if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        if (id.getName().equals(port)) {
          logger.debug("Serial port '{}' has been found.", port);
          portId = id;
        }
      }
    }
    if (portId != null) {
      // initialize serial port
      try {
        serialPort = (SerialPort) portId.open("openHAB", 2000);
      } catch (PortInUseException e) {
        throw new PlugwiseInitializationException(e);
      }

      try {
        serialPort.addEventListener(this);
      } catch (TooManyListenersException e) {
        throw new PlugwiseInitializationException(e);
      }

      // activate the DATA_AVAILABLE notifier
      serialPort.notifyOnDataAvailable(true);

      try {
        // set port parameters
        serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
            SerialPort.PARITY_NONE);
      } catch (UnsupportedCommOperationException e) {
        throw new PlugwiseInitializationException(e);
      }

      try {
        // get the output stream
        outputChannel = Channels.newChannel(serialPort.getOutputStream());
      } catch (IOException e) {
        throw new PlugwiseInitializationException(e);
      }
    } else {
      StringBuilder sb = new StringBuilder();
      portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
        CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
        if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
          sb.append(id.getName() + "\n");
        }
      }
      throw new PlugwiseInitializationException("Serial port '" + port + "' could not be found. Available ports are:\n" + sb.toString());
    }
View Full Code Here

TOP

Related Classes of gnu.io.CommPortIdentifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.