Package gnu.io

Examples of gnu.io.SerialPort


                            log
                                    .debug("Serial port found : "
                                            + portId.getName());
                        }

                        SerialPort serialPort = initializePort("Apache MINA",
                                portId, portAddress);

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(
                                this, getListeners(), portAddress, serialPort);
View Full Code Here


        long connectTimeout = getConnectTimeoutMillis();
        if (connectTimeout > Integer.MAX_VALUE) {
            connectTimeout = Integer.MAX_VALUE;
        }

        SerialPort serialPort = (SerialPort) portId.open(
                user, (int) connectTimeout);

        serialPort.setSerialPortParams(portAddress.getBauds(), portAddress
                .getDataBitsForRXTX(), portAddress.getStopBitsForRXTX(),
                portAddress.getParityForRXTX());

        serialPort.setFlowControlMode(portAddress.getFLowControlForRXTX());

        serialPort.notifyOnDataAvailable(true);

        if (config.isLowLatency()) {
            serialPort.setLowLatency();
        }

        serialPort.setInputBufferSize(config.getInputBufferSize());
        serialPort.setOutputBufferSize(config.getOutputBufferSize());

        if (config.getReceiveThreshold() >= 0) {
            serialPort.enableReceiveThreshold(config.getReceiveThreshold());
        } else {
            serialPort.disableReceiveThreshold();
        }

        return serialPort;
    }
View Full Code Here

                            log
                                    .debug("Serial port found : "
                                            + portId.getName());
                        }

                        SerialPort serialPort = initializePort("Apache MINA",
                                portId, portAddress);

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(
                                this, getListeners(), portAddress, serialPort);
View Full Code Here

        long connectTimeout = getConnectTimeoutMillis();
        if (connectTimeout > Integer.MAX_VALUE) {
            connectTimeout = Integer.MAX_VALUE;
        }

        SerialPort serialPort = (SerialPort) portId.open(
                user, (int) connectTimeout);

        serialPort.setSerialPortParams(portAddress.getBauds(), portAddress
                .getDataBitsForRXTX(), portAddress.getStopBitsForRXTX(),
                portAddress.getParityForRXTX());

        serialPort.setFlowControlMode(portAddress.getFLowControlForRXTX());

        serialPort.notifyOnDataAvailable(true);

        if (config.isLowLatency()) {
            serialPort.setLowLatency();
        }

        serialPort.setInputBufferSize(config.getInputBufferSize());
        serialPort.setOutputBufferSize(config.getOutputBufferSize());

        if (config.getReceiveThreshold() >= 0) {
            serialPort.enableReceiveThreshold(config.getReceiveThreshold());
        } else {
            serialPort.disableReceiveThreshold();
        }

        return serialPort;
    }
View Full Code Here

        //no port found
        return portIdentifier;
    }

    private boolean isSomethingListeningOn(CommPortIdentifier port) {
        SerialPort sPort = openPort(port);
        //is possible to communicate with this port. close test connection.
        if (sPort != null) {
            sPort.close();
            return true;
        } else {
            return false;
        }
    }
View Full Code Here

        } // is port already in use?
        if (port.isCurrentlyOwned()) {
            System.out.println("Port \"" + port.getName() + "\" in use.");
            return null;
        } // open the port
        SerialPort serialPort = null;
        try {
            CommPort cPort = port.open(APP_ID, PORT_OPENTIME);//2 seconds wait
            if (cPort instanceof SerialPort) {
                serialPort = (SerialPort) cPort;
            } else {
                System.out.println("Port \"" + port.getName() + "\" is not a serial port.");
                cPort.close();
                return null;
            }
        } catch (PortInUseException e) {
            System.out.println("Port \"" + port.getName() + "\" in use.");
            return null;
        }

        //setting connection parameters
        try {
            serialPort.setSerialPortParams(PORT_BAUDRATE, PORT_DATABITS, PORT_STOPBITS, PORT_PARITY);
            serialPort.enableReceiveTimeout(PORT_IN_TIMEOUT);
            serialPort.enableReceiveThreshold(PORT_IN_THRESHOLD);
        } catch (UnsupportedCommOperationException e) {
            System.out.println("Parameters not allowed for port \"" + port.getName() + "\".");
            serialPort.close();
            return null;
        }

        // opening streams
    //  InputStream inStream = null;
    //  OutputStream outStream = null;
        try {
            this.in = serialPort.getInputStream();
            this.out = serialPort.getOutputStream();
        } catch (IOException e) {
            System.out.println("Can't open streams of the port \"" + port.getName() + "\".");
            serialPort.close();
            return null;
        }
        isConnected = true;
        return serialPort;
    }
View Full Code Here

                    }
                    EasyControl.sleep(5000);
                    continue;
                }
                warningIssued = false;
                SerialPort ctrlCon;
                try {
                    ctrlCon = (SerialPort)commPort;
                    ctrlCon.setSerialPortParams
                        (9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                         SerialPort.PARITY_NONE);
                    ctrlCon.enableReceiveTimeout(1000);
                } catch (UnsupportedCommOperationException e) {
                    // This is really fatal: configured port does not support
                    // configured mode.
                    log.config("Port " + portIdentifier.getName()
                               + " cannot be configured: " + e.getMessage());
                    return;
                }
                try {
                    ecInStream = ctrlCon.getInputStream();
                    ecOutStream = new BufferedOutputStream
                        (ctrlCon.getOutputStream());
                } catch (IOException e) {
                    log.severe("Port " + portIdentifier.getName()
                            + " cannot be used: " + e.getMessage());
                    return;
                }
View Full Code Here

                            log
                                    .debug("Serial port found : "
                                            + portId.getName());
                        }

                        SerialPort serialPort = initializePort("Apache MINA",
                                portId, portAddress);

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(
                                this, getListeners(), portAddress, serialPort);
View Full Code Here

        long connectTimeout = getConnectTimeoutMillis();
        if (connectTimeout > Integer.MAX_VALUE) {
            connectTimeout = Integer.MAX_VALUE;
        }

        SerialPort serialPort = (SerialPort) portId.open(
                user, (int) connectTimeout);

        serialPort.setSerialPortParams(portAddress.getBauds(), portAddress
                .getDataBitsForRXTX(), portAddress.getStopBitsForRXTX(),
                portAddress.getParityForRXTX());

        serialPort.setFlowControlMode(portAddress.getFLowControlForRXTX());

        serialPort.notifyOnDataAvailable(true);

        if (config.isLowLatency()) {
            serialPort.setLowLatency();
        }

        serialPort.setInputBufferSize(config.getInputBufferSize());
        serialPort.setOutputBufferSize(config.getOutputBufferSize());

        if (config.getReceiveThreshold() >= 0) {
            serialPort.enableReceiveThreshold(config.getReceiveThreshold());
        } else {
            serialPort.disableReceiveThreshold();
        }

        return serialPort;
    }
View Full Code Here

    final int openTimeout = Integer.parseInt(props.getProperty("open.timeout"));
    final int baudRate = Integer.parseInt(props.getProperty("baud.rate"));
    final int dataBits = getDataBits(props);
    final int stopBits = getStopBits(props);
    final int parity = getParity(props);
    final SerialPort port = (SerialPort) portId.open("MyWay Garmin GPS Plugin", openTimeout);
    port.notifyOnDataAvailable(true);
    port.setSerialPortParams(baudRate, dataBits, stopBits, parity);
    return port;
  }
View Full Code Here

TOP

Related Classes of gnu.io.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.