1

我尝试安装 snap7 与 s7-1200 通信。我下载了最新的软件包 (1.4.1) 我找不到为 64 位 Windows 操作系统指定的 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”的片段时,我收到此错误:Traceback(最近一次通话最后一次):

 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

您有任何解决方案或方法来消除这种情况吗?我无法理解我错过的一个或多个点。

问候。

4

0 回答 0