Package javax.comm

Examples of javax.comm.SerialPort


    }
  }

  public void itemStateChanged(ItemEvent  ev)
  {
    SerialPort  port;
    String     sel = (String) ev.getItem();
    int    value = 0;

    if (sel.equals("None"))
    {
      value = SerialPort.PARITY_NONE;
    }

    else if (sel.equals("Odd"))
    {
      value = SerialPort.PARITY_ODD;
    }

    else if (sel.equals("Even"))
    {
      value = SerialPort.PARITY_EVEN;
    }

    else
    {
      this.showValue();
    }

    port = this.owner.port;

    if ((value > 0) && (port != null))
    {
      /*
       *  Set the parity.
       *
       *  Note: we must set all of the parameters, not just
       *  the parity, hence the use of get*
       */

      try
      {
        port.setSerialPortParams(port.getBaudRate(),
               port.getDataBits(),
               port.getStopBits(),
               value);
      }
   
      catch (UnsupportedCommOperationException e)
      {
        System.out.println("Cannot set parity to "
               + sel + " for port "
               + port.getName());
      }
    }

    this.owner.showValues();
  }
View Full Code Here


    System.exit(0);
  }

  private void cleanup()
  {
    SerialPort  p;

    while (portNum > 0)
    {
      portNum--;
      panelNum--;

      /*
       *  Close the port
       */

      p = portDisp[portNum].getPort();

      if (p != null)
      {
        System.out.println("Closing port "
               + portNum
               + " ("
               + p.getName()
               + ")");

        portDisp[portNum].closeBBPort();
      }
    }
View Full Code Here

   }
    */

   private SerialPort getOpenPort(String portName) {
      Object found = c_ports.get(portName);
      SerialPort port = null;
      CommPortIdentifier portId = null;
      try {
         portId = CommPortIdentifier.getPortIdentifier(portName);
      } catch (Exception e) {
      }
View Full Code Here

   }
    */

   public InputStream getInputStream() throws IOException {
      if (portName != null) {
         SerialPort port = getOpenPort(portName);
         if (port != null) {
            return port.getInputStream();
         } else {
            throw new IOException("port is null");
         }
      } else {
         throw new IOException("port id is null");
View Full Code Here

         if (portIdentifier.isCurrentlyOwned()) {
            System.out.println("SerialPortConnection.listenForPort() port already owned, excluding it, owner: " + portIdentifier.getCurrentOwner());
            continue;
         }

         SerialPort serialPort = null;

         // Open the port
         try {
            serialPort = (SerialPort) portIdentifier.open(
                  "BTGPSSimulator.listenForPort()", 2000);
         } catch (PortInUseException pe) {
            System.out
                  .println("SerialPortConnection.listenForPort() port is already used by another application, excluding it: "
                        + name);
            continue;
         } catch (ClassCastException cc) {
            System.out
                  .println("SerialPortConnection.listenForPort() port was not a serial port after all, excluding it: "
                        + name);
            continue;
         }

         // Start listening for events on the port
         if (serialPort != null) {
            try {
               serialPort.addEventListener(this); // This is first call in this
               // section in case of
               // exception
               serialPort.notifyOnDataAvailable(true); // This is the event
               // that is specific
               // when receiving a
               // connection.
               portsOpenWhileListening.add(serialPort);
            } catch (TooManyListenersException te) {
               System.out
                     .println("SerialPortConnection.listenForPort() there was already another listener for the port, excluding it: "
                           + name);
               serialPort.close();
               continue;
            }
         }
      }

      // If no ports found, then return
      if (portsOpenWhileListening.size() == 0) {
         System.out
               .println("SerialPortConnection.listenForPort() No available ports found");
         ErrorDialog errorDialog = new ErrorDialog(caller, "No Ports Found");
         errorDialog.addText("No available ports found.");
         errorDialog.show();
         return;
      }

      // Show a wait message
      cancelDialog = new CancelDialog(caller, "Waiting for Connections");
      cancelDialog
            .addText("Please connect a device, e.g. select your computer as the Bluetooth GPS in WF Navigator.");
      cancelDialog.show();

      isWaitingOnEvent = false;

      // Close all temporary ports
      for (int i = 0; i < portsOpenWhileListening.size(); i++) {
         SerialPort serialPort = (SerialPort) portsOpenWhileListening.get(i);
         serialPort.close();
      }
      portsOpenWhileListening.clear();

      // Confirm that a connection has been made
      if (portOpenAndReadyForUse) {
View Full Code Here

                     .println("SerialPortConnection.serialEvent() data is available, we connect to the data sender: "
                           + portName);

               // Close all temporary ports
               for (int i = 0; i < portsOpenWhileListening.size(); i++) {
                  SerialPort serialPort = (SerialPort) portsOpenWhileListening
                        .get(i);

                  if (serialPort.getName().equals(portName)) {
                     portsOpenWhileListening.remove(i);
                     serialPort.close();
                  }
               }

               // Open the targeted port in the regular way
               openPort(portName);
View Full Code Here

TOP

Related Classes of javax.comm.SerialPort

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.