How to Manage Serial Port Disconnections in Application Development

From wizarPOS
Revision as of 02:53, 6 June 2022 by Mahong (talk | contribs) (Created page with " When app read from serial port, if occurs the error message: "Level 3 halted" in the log, that means the serial port cable is disconnected, then close the serial port in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 When app read from serial port, if occurs the error message: "Level 3 halted" in the log, that means the serial port cable is disconnected, then close the serial port in the app, then try to open it again. If app can not open serial port, please try to connect the serial port cable again.
 In Java SDK, you can catch the DeviceException when do serail port read, snippet code:
try{
  ....
  serialportDevice.read(...);
  ....
}catch(DeviceException e){
  If (e.getMessage.contains("Level 3 halted")){
    serialportDevice.close();
    // then open serial port in somewhere, depends on your app logic.
  }
}