Refine search
@Override protected void doClose() throws Exception { open = false; try { super.doClose(); } finally { if (serialPort != null) { serialPort.removeEventListener(); serialPort.close(); serialPort = null; } } }
protected void doInit() throws Exception { serialPort.setSerialPortParams( config().getOption(BAUD_RATE), config().getOption(DATA_BITS).value(), config().getOption(STOP_BITS).value(), config().getOption(PARITY_BIT).value() ); serialPort.setDTR(config().getOption(DTR)); serialPort.setRTS(config().getOption(RTS)); activate(serialPort.getInputStream(), serialPort.getOutputStream()); }
public void start() { try { Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { if (portId.getName().equals(name)) { port = (SerialPort) portId.open("serial madness", 2000); input = port.getInputStream(); output = port.getOutputStream(); port.setSerialPortParams(rate, databits, stopbits, parity); port.addEventListener(this); port.notifyOnDataAvailable(true);
while (e.hasMoreElements()) { CommPortIdentifier cpi = (CommPortIdentifier) e.nextElement(); if (cpi.getName().equals("COM11")) { pid = cpi; break; sp = (SerialPort) pid.open(getClass().getName(), 2000); sp.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); InputStream is = sp.getInputStream(); input = new BufferedReader(new InputStreamReader(is)); output = sp.getOutputStream(); output.write(line1.getBytes()); output.write(line1.getBytes()); output.flush(); sp.addEventListener(this); sp.notifyOnDataAvailable(true); if (sp != null) { System.out.println("not null"); sp.removeEventListener(); sp.close();
public void serialinit() throws Exception { CommPortIdentifier portIdentifier; portIdentifier = CommPortIdentifier.getPortIdentifier(portName); if (portIdentifier.isCurrentlyOwned()) { System.out.println("Error: Port is currently in use"); } else { serialPort = (SerialPort) portIdentifier.open("Serial", 2000); serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); inputStream = serialPort.getInputStream(); outputStream = serialPort.getOutputStream(); } }
portId = CommPortIdentifier.getPortIdentifier( serialPort ); } catch ( NoSuchPortException e ) { logger.error( "Port doesn't exist : " + serialPort , e ); if ( portId.isCurrentlyOwned( ) ) { logger.error( "port owned by someone else" ); return false; sPort = ( SerialPort ) portId.open( "GSNSerialConnection" , 30 * 1000 ); sPort.setSerialPortParams( baudRate , dataBits , stopBits , parity ); if ( flowControlMode != -1 ) { sPort.setFlowControlMode( flowControlMode ); os = sPort.getOutputStream( ); is = sPort.getInputStream( ); } catch ( IOException e ) { sPort.close( ); logger.error( e.getMessage( ) , e ); return false; sPort.notifyOnDataAvailable( true ); sPort.notifyOnBreakInterrupt( false ); sPort.enableReceiveTimeout( 30 ); } catch ( UnsupportedCommOperationException e ) {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); CommPort commPort = portIdentifier.open("org.openhab.binding.zigbee", 100); serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); switch (flowControl) { case FLOWCONTROL_OUT_NONE: serialPort.setFlowControlMode(gnu.io.SerialPort.FLOWCONTROL_NONE); break; case FLOWCONTROL_OUT_RTSCTS: serialPort.setFlowControlMode(gnu.io.SerialPort.FLOWCONTROL_RTSCTS_OUT); break; case FLOWCONTROL_OUT_XONOFF: serialPort.setFlowControlMode(gnu.io.SerialPort.FLOWCONTROL_XONXOFF_OUT); break; default: serialPort.enableReceiveThreshold(1); serialPort.enableReceiveTimeout(100); serialPort.addEventListener(this); serialPort.notifyOnDataAvailable(true); inputStream = serialPort.getInputStream(); outputStream = serialPort.getOutputStream(); } catch (IOException e) {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(this.port); SerialPort serialPort = (SerialPort) portIdentifier.open("org.openhab.binding.satel", 2000); serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.enableReceiveTimeout(this.getTimeout()); serialPort.addEventListener(new SerialPortEventListener() { @Override public void serialEvent(SerialPortEvent ev) { serialPort.notifyOnDataAvailable(true);
System.out.println("Baud is " + serialPort.getBaudRate()); System.out.println("Bits is " + serialPort.getDataBits()); System.out.println("Stop is " + serialPort.getStopBits()); System.out.println("Par is " + serialPort.getParity()); serialPort.close(); sport.setSerialPortParams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); InputStream in = sport.getInputStream(); OutputStream out = sport.getOutputStream(); sport.addEventListener(new SerialReader(in)); sport.notifyOnDataAvailable(true);
portIdentifier = CommPortIdentifier.getPortIdentifier(port); serialPort = (SerialPort) portIdentifier.open("openhab", 3000); serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.getInputStream())); outputStream = serialPort.getOutputStream(); Enumeration portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { CommPortIdentifier id = (CommPortIdentifier) portList
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); if (portIdentifier.isCurrentlyOwned()) { System.err.println("Error: Port " + portName + " is currently in use"); CommPort commPort = portIdentifier.open("BLED112", 2000); serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT); serialPort.setRTS(true);
@Override protected boolean connect() throws IOException { try { final CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(port); if(portIdentifier != null) { serialPort = (SerialPort) portIdentifier.open("org.openhab.binding.ebus", 2000); serialPort.setSerialPortParams(2400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); // set timeout 10 sec. serialPort.disableReceiveThreshold(); serialPort.enableReceiveTimeout(10000); // use event to let readByte wait until data is available, optimize cpu usage serialPort.addEventListener(this); serialPort.notifyOnDataAvailable(true); outputStream = serialPort.getOutputStream(); inputStream = serialPort.getInputStream(); return super.connect(); } } catch (NoSuchPortException e) { logger.error("Unable to connect to serial port {}", port); } catch (PortInUseException e) { logger.error("Serial port {} is already in use", port); } catch (UnsupportedCommOperationException e) { logger.error(e.toString(), e); } catch (TooManyListenersException e) { logger.error("Too many listeners error!", e); } serialPort = null; return false; }
void connect(String portName, SerialConfiguration conf) { registerPort(portName); try { CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); if (portIdentifier.isCurrentlyOwned()) { System.err.println("Error: Port " + portName + " is currently in use"); } else { CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000); if (commPort instanceof SerialPort) { serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); in = serialPort.getInputStream(); out = serialPort.getOutputStream(); serialPort.addEventListener(new SerialReader()); serialPort.notifyOnDataAvailable(true); } else { System.err.println("Error: Port " + portName + " is not a valid serial port."); } } } catch (Exception e) { e.printStackTrace(); } }
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers(); while (portIdentifiers.hasMoreElements()) { CommPortIdentifier id = (CommPortIdentifier) portIdentifiers.nextElement(); log.debug("Found port: {} x {}", id.getName(), id.getCurrentOwner()); port.setSerialPortParams(9600, SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); port.notifyOnDataAvailable(true); port.addEventListener(this);
commPort = CommPortIdentifier.getPortIdentifier(portName); commPort.addPortOwnershipListener(commPortOwnershipListener); LOGGER .info("Set flow control mode to SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT!"); serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT); serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE); serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.addEventListener(eventListener); serialPort.notifyOnCTS(true); serialPort.notifyOnCarrierDetect(true); serialPort.notifyOnBreakInterrupt(true); serialPort.notifyOnDSR(true); serialPort.notifyOnOverrunError(true); serialPort.notifyOnOutputEmpty(true); serialPort.setDTR(true); // pin 1 in DIN8; on main connector, this is DTR serialPort.notifyOnDataAvailable(true); serialPort.setRTS(true); fireCtsChanged(serialPort.isCTS());
@Override public void connect(String device) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException { CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(device); CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000); serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.enableReceiveThreshold(1); serialPort.disableReceiveTimeout(); in = serialPort.getInputStream(); out = serialPort.getOutputStream(); out.flush(); if (in.markSupported()) { in.reset(); } readerThread = new SerialReader(in); readerThread.start(); }
// change to right port CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyS0"); if (portIdentifier.isCurrentlyOwned()) { throw new RfidReaderUnavailableException(); } else { CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000); if (commPort instanceof SerialPort) { SerialPort serialPort = (SerialPort) commPort; // This details have to match your device configuration or it won't work serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT); in = serialPort.getInputStream(); out = serialPort.getOutputStream(); <-- Here you write the commands on out and read the responses from in --> } else { System.out.println("Error: Only serial ports are handled by this."); } }
/** * Disconnect the serial port connection to the Nikobus module. */ public void disconnect() { log.info("Closing Nikobus connection."); if (!isConnected()) { return; } lastEventTimestamp = 0; port.removeEventListener(); try { write(RS232_DISCONNECT); } catch (Exception e) { log.error("Could not send disconnect command", e); } if (port != null) { try { port.getInputStream().close(); port.getOutputStream().close(); } catch (IOException e) { log.error("Error closing port: {}", e.getMessage()); } port.close(); } }
Enumeration<?> e = CommPortIdentifier.getPortIdentifiers(); if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) { SerialPort sp = (SerialPort) id.open("SerialExample", 30); sp.setSerialPortParams(4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); InputStream is = sp.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader buf = new BufferedReader(isr); System.out.println("Scanning port " + sp.getName());
@Override public void open() throws IOException { if (port == null) { try { CommPortIdentifier identifier = findCommPortIdentifier(comPort); if (identifier == null) { throw new RuntimeException("ComPort not found: " + comPort); } port = (SerialPort)identifier.open(SerialPortNfcDevice.class.getName() + "." + comPort, TIMEOUT_FOR_OPEN); port.setInputBufferSize(SERIAL_PORT_BUFFER_SIZE); // initSerialPortEventListener(); log.trace(port + " BaudRate: " + port.getBaudRate() + ", InputBuffer: " + port.getInputBufferSize()); tweakPort(); inputOutputToken.setInputStream(port.getInputStream()); inputOutputToken.setOutputStream(port.getOutputStream()); speedNegotiator.negotiateBaudRateOnObject(port, baudRate); log.trace("Comport opened: " + port + " BaudRate: " + port.getBaudRate() + ", InputBuffer: " + port.getInputBufferSize()); } catch (PortInUseException e) { throw new IOException(e); } } }