python-snap7安装各种报错
生活随笔
收集整理的這篇文章主要介紹了
python-snap7安装各种报错
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
python-snap7安裝各種報錯
準備:win10 64位專業(yè) 、pycharm 、snap7-full-1.4.2
- **python-snap7安裝各種報錯**
- 錯誤一、snap7.snap7exceptions.Snap7Exception: can't fintd snap7 library. If installed, try running ldconfig
- 錯誤二、OSError: [WinError 193] %1 不是有效的 Win32 應用程序。
- 第一步:pycharm中安裝python-snap7
- 第二步:復制snap7-full-1.4.2文件路徑:snap7-full-1.4.2\snap7-full-1.4.2\release\Windows\Win64 下的snap7.dll和snap7.lib,放入C:\Windows\SysWOW64路徑和G:\Python\Python38(你的python安裝路徑)
錯誤一、snap7.snap7exceptions.Snap7Exception: can’t fintd snap7 library. If installed, try running ldconfig
錯誤二、OSError: [WinError 193] %1 不是有效的 Win32 應用程序。
第一步:pycharm中安裝python-snap7
第二步:復制snap7-full-1.4.2文件路徑:snap7-full-1.4.2\snap7-full-1.4.2\release\Windows\Win64 下的snap7.dll和snap7.lib,放入C:\Windows\SysWOW64路徑和G:\Python\Python38(你的python安裝路徑)
讀取s7 200smartPLC 輸出區(qū)(Q)數(shù)據(jù)的代碼示例:
from time import sleepimport snap7 from snap7.exceptions import Snap7Exception''' 其中address是服務器的IP地址,如果使用NetToPLCsim連接PLCsim,則IP地址應該是計算機的IP地址,rack和slot和NetToPLCsim設置的一樣,針對S7-1200此處應該是0和1,端口默認是102,不需要進行更改連接后可以通過get_connected檢查連接是否建立,返回值如果是True,則代表連接成功連接建立后,通過read_area方法獲取PLC各個區(qū)的數(shù)值 '''def connect(device, ip, rack, slot):while True:if device.get_connected():breaktry:device.connect(ip, rack, slot)except:passsleep(1)def ReadOutput(dev):data = dev.read_area(0x82, 0, 0, 1)binary_list = [int(x) for x in bin(data[0])[2:]]print(binary_list)def main():s71200 = snap7.client.Client()connect(s71200, '192.168.2.1', 0, 1)while True:try:ReadOutput(s71200)sleep(1)except Snap7Exception as e:connect(s71200, '192.168.2.1', 0, 1)if __name__ == '__main__':main()參考博文: https://blog.csdn.net/lcb411/article/details/101936678
總結
以上是生活随笔為你收集整理的python-snap7安装各种报错的全部內容,希望文章能夠幫你解決所遇到的問題。