import time from pyS7 import S7Client import pprint LOOPS = 3 counter = 0 client = S7Client(address="172.16.3.231", rack=0, slot=2) while counter < LOOPS: try: # Create a new 'S7Client' object to connect to S7-300/400/1200/1500 PLC. # Provide the PLC's IP address and slot/rack information # client = S7Client(address="172.16.4.220", rack=0, slot=2) # Establish connection with the PLC client.connect() # Define area tags to read tags = ["DB9,DBD0"] # Read the data from the PLC using the specified tag list data = client.read(tags=tags) print(data) # [True, False, 123, True, 10, -2.54943805634653e-12, 'Hello'] except Exception as e: pprint.pprint(e) finally: client.disconnect() counter += 1 time.sleep(1)