> 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-connect.md).

# Serial Connect

This function block opens and manages a serial (COM) connection. Use it to connect to serial devices, monitor connection state, and expose a connection identifier for other blocks to reference.

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

This function block does not have any inputs.

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

`ConnId` Unique identifier for the opened serial connection. Use this value to reference the connection from other blocks.

`Connected?` Boolean flag that indicates whether the serial connection is currently active.

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

`Port` COM port name to connect to (for example COM3).

`Baud` Communication speed (for example 115200).

`Read timeout (s)` Time in seconds to wait for read operations.

`Line delimiter` Select the line ending used by your device (LF / CRLF / CR).

`AutoReconnect` Switch that enables automatic reconnection when the connection drops.

`Reconnect interval (s)` Interval between reconnection attempts when auto-reconnect is enabled.

`Idle disconnect (s)` Time of inactivity after which the connection will be closed automatically to free the port.

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

* Automatic connection management: opens a connection with the configured parameters and keeps the `ConnId` available to other blocks.
* Auto-reconnect: optionally retries when the device becomes unavailable.
* Idle disconnect: closes the port when unused to avoid locking the device for other applications.
* Human-readable settings: select newline convention and tune timeouts to match the connected device.

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

1. Set the `Port` and `Baud` values to match your device.
2. Configure `Read timeout (s)` and `Line delimiter` according to your device protocol.
3. Toggle `AutoReconnect` and set `Reconnect interval (s)` if you want the block to recover from disconnections automatically.
4. Adjust `Idle disconnect (s)` to let the block close the port when not in use.
5. Run the scenario. The block will open the connection and output `ConnId` and `Connected?`. Use the `ConnId` in other communication blocks that accept a connection reference.

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

When evaluated, the block ensures a serial connection exists with the current settings. If settings change, the previous connection is released and a new one is created. The outputs reflect the active connection id and whether the connection is currently established.

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

* Use `Led Output` to visually reflect the `Connected?` state in your UI.
* Use `String Input` or `Number Input` and `String Merge` to craft commands to send over the serial link.
* Use `Data Write Global` / `Data Read Global` to share the `ConnId` or serial results with other parts of your scenario without direct wiring.
* Feed serial data into `Data to JSON` or `CSV Export` to log communication for later analysis.
* Forward parsed data to remote systems with `MQTT Publish` or `REST API - Post` for cloud integration or monitoring.
* Use `Debug Input` to inspect messages while developing your serial workflow.
* Combine with `Send Mail` to trigger email alerts when connection drops or when specific messages arrive.

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

* If `Connected?` remains false: verify the device port and baud settings match the device; check device drivers and OS device manager.
* If you cannot open the port: make sure no other application is using the same COM port. Close other programs or enable idle disconnect in those systems.
* If lines appear truncated or merged: try a different `Line delimiter` setting or increase `Read timeout (s)`.
* If frequent disconnects occur: enable `AutoReconnect` and increase `Reconnect interval (s)` to give the device time to recover.
* If unexpected characters appear: confirm baud rate and parity settings with the device documentation and adjust accordingly.
