pys7 program test

This commit is contained in:
Igor Barcik 2024-12-11 07:26:56 +01:00
parent 248c41b986
commit a2d6cf2f9a
Signed by: biggy
GPG Key ID: EA4CE0D1E2A6DC98

30
pyS7_test.py Normal file
View File

@ -0,0 +1,30 @@
import time
from pyS7 import S7Client
import pprint
LOOPS = 5
counter = 0
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)
# 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)