How to Manage Serial Port Connections During Terminal Sleep Mode: Difference between revisions

From wizarPOS
(Created page with "When the temrinal enter the sleep mode, it will disconnect the power of the usb, which will make the connection broken. At that time, any serial port function can not work,...")
 
No edit summary
Line 8: Line 8:
'''Here is the code about how to monitor the screen on/off:'''
'''Here is the code about how to monitor the screen on/off:'''
<syntaxhighlight lang="java" line='line'>
<syntaxhighlight lang="java" line='line'>
ntentFilter filter = new IntentFilter();
intentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_OFF);

Revision as of 03:01, 17 December 2021

When the temrinal enter the sleep mode, it will disconnect the power of the usb, which will make the connection broken.

At that time, any serial port function can not work, even after the terminal restore from sleep mode, wake up.

So the serial port should be closed before enter sleep mode. Then open the serial port any time after wakeup, the serial port should work fine.


Here is the code about how to monitor the screen on/off:

intentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(receiver, filter);

when receive screen off, close the serial port.