Java 类gnu.io.NRSerialPort 实例源码

项目:spring-serial-port-connector    文件:AbstractSpringSerialPortConnector.java   
@PostConstruct
public void connect() throws TooManyListenersException, NoSuchPortException {
    log.info("Connection PostConstruct callback: connecting ...");

    serial = new NRSerialPort(serialPortProperties.getPortName(), serialPortProperties.getBaudRate());
    serial.connect();

    if (serial.isConnected()) {
        log.info("Connection opened!");
    } else {
        throw new RuntimeException("Is not possible to open connection in " + serialPortProperties.getPortName() + " port");
    }
    serial.addEventListener(this);
    serial.notifyOnDataAvailable(true);
    input = new BufferedReader(new InputStreamReader(serial.getInputStream()));
}
项目:openhab2-addons    文件:LgTvSerialHandler.java   
@Override
public void initialize() {
    portName = (String) getThing().getConfiguration().get("port");
    if (portName != null) {
        serialPort = new NRSerialPort(portName, BAUD);
        if (serialPort.connect()) {
            updateStatus(ThingStatus.ONLINE);
            output = new OutputStreamWriter(serialPort.getOutputStream());
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
                    "Failed to connect to serial port " + portName);
            logger.debug("Failed to connect to serial port {}", portName);
        }
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Serial port name not configured");
        logger.debug("Serial port name not configured");
    }
}
项目:openhab2-addons    文件:SerialAvrConnection.java   
@Override
protected void openConnection() throws IOException {
    if (isPortNameExist(portName)) {

        serialPort = new NRSerialPort(portName, LINK_SPEED);

        boolean isConnected = serialPort.connect();

        if (!isConnected) {
            throw new IOException("Failed to connect on port " + portName);
        }

        logger.debug("Connected to {}", getConnectionName());
    } else {
        throw new IOException("Serial port with name " + portName + " does not exist. Available port names: "
                + NRSerialPort.getAvailableSerialPorts());
    }
}
项目:openhab1-addons    文件:BenqProjectorSerialTransport.java   
private boolean serialConnect() {
    logger.debug("Running connection setup");
    try {
        logger.debug("Setting up socket connection to " + this.serialDevice);
        this.serialPort = new NRSerialPort(this.serialDevice, this.serialSpeed);
        this.serialPort.connect();

        this.projectorReader = new BufferedReader(new InputStreamReader(this.serialPort.getInputStream()));
        this.projectorWriter = new PrintWriter(this.serialPort.getOutputStream(), true);

        logger.debug("Serial connection setup successfully!");
        return true;
    } catch (Exception e) {
        logger.error("Unable to connect to device: " + this.serialDevice, e);
    }
    return false;
}
项目:openhab2-addons    文件:SerialRegoConnection.java   
@Override
public void connect() throws IOException {
    if (isPortNameExist(portName)) {
        serialPort = new NRSerialPort(portName, baudRate);
        if (serialPort.connect() == false) {
            throw new IOException("Failed to connect on port " + portName);
        }

        logger.debug("Connected to {}", portName);

    } else {
        throw new IOException("Serial port with name " + portName + " does not exist. Available port names: "
                + NRSerialPort.getAvailableSerialPorts());
    }
}
项目:openhab-hdl    文件:SerialPortGateway.java   
private SerialPortGateway(String serialPortName) {
    this.serialPort = new NRSerialPort(serialPortName, 9600);
    this.serialPort.connect();
}
项目:openhab-hdl    文件:SerialPortByteProvider.java   
/**
 * Create a new instance
 */
public static IByteProvider create(NRSerialPort serialPort) {
    return new SerialPortByteProvider(serialPort);
}
项目:openhab2-addons    文件:SerialRegoConnection.java   
private boolean isPortNameExist(String portName) {
    return NRSerialPort.getAvailableSerialPorts().contains(portName);
}
项目:j8051    文件:Uploader.java   
public static String[] getAvailableComPorts()
{
    Set<String> set = NRSerialPort.getAvailableSerialPorts();
    return set.toArray(new String[set.size()]);
}
项目:openhab1-addons    文件:SerialPortGateway.java   
private SerialPortGateway(String serialPortName) {
    this.serialPort = new NRSerialPort(serialPortName, 9600);
    this.serialPort.connect();
}
项目:openhab1-addons    文件:SerialPortByteProvider.java   
/**
 * Create a new instance
 */
public static IByteProvider create(NRSerialPort serialPort) {
    return new SerialPortByteProvider(serialPort);
}
项目:openhab-hdl    文件:SerialPortByteProvider.java   
/**
 * Constructor
 * 
 * @param serialPort
 */
private SerialPortByteProvider(NRSerialPort serialPort) {
    this.serialPort = serialPort;
}
项目:openhab2-addons    文件:SerialAvrConnection.java   
/**
 * Check if the Serial with the given name exist.
 * 
 * @param portName
 * @return
 */
private boolean isPortNameExist(String portName) {
    return NRSerialPort.getAvailableSerialPorts().contains(portName);
}
项目:openhab1-addons    文件:SerialPortByteProvider.java   
/**
 * Constructor
 * 
 * @param serialPort
 */
private SerialPortByteProvider(NRSerialPort serialPort) {
    this.serialPort = serialPort;
}