使用其中的python3.7 32位
下载snap7 1.4.2 版本解压
在win 环境变量里添加path snap7的release里win32路径
通过github 下离线包
GitHub - gijzelaerr/python-snap7: A Python wrapper for the snap7 PLC communication library
pip setup.py install 安装
pc为客户端向plc发送 请求操作获取信息
import snap7 client = snap7.client.Client()
client.set_connection_type(3) (200 必须用)
client.connect("192.168.0.1", 0, 0) # ip地址, rack,slot(根据plc板的硬件配置填写 rack slot) 200 为 rack0 slot1 buffer = client.db_read(1, 10, 4) # reads the db number 1 starting from ˓→the byte 10 until byte 14. v区是register必须为1
data.db_write(1, 0, data)
db_read(db_number: int, start: int, size: int) → bytearray Reads a part of a DB from a PLC
client.disconnect()