How to Manage Serial Port Disconnections in Application Development: Difference between revisions

From wizarPOS
No edit summary
(Replaced content with "{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/close-serial-after-disconnect}}")
Tag: Replaced
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/close-serial-after-disconnect}}
  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:
<syntaxhighlight lang="java">
        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();
        }
</syntaxhighlight >

Latest revision as of 08:26, 7 April 2024

Please visit new link of same subject:

https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/close-serial-after-disconnect

We're making a move! Our site's content is migrating to a new URL, to provide you with an enhanced browsing experience. Please update your bookmarks accordingly. Thank you for your continuous support!