python snap7开发手册_python snap7 windows - can't find snap7 library

After some try and error experiments and with some infos of snap7 involved developers, i fixed the problem. The folder where the snap7.dll and .lib file are located must be present in the Enviroment variables of Windows. Alternative you can copy the files to the Python install dir if you have checked the "add path" option from the Python installer.

See the picture for Details: Edit Enviroment Vars

To give a good starting point for everyone who is a greenhorn like me here is a minimal snap7 tutorial to read variables of a DB from a S7 1212C PLC with Python3:

import snap7

from snap7.util import *

import struct

plc = snap7.client.Client()

plc.connect("10.112.115.10",0,1)

#---Read DB---

db = plc.db_read(1234,0,14)

real = struct.iter_unpack("!f",db[:12] )

print( "3 x Real Vars:", [f for f, in real] )

print( "3 x Bool Vars:", db[12]&1==1, db[12]&2==2, db[12]&4==4 )

plc.disconnect()

IP and Subnetmask

The IP of the PLC must be in the range of the subnetmask of the PC LAN Device. If the IP of the LAN device is 10.112.115.1 and the submask is 255.255.255.0 this give you a range of 10.112.115.2 to 10.112.115.255 for your PLC. Every PLC IP outside this range will give you a "Unreachable peer" Error.

Firewall

Make sure that your firewall allow the communication between your PC and PLC.

PLC Data Location

If you are unfamilar with STEP 7/ TIA Portal. Look for the "Online Diagnostics" Button and see the pictures to find the location of your data.

PLC Configuration

Beside a PLC program that uses the variables you want to read, the PLC need no additional parts to communicate with snap7. The services that are needed to communicate with snap7 are started by the firmware on power on.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值