> For the complete documentation index, see [llms.txt](https://docs.augelab.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.augelab.com/function-blocks/blocks-reference/input-output/communication/serial-read.md).

# Serial Read

This function block reads the latest line from a serial connection (non-blocking) and converts it to a chosen data type. It is designed to be resilient to stale or malformed input by returning a user-defined default when needed.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

* `Enable` Boolean input socket that enables or disables reading.
* `ConnId` Generic input socket that selects which serial connection to read from (connection identifier).

## 📤 Outputs <a href="#outputs" id="outputs"></a>

* `Data` Generic output socket that emits the latest converted value (or the default value when stale/failed).

## 🕹️ Controls <a href="#controls" id="controls"></a>

* `Stale timeout (s)` Text input that sets how long to wait for a new line before treating the reading as stale.
* `Data Type` Dropdown to choose the conversion type for incoming lines. Available options: `String`, `Int`, `Float`, `Boolean`, `HexInt`, `Bytes`.
* `Default (on stale/parse fail)` Text input that provides the fallback value returned when no fresh data is available or conversion fails. For `Bytes` enter hex characters (e.g., `AA55`).

## 🎯 Features <a href="#features" id="features"></a>

* Non-blocking read of the latest available line.
* Stale detection so old lines are not forwarded indefinitely.
* Multiple conversion types with a configurable fallback value.
* Simple inputs and outputs to integrate into larger scenarios.

## 📝 Usage <a href="#usage" id="usage"></a>

1. Provide a connection identifier to `ConnId` that refers to an active serial connection.
2. Use `Enable` to start or stop reading without removing the block.
3. Set `Stale timeout (s)` to define how fresh the incoming data must be.
4. Choose the desired `Data Type` to convert incoming lines.
5. Define `Default (on stale/parse fail)` to control what the block outputs when there is no fresh or parseable data.
6. Consume the output from `Data` in subsequent blocks for logging, visualization, or publishing.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

* When enabled, the block attempts to read the latest line from the selected connection.
* If no new line arrives within the configured stale timeout, the block emits the configured default.
* If conversion to the selected data type fails, the block emits the configured default.
* For `Bytes` type, the block treats the default as hexadecimal text.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* Use `Debug Input` to log or inspect raw results during development.
* Forward serial readings to `Data to JSON` or `CSV Export` for structured logging or batch export.
* Publish processed values with `MQTT Publish` or send them to a web service using `REST API - Post`.
* Store values for later use with `Data Write Local` or `Data Write Global` and retrieve them with the corresponding read blocks.
* Plot numeric data in real time using `Scope` to observe trends or anomalies.
* Combine with `Logic Input` or comparison blocks to trigger actions based on incoming values (for example, alarm when a numeric reading exceeds a threshold).

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* If no data appears on `Data`, verify the provided `ConnId` refers to an active connection.
* If output is always the default, increase `Stale timeout (s)` or ensure the source is actively sending lines.
* If conversion fails for a numeric or boolean type, check the raw text format from the device and adjust the default accordingly.
* For `Bytes` type, ensure the default is provided as valid hexadecimal characters (no spaces or non-hex chars).
