Python OPC UA client communication with Siemens PLC TIA Portal

2 min read 1 year ago
Published on May 03, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Step-by-Step Tutorial: Communicating with Siemens PLC TIA Portal using Python OPC UA Client

  1. Connect to Virtual PLC using PLC Sim Advanced:

    • Open PLC Sim Advanced and define a CPU 1513 PLC.
    • Create a server on the PLC side by clicking the corresponding box and selecting the PLC Sim virtual Ethernet adapter in the settings.
  2. Download Necessary Software:

    • Download the OPC UA client for Python. The commands to install the required packages are:
      pip install opcua
      pip install python-opcua
      
  3. Connect to the PLC using OPC UA Client for Python:

    • Launch the OPC UA client for Python.
    • Enter the corresponding IP address and port of the server (found in PLC settings).
    • Click "Connect" to establish a connection.
  4. Modify Values using Python OPC UA Client:

    • Create functions to read input values, write integer values, and write boolean values.
    • Use the functions to interact with the PLC data
      • Read the current values.
      • Modify values as needed.
  5. Manipulate Values with Python:

    • Use the Python OPC UA client to change parameters and values in the PLC
      • Change boolean values (e.g., from false to true).
      • Update integer values (e.g., increase the number of sold Nintendo switches).
  6. Handle Value Accessibility Changes:

    • Be aware that changes in value accessibility can impact communication.
    • Untick the values that are no longer accessible to avoid issues.
  7. Troubleshooting and Reconnecting:

    • If values are not accessible, reconnect to the server after making necessary adjustments.
    • Ensure that the values you are trying to access are still available in the server address space.
  8. Final Checks and Reinitialization:

    • Verify that the values have been updated successfully.
    • Reinitialize the server if needed to ensure proper communication.
  9. Conclusion:

    • By following these steps, you can effectively communicate with a Siemens PLC in TIA Portal using a Python OPC UA client.
    • Experiment with different values and functions to understand the communication process better.

This tutorial provides a comprehensive guide on setting up the communication between Python OPC UA client and Siemens PLC TIA Portal. Feel free to reach out if you have any questions or need further assistance.