Snap7-python Windows 7 64 bit

832 views Asked by At

I try to install snap7 to communicate with s7-1200. I downloaded latest package (1.4.1) I cannot find dll that specified for 64 bit windows OS. I used pip3 command to install it and everything was fine.

I wrote this simple code with PyQt5 and snap7 library:

# -*- 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_())

When i added plc = c.Client() and another snippets that contains "plc" i am getting this error : Traceback (most recent call last):

 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

Do you have any solution or way to eliminate this? I cannot understand the point or points that i missed.

Regards.

0

There are 0 answers