> For the complete documentation index, see [llms.txt](https://smartpossdk.gitbook.io/cloudpossdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/reopen-serial-after-wake-up.md).

# ReOpen Serial after Wake-up

### Issue Overview:

In scenarios where the terminal enters sleep mode, the power to the USB is disconnected. This disruption leads to the breaking of existing connections and renders the serial port functions inoperative, even after the terminal wakes up from sleep mode.

### Recommended Approach:

1. Proactive Management of Serial Port:
   * It is crucial to close the serial port before the terminal enters sleep mode. This proactive step helps in avoiding connection issues.
2. Re-establishing Connection After Wake-up:
   * After the terminal wakes up from sleep mode, open the serial port again. Doing so should restore the serial port's functionality without any issues.

### Code Implementation for Screen On/Off Monitoring:

* Handling Screen Off Event:
  * Implement code to monitor the screen's on/off status.
  * When a 'screen off' event is detected, ensure that the serial port is closed.

### Example Code Snippet:

{% code overflow="wrap" lineNumbers="true" %}

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

{% endcode %}

This process is essential to maintain the integrity of the serial port functionality and ensure continuous operation post wake-up.

{% hint style="info" %}
Note: The mechanism for handling serial ports after wake-up from sleep is applicable only to USB serial ports. It does not apply to extended serial ports, which do not disconnect.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://smartpossdk.gitbook.io/cloudpossdk/faq/usb-serial-port/reopen-serial-after-wake-up.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
