22 lines
561 B
Python
22 lines
561 B
Python
import time
|
|
import snap7
|
|
from snap7.util.getters import get_lreal, get_dint
|
|
import pprint
|
|
|
|
LOOPS = 20
|
|
counter = 0
|
|
while counter < LOOPS:
|
|
try:
|
|
plc = snap7.client.Client()
|
|
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(3)
|