diff --git a/pyS7_test.py b/pyS7_test.py index e36cb70..c813cd4 100644 --- a/pyS7_test.py +++ b/pyS7_test.py @@ -2,21 +2,20 @@ import time from pyS7 import S7Client import pprint -LOOPS = 5 +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.3.231", rack=0, slot=1) + # 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", - ] + tags = ["DB9,DBD0"] # Read the data from the PLC using the specified tag list data = client.read(tags=tags) diff --git a/snap7_test.py b/snap7_test.py index ee25ff0..15a9d1b 100644 --- a/snap7_test.py +++ b/snap7_test.py @@ -1,17 +1,21 @@ import time import snap7 +from snap7.util.getters import get_lreal, get_dint import pprint -LOOPS = 5 +LOOPS = 20 counter = 0 while counter < LOOPS: try: plc = snap7.client.Client() - plc.connect("172.16.3.231", 0, 1) - pprint.pprint(plc.get_cpu_state()) + plc.connect("172.16.3.231", 0, 2) + # pprint.pprint(plc.get_cpu_state()) + data = plc.db_read(9, 0, 4) # Define range of bytes to read + energy_value = get_dint(data, 0) # Read energy value + pprint.pprint(energy_value) except Exception as e: pprint.pprint(e) finally: plc.disconnect() counter += 1 - time.sleep(1) + time.sleep(3)