A powerful plugin to connect Siemens S7 PLCs with the Godot Engine, enabling real-time industrial automation and visualization.
Features
- Connect to Siemens S7 PLCs (S7-300, S7-400, S7-1200, S7-1500)
- Read and write PLC variables directly from Godot
- Support for multiple data types: Bool, Byte, Int, DInt, Real, LReal, String, etc.
- Data grouping for efficient batch operations
- Visual binding: Link PLC variables to Godot UI components and properties
- Robust error handling and automatic reconnection logic
- Extensible: Easily add new variable types and behaviors
]
VarTypes and DataItems Explained
VarTypes define the type of PLC variable you wish to read or write (e.g., Bit, Int, Real). In this plugin, each variable you interact with is represented by a DataItem node, which you configure with the appropriate VarType, memory area, address, and access mode.
Supported VarTypes:
VarType | Description |
---|---|
Bit | Single boolean bit |
Byte | 8-bit unsigned integer |
Word | 16-bit unsigned integer |
DWord | 32-bit unsigned integer |
Int | 16-bit signed integer |
DInt | 32-bit signed integer |
Real | 32-bit floating-point number |
LReal | 64-bit floating-point number |
String | Character string |
DataItem Properties:
Property | Description |
---|---|
DataType | PLC memory area (Memory, DataBlock, Input, Output) |
VarType | Variable type (see above) |
DB | DataBlock number (0 for main memory, or specific DB) |
StartByte Adr | Starting byte address |
Bit Adr | Bit address (for Bit VarType) |
Count | Number of variables to read/write |
Mode | "ReadFromPlc" or "WriteToPlc" |
Installation
- Copy the
siemens_plugin
folder into your project'saddons
directory. - Enable the plugin in Project > Project Settings > Plugins.
- Ensure your project targets Godot 4.x and has .NET support enabled.
- Build the project.
- Reload your project.
Quick Start
- Add a S7_1500 escene to your scene (
Plc
). - Configure the PLC's IP, CPU model, rack, and slot.
- Add GroupData nodes as children of the PLC Node.
- Add Data Items (e.g.,
BoolItem
,IntItem
) as children of the GroupData Node. - Use the provided scripts to read/write variables or bind them to UI components.
Example Scenes
You can use these example scenes as a guide to create your own demos and documentation for the plugin. Each example includes a brief description, step-by-step instructions, and suggestions for visual integration.
1. Basic Connection to a Siemens PLC
Description: A simple scene allowing you to configure the PLC's IP address, CPU type, rack, and slot, then connect or disconnect and view the connection status.
Features:
- Input fields for IP, rack, and slot.
- Dropdown for CPU type selection.
- Button to connect/disconnect from the PLC.
- Label or indicator showing the current connection status.
Instructions (as shown in a Label3D in the scene):
- Add Plc scene to tree.
- Enter the PLC's IP address.
- Select the CPU type.
- Set rack and slot.
- Click the Connect button.
- Check the connection status.
2. Reading a Boolean Variable
Description: A scene with a visual switch (checkbox or button) that reflects the state of a boolean variable in the PLC.
Features:
- Periodically reads a boolean variable from the PLC.
- Updates the visual component in Godot to match the PLC value.
Instructions:
- Configure the Plc node as shown in the previous example.
- Add a GroupData node as a child of the Plc node.
- Add a BoolItem as a child of the GroupData node.
- Set the DataType to "Memory" to read a bit from the PLC.
- Set the VarType to "Bit".
- Set DB to 0 if it is in the Main DB, or to the number of the DB where the boolean is stored.
- Set the StartByte Adr and Bit Adr according to the address of the bit in the PLC.
- Set Count to 1.
- Set Mode to "ReadFromPlc".
- Click the "Online" button.
- Run the current scene.
- Select "BoolItem".
- View the value in the "Gd Value" property.
3. Writing Numeric Variables
Description: A scene with numeric input fields for writing integer and floating-point values (Int, DInt, Real, LReal) to the PLC.
Features:
- Demonstrates mapping of different data types.
- Real-time updates between Godot and the PLC.
Instructions:
- Configure the Plc node as shown in the previous example.
- Add a GroupData node as a child of the Plc node.
- Add an IntItem, RealItem, and LRealItem as children of the GroupData node.
- Set the DataType to "Memory" to write to the PLC.
- Set VarType to "Int", "Real", or "LReal" depending on the item.
- Set DB to 0 if it is in the Main DB, or to the number of the DB where the variable is stored.
- Set the StartByte Adr and Bit Adr according to the address in the PLC.
- Set Count to 1.
- Set Mode to "WriteFromPlc".
- Click the "Online" button.
- Run the current scene.
- Select "IntItem", "RealItem", or "LRealItem" and change the "GdValue".
- View the value changing in TIA Portal.
4. Advanced Visual Integration
Description: An example showing how to bind PLC variables to advanced visual properties, such as colors or animations.
Features:
- Dynamic UI driven by PLC data.
- Integration with Godot's visual and animation systems.
Instructions:
- Configure the Plc node as shown in the previous example.
- Add a GroupData node as a child of the Plc node.
- Add a BoolItem as a child of the GroupData node.
- Set the DataType to "Memory" to write a bit from Godot to the PLC.
- Set the VarType to "Bit".
- Set DB to 0 if it is in the Main DB, or to the number of the DB where the boolean is stored.
- Set the StartByte Adr and Bit Adr according to the address in the PLC.
- Set Count to 1.
- Set Mode to "WriteToPlc".
- Select BoolItem.
- Drag and drop your visual component (e.g., "CSGCylinder3D") to the "Visual Component" property in the inspector.
- Select the property to bind (e.g., "on_blocked") in the "Visual Property" field.
- Click the "Online" button.
- Run the current scene.
- The "on_blocked" property will write to memory (e.g., M0.0) in the PLC.
- View the value changing in TIA Portal.
Reference
- Plc: Main node for PLC connection and communication.
- GroupData: Manages groups of variables for efficient batch operations.
- DataItem: Base class for all variable types.
- BoolItem, IntItem, DIntItem, RealItem, LRealItem, etc.: Specialized variable nodes for each supported VarType.
Troubleshooting
- Ensure your PLC is reachable from your network.
- Check firewall settings and PLC configuration.
- In TIA Portal, allow access with PUT/GET communication from remote partners.
- Use the Godot output console for error messages.
Contributing
Pull requests and suggestions are welcome! Please open an issue for bugs or feature requests.
License
MIT License.
Credits
- S7NetPlus library for PLC communication.
- Godot Engine community.
Contact
For questions or support, open an issue or contact the maintainer: Álex Pérez, CTO at Wepall alex.perez@wepall.com