Package gnu.io

Examples of gnu.io.CommPortIdentifier


  /**
   * Create the application.
   */
  public TempPressure() {
    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

    // iterate through, looking for the port
    while (portEnum.hasMoreElements()) {
      CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
      for (String portName : PORT_NAMES) {
        if (currPortId.getName().equals(portName)) {
          portId = currPortId;
          break;
        }
      }
    }
View Full Code Here


  private static final int TIME_OUT = 2000;
  /** Default bits per second for COM port. */
  private static final int DATA_RATE = 9600;

  public void initialize() {
    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

    // iterate through, looking for the port
    while (portEnum.hasMoreElements()) {
      CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
      for (String portName : PORT_NAMES) {
        if (currPortId.getName().equals(portName)) {
          portId = currPortId;
          break;
        }
      }
    }
View Full Code Here

  private static final int TIME_OUT = 2000;
  /** Default bits per second for COM port. */
  private static final int DATA_RATE = 9600;

  public void initialize() {
    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

    // iterate through, looking for the port
    while (portEnum.hasMoreElements()) {
      CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
      for (String portName : PORT_NAMES) {
        if (currPortId.getName().equals(portName)) {
          portId = currPortId;
          break;
        }
      }
    }
View Full Code Here

                    // so loop over available ports instead.
                    portIdentifier = null;
                    for (@SuppressWarnings("unchecked")
                         Enumeration<CommPortIdentifier> e = CommPortIdentifier
                         .getPortIdentifiers(); e.hasMoreElements();) {
                        CommPortIdentifier pid = e.nextElement();
                        if (pid.getName().equals(portName)) {
                            portIdentifier = pid;
                            break;
                        }
                    }
                    if (portIdentifier == null) {
View Full Code Here

    @Override
    protected synchronized 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

  @SuppressWarnings("unchecked")
  public static CommPortIdentifier[] getAllPorts() {
    final List<CommPortIdentifier> serials = new ArrayList<CommPortIdentifier>();
    for (final Enumeration<CommPortIdentifier> e = CommPortIdentifier.getPortIdentifiers(); e
      .hasMoreElements();) {
      final CommPortIdentifier port = e.nextElement();
      if (port.getPortType() == CommPortIdentifier.PORT_SERIAL)
        serials.add(port);
    }
    return serials.toArray(new CommPortIdentifier[serials.size()]);
  }
View Full Code Here

  @Override
  public GarminDownloadHandler connect(final Properties props, final ProtocolListener l,
    final ProtocolFinder f) {
    try {
      final String port = props.getProperty("port");
      final CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(port);
      _serialPort = getSerialPort(portId, props);
      final InputStream gpsInputStream = _serialPort.getInputStream();
      final OutputStream gpsOutputStream = _serialPort.getOutputStream();
      GarminUnitConfiguration.getLinkProtocol().setUploadHandler(
        new GarminSerialUploadHandler(gpsOutputStream));
View Full Code Here

  @SuppressWarnings("unchecked")
  private void init() {
    final List<String> ports = new ArrayList<String>();
    final Enumeration<CommPortIdentifier> en = CommPortIdentifier.getPortIdentifiers();
    while (en.hasMoreElements()) {
      final CommPortIdentifier cpi = en.nextElement();
      ports.add(cpi.getName());
    }
    _portCombo.setItems(ports.toArray(new String[ports.size()]));
    _connectionTypeCombo.setItems(new String[] { "Serial", "USB" });
    _parityCombo.setItems(new String[] { "none", "even", "odd" });
  }
View Full Code Here

    initSerial();
  }

  private void initSerial() {
    puertos = new LinkedList();
    CommPortIdentifier portId;
    // parse ports and if the default port is found, initialized the reader
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
      portId = (CommPortIdentifier) portList.nextElement();
      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        // initalize serial port
        try {
          // name,timeout
          serialPort = (SerialPort) portId.open("lee", 2000); //$NON-NLS-1$
          System.out
              .println(Messages
                  .getString("io.SerialCommunication.1") + portId.getName()); //$NON-NLS-1$
          puertos.add(serialPort);
          // Cadena de entrada por el puerto serie
          inputStream = serialPort.getInputStream();
          // Se añade el evento
          serialPort.addEventListener(this);
          // activate the DATA_AVAILABLE notifier
          serialPort.notifyOnDataAvailable(true);
          // set port parameters
          serialPort.setSerialPortParams(115200,
              SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
              SerialPort.PARITY_NONE);
          // Inicializa la escritura al puerto
          initWriteToPort();
          // Pide al concentrador que devuelva la información de la
          // red y asi comprobar si el puerto es concentrador zigBee
          byte bArray[] = { 0x23, 0x03, 0x40 };
          writeToPort(bArray);
        } catch (IOException e) {
          e.printStackTrace();
        } catch (TooManyListenersException e2) {
          e2.printStackTrace();
        } catch (UnsupportedCommOperationException e) {
          e.printStackTrace();
        } catch (PortInUseException e) {
          System.out
              .println(Messages
                  .getString("io.SerialCommunication.2") + portId.getName()); //$NON-NLS-1$
        }
      }
    }
    try {
      Thread.sleep(2000);// Para dar tiempo a que responda al controlador
View Full Code Here

  public static List<String> getSerialPorts() {
    log.debug("Loading available COM ports");
    Enumeration<CommPortIdentifier> portList;
    List<String> ports = new ArrayList<String>();
    portList = CommPortIdentifier.getPortIdentifiers();
    CommPortIdentifier portId;
    while (portList.hasMoreElements()) {
      portId = portList.nextElement();
      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        ports.add(portId.getName());
      }
    }
    if (log.isDebugEnabled()) {
      final StringBuilder sb = new StringBuilder("Found the following ports: ");
      for (int i = 0; i < ports.size(); i++) {
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.