Package gnu.io

Examples of gnu.io.CommPortIdentifier


    OutputStream os;
    SerialPort com;
    private boolean isOutputOpen = false;

    public MoppyCOMBridge(String portName) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException {
        CommPortIdentifier cpi = CommPortIdentifier.getPortIdentifier(portName);
        com = (SerialPort) cpi.open("MoppyDesk", 2000);
        com.setSerialPortParams(SERIAL_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
        os = com.getOutputStream();
        isOutputOpen = true;
    }
View Full Code Here


  OutputStream outputStream;
  InputStream inputStream;

  public DevBotSerial(String args) {
    Enumeration portList;
    CommPortIdentifier portId;

    portList = CommPortIdentifier.getPortIdentifiers();
    Logger.getLogger(DevBotSerial.class.getName()).log(Level.INFO, "Iniciando DevBot 1.0");

    while (portList.hasMoreElements()) {
      portId = (CommPortIdentifier) portList.nextElement();

      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        if (portId.getName().equals(args)) {
          try {
            this.portId = portId;
            open();
          } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

                TooManyListenersException {

            final CommPort commPort;
            try {

                final CommPortIdentifier cpi =
                        CommPortIdentifier.getPortIdentifier(channelSink.remoteAddress.getDeviceAddress());
                commPort = cpi.open(this.getClass().getName(), 1000);

            } catch (NoSuchPortException e) {
                throw e;
            } catch (PortInUseException e) {
                throw e;
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

  private Vector<Mensaje> mensajes = new Vector<Mensaje>();
 
  private DefaultValueDataset compassData;
 
  public void initialize() {
    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

    //First, Find an instance of serial port as set in PORT_NAMES.
    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

        List<SerialPort> ports = new ArrayList<>();
        try {
       
        //get all ports
        for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();) {
            CommPortIdentifier port = (CommPortIdentifier) enumeration.nextElement();
            SerialPort pt = new SerialPort();
            pt.portName = port.getName();
            pt.shortName = pt.portName;
            ports.add(pt);
        }
       
        //filter out dupes
View Full Code Here

  // =============================================================================
  // Methods
  // =============================================================================
  public static CommPortIdentifier serialPortIdentifier(String port)
      throws Exception {
    CommPortIdentifier result = null;
    Enumeration<?> commEnum = CommPortIdentifier.getPortIdentifiers();
    CommPortIdentifier cpi;

    while (commEnum.hasMoreElements()) {
      cpi = (CommPortIdentifier) commEnum.nextElement();

      if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        // if (cpi.getName().substring(3).equals(port.substring(3))) {
        if (cpi.getName().equals(port)) {
          result = cpi;
        }
      }
    }
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

        //i already know the port id
        if (currentPortID != null) {
            return currentPortID;
        }

        CommPortIdentifier portIdentifier = null;
        try {
            portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
        } catch (NoSuchPortException ex) {
            System.err.println("No serial device connected to port " + portName);
        }
View Full Code Here

    public void connect() {
        //is already connected
        if (isConnected) {
            return;
        }
        CommPortIdentifier portId = null;
//        if (PORT_NAME == null) { //port undefined in xml, try to discover using hello message on all ports
//            //discover using hello message
//            portId = discoverDevice();
//            if (portId == null) {
//                System.err.println("No device reply to hello-message=" + HELLO_MESSAGE);
//                isConnected = false;
//                return;
//            }
//        } else {
        //use the port name in xml to get a reference
        portId = discoverDevice(PORT_NAME); //with a given port name like COM1
//        }
        currentPort = openPort(portId);
        if (currentPort == null) {
            isConnected = false;
        } else {
            System.out.println("Connected to serial port " + portId.getName());
            // Add this object as an event listener for the serial port.
            try {
                currentPort.addEventListener(this);
            } catch (TooManyListenersException e) {
                currentPort.close();
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.