# Siemens S7 Read

This function block reads values from a Siemens S7 PLC data block (DB). Use it to fetch numeric values, booleans, strings or other PLC data types and bring them into your scenario for monitoring, logging or decision logic.

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

`Enable` (Boolean) — When FALSE the block will skip reading and produce no output. Use this to control when reads occur.\
`S7 Client` (Generic) — PLC connection object provided by a connection block. Connect the client created by a PLC connection block here.

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

`Data` (Generic) — The value read from the PLC. The data type depends on the selection in the controls (number, list of booleans, text, etc.).

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

`DB Number` - Database (DB) number to read from on the PLC.\
`DB Byte Address` - Starting byte offset inside the selected DB.\
`DB Data Type` - Dropdown to select the expected PLC data type (examples: `Boolean`, `Int`, `Real`, `String`).\
`Connection Type` - Select `Sync` or `Async`. `Sync` keeps a shared connection mode suitable when multiple blocks use the same PLC bytes; `Async` gives the block its own connection behavior.

## ⚙️ How it works <a href="#how-it-works" id="how-it-works"></a>

* When active, the block uses the connected `S7 Client` to read bytes from the specified `DB Number` and `DB Byte Address`.
* The block interprets the raw PLC bytes according to the selected `DB Data Type` and returns a Python-friendly value via the `Data` output. For example, selecting `Boolean` may return a list of bit states, while `String` returns the decoded text.
* The `Enable` input allows you to stop reads without removing the configuration.
* The `Connection Type` influences sharing behavior: choose `Sync` when you want consistent, shared access across multiple blocks; choose `Async` for independent or isolated access.

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

* Simple UI to specify DB number, byte address and expected PLC data type.
* Supports many PLC types (booleans, signed/unsigned integers, reals, strings, time types, words/dwords, etc.).
* Configurable connection mode to match your deployment (shared vs independent).
* Error reporting in the UI when reads fail or if the provided parameters are out of range.

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

1. Provide a valid PLC connection to the `S7 Client` input (from a PLC connection block).
2. Enable the block by providing TRUE to the `Enable` input or leaving it enabled.
3. Set the target `DB Number` and `DB Byte Address`.
4. Choose the appropriate `DB Data Type` for the value you want to read.
5. Read values will appear on the `Data` output; connect downstream blocks to consume or log them.

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

* Trigger reads on demand: combine with `Logic Input` or a single-shot trigger like `Rising Edge` to perform reads only when needed (reduces bus load).
* Log and store values: send the `Data` output to `CSV Export` or `SQL-DB Operations` to build historical logs.
* Publish readings to external systems: connect `Data` to `MQTT Publish` to stream PLC values to a cloud or broker.
* Visualize trends: feed numeric outputs into `Scope` to monitor live values over time.
* Keep recent values available: use `Data Memory` to hold the last-read value and release updates only when desired.
* Handle missing values: use `Is None` and `Replace None` blocks to create safe fallback behavior if a read fails.
* Compose JSON payloads: feed values into `Data to JSON` before publishing or saving to simplify downstream parsing.
* Use `Connection Type` wisely: `Sync` is convenient when several blocks must read/write the same bytes; choose `Async` when you need isolated access or independent retries.

(hint) If you need a UI block that displays current values for operators, combine with display/output blocks like `Show Image` (for image-like data) or `Led Output` and simple text widgets for numeric indicators.

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

* No output appears: confirm the `Enable` input is TRUE and that a valid `S7 Client` is connected.
* Connection errors or timeouts: verify PLC network settings, check the connection block providing the `S7 Client`, and try switching `Connection Type` modes.
* Unexpected data format: ensure `DB Number`, `DB Byte Address` and `DB Data Type` match the PLC program layout. For strings, confirm the DB layout uses the same length/encoding.
* High bus load: reduce read frequency, use triggered reads (`Rising Edge`) or share a connection with `Sync` mode where appropriate.


---

# Agent Instructions: 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:

```
GET https://docs.augelab.com/function-blocks/input-output/communication/siemens-s7-read.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
