gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
669 stars 246 forks source link

Update to support 64bit snap7 1.2.0 API #9

Closed lkraider closed 10 years ago

lkraider commented 10 years ago

Not sure about the changes, just tried to run it and got a segfault:

INFO:snap7.server:creating server
INFO:snap7.server:setting event callback
Segmentation fault: 11

trace:

stop reason = EXC_BAD_ACCESS (code=1, address=0x88fc40)
frame #0: 0x0000000100643d74 libsnap7.so`TCustomMsgServer::SetEventsCallBack(void (*)(void*, TSrvEvent*, int), void*) + 4
frame #1: 0x00000001004d26e7 _ctypes.so`ffi_call_unix64 + 79
...
gijzelaerr commented 10 years ago

hi @lkraider , thanks for the report. Can you create a gist with a minimal version of your code that triggers this segmentation fault?

lkraider commented 10 years ago

I should state that I am testing on OSX 10.9.2 with the x86_64 library compiled with lldb. The examples/plain-c/server and client from the snap7 source work fine.

Looking at the source, the S7Object in python-snap7 is 32bit, which is the problem. The code below works:

import ctypes

lib = ctypes.cdll.LoadLibrary('lib/libsnap7.so')
print(lib)

lib.Cli_Create.restype = ctypes.c_void_p
cli = lib.Cli_Create()
print(hex(cli))

lib.Cli_ConnectTo.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int]
res = lib.Cli_ConnectTo(cli, '127.0.0.1', 0, 0)
print(res)

result:

<CDLL 'lib/libsnap7.so', handle 7f983b462ed0 at 10f360f50>
0x7f983b875000
0
gijzelaerr commented 10 years ago

interesting, we've developed python-snap7 on 64bit linux so i'm not sure why this is a problem for 64 osx.

spreeker commented 10 years ago

ikraider, out of curiosity what kind of project are you using snap7 for?

lkraider commented 10 years ago

It's in a new custom production line for printing codes in a thermal printer. We use a PLC to control several parts of the line, and I read and also write to it from a python app that I created that generates these codes.

spreeker commented 10 years ago

You are AWESOME ;)