Giter Club home page Giter Club logo

Comments (17)

gijzelaerr avatar gijzelaerr commented on August 26, 2024

It looks like that error can't come from the code you copy pasted. Also I get the idea are not really familiar with Python since you try to override the existing client code? I think it is wise to maybe follow some python tutorials.

Try something like this:

import snap 7
client = snap7.client.Client()
client.connect('192.168.5.2', 0, 1)
db_number = 109
start = 0
data = ff
client.db_write(self, db_number, start, data)

hope that gets you a bit further.

from python-snap7.

Youandi12 avatar Youandi12 commented on August 26, 2024

We have run your program and have the same problems
We don't know what the attributeError is or how we can solve that.

Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "copyright", "credits" or "license()" for more information.

================================ RESTART ================================

Traceback (most recent call last):
File "/home/pi/testcom3.py", line 2, in
client = snap7.client.Client()
File "/usr/local/lib/python2.7/dist-packages/snap7/client.py", line 36, in init
self.create()
File "/usr/local/lib/python2.7/dist-packages/snap7/client.py", line 43, in create
self.library.Cli_Create.restype = c_void_p
AttributeError: 'NoneType' object has no attribute 'Cli_Create'

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

you don't get an other error about snap7 library not found? How did you install snap7? Did you modify the python-snap7 source code?

from python-snap7.

Youandi12 avatar Youandi12 commented on August 26, 2024

These are the only errors we get. Normally the snap7 library is ok.
We have installed the snap7 library with:
$ p7zip -d snap7-full-1.0.0.7z
$ cd build/unix
$ make -f arm_v7_linux.mk
pip install python-snap7

We didn't modify anything in the source code.

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

what happens if you run

from ctypes.util import find_library
print find_library('snap7')

in a python console or script?

from python-snap7.

Youandi12 avatar Youandi12 commented on August 26, 2024

we got this:

libsnap7.so

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

And what does this give you:

from ctypes import cdll
from ctypes.util import find_library
print cdll.LoadLibrary(find_library('snap7'))

from python-snap7.

Youandi12 avatar Youandi12 commented on August 26, 2024

<CDLL 'libsnap7.so', handle 5de320 at 756d0ff0>

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

are you sure you didn't modify the client code? This should just work... try uninstalling python-snap7 and reinstalling from pip.

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

hm you might have spotted a bug actually.

https://github.com/gijzelaerr/python-snap7/blob/master/snap7/common.py#L42

are you running this in an interactive terminal? it looks like if you called the find_library function before it will return None. Can you restart the interpreter?

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

nah that doesn't seem the case.... hm

from python-snap7.

Youandi12 avatar Youandi12 commented on August 26, 2024

we have changed the common.py en we add the lib_location='/usr/local/lib/libsnap7.so
above return your marked return (boven return heb ik deze regel ingezet )

i have follow this
You will need to edit the lib_location on common.py in the /usr/local/lib/python2.7/dist-packages/snap7/ directory
Add a line in the init part of the Snap7Library class:
lib_location='/usr/local/lib/libsnap7.so'
example below:

class Snap7Library(object):
    """
    Snap7 loader and encapsulator. We make this a singleton to make
    sure the library is loaded only once.
    """
    _instance = None
    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = object.__new__(cls)
            cls._instance.lib_location = None
            cls._instance.cdll = None
        return cls._instance

    def __init__(self, lib_location=None):
        lib_location='/usr/local/lib/libsnap7.so' # add this line here
        if self.cdll:
            return
        self.lib_location = lib_location or self.lib_location or find_library('snap7')
        if not self.lib_location:
            msg = "can't find snap7 library. If installed, try running ldconfig"
            raise Snap7Exception(msg)
        self.cdll = cdll.LoadLibrary(self.lib_location)

from python-snap7.

Youandi12 avatar Youandi12 commented on August 26, 2024

hi ,
We have reinstalled snap 7 and his library. We tested this like you told us yesterday and it says that the library is installed.
Our faults of yesterday are gone, but we have a new problem if we try this:
import snap 7
client = snap7.client.Client()
client.connect('192.168.5.2', 0, 1)
db_number = 109
start = 0
data = ff
client.db_write(self, db_number, start, data)

We get this fault:
Traceback (most recent call last):
File "/home/pi/TEST3.py", line 8, in
client.db_write(self, db_number, start, data)
NameError: name 'self' is not defined

Could you help us please?

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

don't give self to the method. Please google for 'python' and 'self', for example this explains more:

http://stackoverflow.com/questions/7721920/when-do-you-use-self-in-python

import snap 7
client = snap7.client.Client()
client.connect('192.168.5.2', 0, 1)
db_number = 109
start = 0
data = ff
client.db_write(db_number, start, data)

from python-snap7.

Youandi12 avatar Youandi12 commented on August 26, 2024

if we remove self then we got this problems
Traceback (most recent call last):
File "/home/pi/TEST3.py", line 8, in
client.db_write( db_number, start, data)
File "/usr/local/lib/python2.7/dist-packages/snap7/client.py", line 24, in f
code = func(*args, **kw)
File "/usr/local/lib/python2.7/dist-packages/snap7/client.py", line 152, in db_write
size = len(data)
TypeError: object of type 'int' has no len()

from python-snap7.

gijzelaerr avatar gijzelaerr commented on August 26, 2024

i'm sorry but you really should get yourself more familiar with Python, otherwise this is going nowhere. Data should be a bytearray.

from python-snap7.

Zebrafish007 avatar Zebrafish007 commented on August 26, 2024

It should be data = 'ff' # for all who just new to python.

from python-snap7.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.