24 lines
624 B
Python
24 lines
624 B
Python
import pprint
|
|
import time
|
|
|
|
import snap7
|
|
from snap7.util.getters import get_dint, get_lreal
|
|
|
|
LOOPS = 20
|
|
counter = 0
|
|
while counter < LOOPS:
|
|
try:
|
|
plc = snap7.client.Client()
|
|
plc.connect("172.16.3.231", 0, 2) # fagor 6
|
|
plc.connect("172.16.3.230", 0, 2) # fagor 5
|
|
# 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(3)
|