Snap7-Python Windows 7 64位

时间:2018-11-10 16:17:35

标签: python-3.x windows-7-x64 snap7

我尝试安装snap7与s7-1200通信。我下载了最新的软件包(1.4.1),但找不到为64位Windows OS指定的dll。我用pip3命令安装了它,一切都很好。

我用PyQt5和snap7库编写了以下简单代码:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'f.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets
import snap7 as c
from snap7.util import *
from snap7.snap7types import *

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(280, 230, 75, 71))
        self.pushButton.setObjectName("pushButton")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "PushButton"))


if __name__ == "__main__":
    import sys
    plc = c.client.Client()
    plc.connect('192.168.137.100',0,1)
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

当我添加plc = c.Client()和另一个包含“ plc”的代码段时,出现此错误: 追溯(最近一次通话):

 File "C:\Python\Lib\site-packages\snap7\f.py", line 43, in <module>
    plc = c.client.Client()
  File "C:\Python\lib\site-packages\snap7\client.py", line 37, in __init__
    self.library = load_library()
  File "C:\Python\lib\site-packages\snap7\common.py", line 54, in load_library
    return Snap7Library(lib_location).cdll
  File "C:\Python\lib\site-packages\snap7\common.py", line 47, in __init__
    self.cdll = cdll.LoadLibrary(self.lib_location)
  File "C:\Python\lib\ctypes\__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

您有什么解决方案或方法可以消除这种情况吗?我无法理解我错过的一点。

致谢。

0 个答案:

没有答案