]> sigrok.org Git - libsigrok.git/commitdiff
Python-Binding: Added data array for logic packet payload
authorSven Bursch-Osewold <redacted>
Fri, 19 Oct 2018 07:11:36 +0000 (09:11 +0200)
committerUwe Hermann <redacted>
Sat, 10 Nov 2018 22:20:16 +0000 (23:20 +0100)
bindings/python/sigrok/core/classes.i

index 69c05a30b808317aa0f11b849c0fbb94bbff9f81..63a5143ebc96b8379b14a3fe86035641159719f4 100644 (file)
@@ -390,6 +390,7 @@ std::map<std::string, Glib::VariantBase> dict_to_map_options(PyObject *dict,
 
 /* Ignore these methods, we will override them below. */
 %ignore sigrok::Analog::data;
+%ignore sigrok::Logic::data;
 %ignore sigrok::Driver::scan;
 %ignore sigrok::InputFormat::create_input;
 %ignore sigrok::OutputFormat::create_output;
@@ -548,4 +549,24 @@ std::map<std::string, Glib::VariantBase> dict_to_map_options(PyObject *dict,
 }
 }
 
+/* Return NumPy array from Logic::data(). */
+%extend sigrok::Logic
+{
+    PyObject * _data()
+    {
+        npy_intp dims[2];
+        dims[0] = $self->data_length() / $self->unit_size();
+        dims[1] = $self->unit_size();
+        int typenum = NPY_UINT8;
+        void *data = $self->data_pointer();
+        return PyArray_SimpleNewFromData(2, dims, typenum, data);
+    }
+
+%pythoncode
+{
+    data = property(_data)
+}
+}
+
+
 %include "doc_end.i"