We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Non-blocking reading is the default mode used by this library. It can be selected simply by opening the COM port with no other options:
SerialPort comPort = SerialPort.getCommPorts()[0]; comPort.openPort(); try { while (true) { while (comPort.bytesAvailable() == 0) Thread.sleep(20); byte[] readBuffer = new byte[comPort.bytesAvailable()]; int numRead = comPort.readBytes(readBuffer, readBuffer.length); System.out.println("Read " + numRead + " bytes."); } } catch (Exception e) { e.printStackTrace(); } comPort.closePort();
If you were already in a different mode of operation, you can enable non-blocking/polling mode by calling the following method at any point in time:
comPort.setComPortTimeouts(SerialPort.TIMEOUT_NONBLOCKING, 0, 0);