Close Serial after Disconnect
Issue Identification:
Recommended Solution:
Java SDK Implementation:
Code Snippet Example:
try {
byte[] readBytes = new byte[256];
SerialPortOperationResult serialPortOperationResult = serialPortDevice.waitForRead(readBytes.length, TimeConstants.FOREVER);
int resultCode = serialPortOperationResult.getResultCode();
if (resultCode == SerialPortOperationResult.SUCCESS) {
byte[] data = serialPortOperationResult.getData();
Logger.debug("read success:" + new String(data));
} else if (resultCode == SerialPortOperationResult.LEVEL_3_HALTED) {
Logger.debug("devices is gone, please close it first, then open it again.");
serialPortDevice.close();
}
} catch (DeviceException e) {
e.printStackTrace();
}Last updated