You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am finding that a configured read timeout is not respected when communicating with an ESP32 device. The code is fairly straightforward:
serialPort.openPort();
serialPort.setComPortParameters(115200, 8, 1, 0);
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 500, 1000);
serialPort.clearRTS();
serialPort.clearDTR();
//write to port, then wait for response as follows:
InputStream in = serialPort.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] readBuffer = new byte[64];
int numBytes;
while(true) {
long time = System.currentTimeMillis();
try {
while((numBytes = in.read(readBuffer)) != -1) {
if(numBytes > 0) {
baos.write(readBuffer, 0, numBytes);
}
}
} catch(SerialPortTimeoutException e) {
System.out.println("Timed out after " + (System.currentTimeMillis() - time) + " ms");
}
}
This results in the following output:
Timed out after 578 ms true
Timed out after 609 ms true
Timed out after 502 ms true
Timed out after 502 ms true
Timed out after 501 ms true
Timed out after 502 ms true
Timed out after 501 ms true
Timed out after 501 ms true
Timed out after 277 ms
Timed out after 0 ms
Timed out after 0 ms
Timed out after 0 ms
Timed out after 0 ms
Timed out after 0 ms
<repeated endlessly until the ESP32 sends data>
The text was updated successfully, but these errors were encountered:
Update: This issue appears to be caused by the nature of the USB connection. I was able to avoid it by connecting directly rather than through a USB hub, although it's still a mystery why this would cause immediate read timeouts.
I am finding that a configured read timeout is not respected when communicating with an ESP32 device. The code is fairly straightforward:
This results in the following output:
The text was updated successfully, but these errors were encountered: