# Siemens S7 Read

This function block facilitates communication with Siemens S7 PLCs (Programmable Logic Controllers) by reading various data types from specified data blocks within the PLC.

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

`Enable` A boolean input that allows enabling or disabling the reading operation from the PLC.

`S7 Client` A generic input representing the connection details required to communicate with the Siemens S7 device.

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

`Data` Provides the data read from the specified data block in the PLC, corresponding to the selected data type.

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

`DB Number` A textual input field where you specify the data block number from which to read.

`DB Byte Address` A textual input field to input the starting byte address within the data block.

`DB Data Type` A dropdown menu allowing you to select the type of data to read, such as Boolean, Int, DInt, Real, etc. Available types are predefined.

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

`Flexible Data Access` Users can read various data types from different data blocks within the PLC.

`Error Handling` Robust logging against potential read errors or connection issues provides real-time feedback.

`Dynamic Connection Management` Automatically reconnects to different PLC devices when the address changes.

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

1. **Enable Reading**: Set the `Enable` input to true to allow the block to initiate a read operation.
2. **Input Connection Details**: Connect the `S7 Client` input with the connection parameters of the Siemens PLC.
3. **Specify DB Number**: Specify the desired data block number using the `DB Number` input field.
4. **Set Byte Address**: Input the byte address to specify from which point in the block the data should be read.
5. **Select Data Type**: Choose the appropriate data type for reading from the dropdown menu.
6. **Run the Block**: When executed, the block will read data from the PLC based on the provided parameters and output the result.

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

The function block retrieves and displays the specified data from the Siemens S7 PLC when executed successfully.

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

<details>

<summary>Understanding Data Types</summary>

Ensure that the data type selected from the `DB Data Type` dropdown corresponds accurately with the data stored in the PLC. Mismatching types can lead to unexpected results or errors.

</details>

<details>

<summary>Checking Connection Status</summary>

If you experience issues reading data, confirm that the PLC is connected and accessible. Utilize the logging features to identify connection errors.

</details>

<details>

<summary>Efficiently Handling Busy Server States</summary>

If you encounter a "server busy" warning, consider implementing retry mechanisms or extending the read interval to allow the server time to process previous requests.

</details>

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

<details>

<summary>Server Not Connected</summary>

If the error message indicates the server is not connected, verify the connection settings passed through the `S7 Client` input. Ensure your PLC is powered and properly configured.

</details>

<details>

<summary>Invalid DB Number or Byte Address</summary>

Ensure that the DB Number and Byte Address provided are valid and exist in the PLC configuration. A wrong configuration will prevent data reading.

</details>
