rscada / python-mbus Goto Github PK
View Code? Open in Web Editor NEWPython wrapper for libmbus
License: BSD 3-Clause "New" or "Revised" License
Python wrapper for libmbus
License: BSD 3-Clause "New" or "Revised" License
Just running the tests that come with python-mbus
causes the Python interpreter to segfault.
libmbus
is git head as of this morning, tried both with commit widesky/libmbus@716d712 and widesky/libmbus@ef6c4be. libmbus
itself appears to work judging from the test/example programs it comes with, so it looks to be something funny with python-mbus
.
RC=0 stuartl@rikishi /tmp/python-mbus $ py.test
======================================================================== test session starts ========================================================================
platform linux2 -- Python 2.7.7 -- py-1.4.30 -- pytest-2.7.2
rootdir: /tmp/python-mbus, inifile: pytest.ini
plugins: cov
collected 16 items
tests/test_MBus_connect.py Segmentation fault
Changes to python-mbus
:
diff --git a/mbus/MBus.py b/mbus/MBus.py
index 7f26165..671a18f 100644
--- a/mbus/MBus.py
+++ b/mbus/MBus.py
@@ -60,7 +60,7 @@ class MBus:
raise TypeError("port number not given as integer")
if None == libpath:
- libpath = "/usr/local/lib/libmbus.so"
+ libpath = "/usr/local/lib64/libmbus.so"
self._libmbus = cdll.LoadLibrary(libpath)
diff --git a/pytest.ini b/pytest.ini
index f84356a..0cd849c 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,8 +1,8 @@
[pytest]
-addopts = --pep8 --cov-config .coveragerc --cov . tests/
+addopts = --cov-config .coveragerc --cov . tests/
-serialdevice = /dev/adjustme
+serialdevice = /dev/ttyS0
;serialdevice = /dev/ttyUSB0
markers =
- serial: mark a test to be run with serial device attached
\ No newline at end of file
+ serial: mark a test to be run with serial device attached
I think there is a typo in https://github.com/rscada/python-mbus/blob/master/mbus/MBusFrame.py#L21
the field stop
is a duplicate and the second instance probably should be type
, according to https://github.com/rscada/libmbus/blob/master/mbus/mbus-protocol.h#L91.
I tried redefining the field as:
diff --git a/mbus/MBusFrame.py b/mbus/MBusFrame.py
index 36358e8..1b9c677 100644
--- a/mbus/MBusFrame.py
+++ b/mbus/MBusFrame.py
@@ -1,4 +1,4 @@
-from ctypes import Structure, c_uint8, c_long, c_size_t, POINTER
+from ctypes import Structure, c_int, c_uint8, c_long, c_size_t, POINTER
c_time_t = c_long
@@ -18,7 +18,7 @@ MBusFrame._fields_ = [
("stop", c_uint8),
("data", c_uint8 * 252),
("data_size", c_size_t),
- ("stop", c_uint8),
+ ("type", c_int),
("timestamp", c_time_t),
("next", POINTER(MBusFrame))
]
However, even with this change, I wasn't able to read the type of the MBusFrame (also tried c_uint8 for the type). I'm not that familiar with ctypes
, so maybe there is another place where the C struct is mapped to the Python object MBusFrame?
For testing I called the function frame_type
from the C library directly and it returned 4
while queryting the type
attribute in Python always returned 0
.
Hi,
Is this a typo or why is start1
type c_uint8 * 16
in MBusFrame._fields_
? According to https://github.com/rscada/libmbus/blob/master/mbus/mbus-protocol.h#L77 it shoul also be just c_uint8
.
typedef struct _mbus_frame {
unsigned char start1;
unsigned char length1;
unsigned char length2;
unsigned char start2;
...
How do you fill and use the frame structure with such array definition?
I locally changed it to c_uint8
diff --git a/mbus/MBusFrame.py b/mbus/MBusFrame.py
index 9d1b2b5..8f511b6 100644
--- a/mbus/MBusFrame.py
+++ b/mbus/MBusFrame.py
@@ -7,7 +7,7 @@ class MBusFrame(Structure):
return "MBusFrame: XXX"
MBusFrame._fields_ = [
- ("start1", c_uint8 * 16), # MBusFrameFixed
+ ("start1", c_uint8),
("length1", c_uint8),
("length2", c_uint8),
("start2", c_uint8),
Now I can easily create MBus frames with code like this:
mbus_frame = MBusFrame()
mbus_frame.start1 = MBUS_FRAME_LONG_START
mbus_frame.length1 = data_size + 3
mbus_frame.length2 = mbus_frame.length1
mbus_frame.start2 = mbus_frame.start1
...
Is this a mistake and should I send a pull request for that or is it possible to use this structure in any other way?
Hello
I've been testing this code but I can't do much. Seems that this was not designed for the latest version of libmbus.
Can you give me some help on this?
Hi,
I managed to get the libmbus library compiled and working on my pi.
I would like to use the python wrapper
to develop my Mbus scanner application on Python.
In the example code, I see an Mbus instance being initialised in line 16
mbus = MBus(host="mbus-gw1", port=8888)
I would like to have Mbus on serial port /dev/TTYAMA0.
Please guide me on initialising Mbus on the serial port instead of TCP.
is it possible to change the baudrate? i tried to call the function 'serial_set_baudrate' of MBusLowLevel but i don't know what mbus_handle_p object to pass.
The original code states no specific FLOSS-license. Which one to choose? I would go for a 3-clause BSD license like libmbus, but AGPL is also fine.
Cheers,
tpltnt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.