import time import snap7 import pprint LOOPS = 5 counter = 0 while counter < LOOPS: try: plc = snap7.client.Client() plc.connect("172.16.3.231", 0, 1) pprint.pprint(plc.get_cpu_state()) except Exception as e: pprint.pprint(e) finally: plc.disconnect() counter += 1 time.sleep(1)