pys7 program test
This commit is contained in:
parent
248c41b986
commit
a2d6cf2f9a
30
pyS7_test.py
Normal file
30
pyS7_test.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user