> 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/twincat-read.md).

# TwinCAT Read

This function block reads a variable from a TwinCAT PLC and outputs the retrieved value along with a success indicator. It is intended for simple PLC data retrieval in automation scenarios.

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

`Connection` — Generic PLC connection object (provide using a connect block such as `TwinCAT Connect`).

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

`Data` — Retrieved variable value from the PLC.

`Success` — Boolean flag indicating whether the read operation succeeded.

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

`Variable Name` — Text field where you enter the PLC variable name to read. This value must match the variable identifier defined in the PLC.

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

* Simple PLC read operation with clear success feedback.
* Designed to accept a connection from a separate connection block, keeping connection management separated from reads.
* Validates key inputs and reports clear error messages when connection or variable name is missing.

## 📝 How to use <a href="#usage" id="usage"></a>

1. Provide a PLC connection to the `Connection` input. The typical way is to use the `TwinCAT Connect` block and connect its output to this block.
2. Enter the target PLC variable into the `Variable Name` control.
3. Trigger evaluation (manually or from flow controls). The block will attempt to read the named variable and output `Data` and `Success`.
4. Use the `Success` output to gate downstream logic (e.g., logging or storage) so you only act on valid reads.

## 📊 Runtime behavior <a href="#evaluation" id="evaluation"></a>

When evaluated, the block checks that a valid `Connection` is present and that `Variable Name` is not empty. If either is missing it reports an error and outputs a failed `Success`. On a valid configuration it performs a read and outputs the variable value on `Data` and a boolean on `Success`.

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

* Use `TwinCAT Connect` to create and manage the PLC connection and feed it into `Connection`.
* Combine with `Rising Edge` or `Cycle Timer` to control read frequency (e.g., read once on start or periodically).
* Send successful reads to `CSV Export` or `Data to JSON` to log values for later analysis.
* Use `Debug Input` or `Scope` to inspect values while you build and test your system.
* To write values back to the PLC, pair this block with `TwinCAT Write` and use logic blocks (for example `Logic Input` or `Set - Reset`) to control when reads/writes happen.
* Use `Data Write Local` or `Data Write Global` to store values for other parts of your scenario.

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

* If you see "Connection is not established" errors, verify the connection block (for example `TwinCAT Connect`) is configured and connected.
* If `Variable Name` is empty, the block will not attempt a read — enter a valid PLC variable identifier.
* If a read fails despite valid inputs, check PLC access rights, variable name spelling, and network/PLC status. Use `Debug Input` to capture the raw response and the `Success` output to branch error handling.
* If you need periodic stability, control reads with timing blocks like `Cycle Timer` and add simple retry logic using logic blocks.
