Comments (17)
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.
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.
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.
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.
what happens if you run
from ctypes.util import find_library
print find_library('snap7')
in a python console or script?
from python-snap7.
we got this:
libsnap7.so
from python-snap7.
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.
<CDLL 'libsnap7.so', handle 5de320 at 756d0ff0>
from python-snap7.
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.
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.
nah that doesn't seem the case.... hm
from python-snap7.
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.
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.
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.
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.
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.
It should be data = 'ff'
# for all who just new to python.
from python-snap7.
Related Issues (20)
- Redundant 400-H get_cpu_state() returning incorrect value.
- Add python 3.12 support, build wheels HOT 2
- RuntimeError: b' ISO : An error occurred during recv TCP : Connection timed out'
- Error in util.Set_String and util.Get_String HOT 1
- as_db_read() doesnt work
- Wrong values set_lreal
- db[0]['x']=22.33 raises ValueError HOT 2
- Improve doc for area_read in client HOT 3
- Communication between PLC and PC HOT 1
- Can't read from S210 Drive
- Get data block layout
- TypeError: '_ctypes.PyCArrayType' object is not subscriptable HOT 1
- Make client and server a contextmanager HOT 1
- Drop Python 3.8 from metadata and doc HOT 1
- Drop Snap7Library singleton and use python functools caching HOT 1
- version 1.4 broken on python 3.8 HOT 2
- Snap7Exception is not used HOT 1
- Replace `OrderedDict` with the built-in `dict` HOT 2
- Add set_pdu_length() HOT 11
- Can anyone port this library to micropython?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-snap7.