python-snap7使⽤说明
1.⾸先从官⽹下载完整包,解压后从\snap7-full-1.4.2\snap7-full-1.4.2\release\Windows\Win64⽂件夹把snap7.dll⽂件和snap7.lib⽂件拷⼊已经注册环境变量Path的路径,可以是⽂件或库的路径。
2.安装python-snap7
3.安装完毕后,先导⼊库,常见的有
import snap7
pes import *
python默认安装路径from snap7.util import *
4.完整程序如下:
import snap7
pes import *
from snap7.util import *
plc = snap7.client.Client()
# In this example boolean in DB 31 at byte 120 and bit 5 is changed. = 120.5
reading = plc.db_read(31, 120, 1)    # read 1 byte from db 31 staring from byte 120
snap7.util.set_bool(reading, 0, 5)  # set a value of fifth bit
plc.db_write(reading, 31, 120, 1)    # write back the bytearray and now the boolean value is changed
#  in the PLC.
# NOTE you could also use the read_area and write_area fu

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。