Mailing List Archive

Issue sending data from C++ to Python
Hello,

I have been using your C++ Python API, in order to establish a bridge from
C++ to Python. We want to do this, as we have a tactile sensor, which only
has a library developed in C++, but we want to obtain the data in real time
in Python to perform tests with a robotic arm and gripper. The problem we
are facing is with transmitting the data into Python. We are using the
function Py_BuildValue, and it seems to be working, but only for sending
one value at a time, and we want to transmit 54 numbers. When
transmitting a single value retrieved from the sensor into Python in a
double or string format, it works, but when we make the string bigger it
gives us an error with the utf-8 encoding. Also when sending a tuple of
doubles or strings, it works when the tuple is composed of a single
element, but not when we send 2 or more values. Is there any way of fixing
this issue? Or is it just not possible to transmit such a large amount of
data?

Thank you.
Best regards,

*Pablo Martinez Ulloa*
PhD Candidate,
School of Electrical and Electronic Engineering, R324A
University College Dublin, Belfield, Dublin 4, Ireland
--
https://mail.python.org/mailman/listinfo/python-list
Re: Issue sending data from C++ to Python [ In reply to ]
On 2022-05-18 15:08, Pablo Martinez Ulloa wrote:
> Hello,
>
> I have been using your C++ Python API, in order to establish a bridge from
> C++ to Python. We want to do this, as we have a tactile sensor, which only
> has a library developed in C++, but we want to obtain the data in real time
> in Python to perform tests with a robotic arm and gripper. The problem we
> are facing is with transmitting the data into Python. We are using the
> function Py_BuildValue, and it seems to be working, but only for sending
> one value at a time, and we want to transmit 54 numbers. When
> transmitting a single value retrieved from the sensor into Python in a
> double or string format, it works, but when we make the string bigger it
> gives us an error with the utf-8 encoding. Also when sending a tuple of
> doubles or strings, it works when the tuple is composed of a single
> element, but not when we send 2 or more values. Is there any way of fixing
> this issue? Or is it just not possible to transmit such a large amount of
> data?
>
I find it easier if I have some code in front of me to 'criticise'!

Have you thought about building and returning, say, a list instead?

/* Error checking omitted. */
PyObject* list;
list = PyList_New(0);
PyList_Append(list, PyLong_FromSsize_t(1));
PyList_Append(list, PyFloat_FromDouble(2.0));
...
--
https://mail.python.org/mailman/listinfo/python-list
Re: Issue sending data from C++ to Python [ In reply to ]
Am 18.05.22 um 16:08 schrieb Pablo Martinez Ulloa:
> I have been using your C++ Python API, in order to establish a bridge from
> C++ to Python. We want to do this, as we have a tactile sensor, which only
> has a library developed in C++, but we want to obtain the data in real time
> in Python to perform tests with a robotic arm and gripper. The problem we
> are facing is with transmitting the data into Python. We are using the
> function Py_BuildValue, and it seems to be working, but only for sending
> one value at a time, and we want to transmit 54 numbers

The usual way to pass an array of numbers into Python is by means of a
Numpy Array. In order to do that, you need to include arrayobject.h and
then use PyArray_SimpleNew to create an array of numbers as a Python
object which you can return
https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_SimpleNew


Christian
--
https://mail.python.org/mailman/listinfo/python-list
Re: Issue sending data from C++ to Python [ In reply to ]
Pablo Martinez Ulloa wrote at 2022-5-18 15:08 +0100:
>I have been using your C++ Python API, in order to establish a bridge from
>C++ to Python.

Do you know `cython`?
It can help very much in the implementation of bridges between
Python and C/C++.
--
https://mail.python.org/mailman/listinfo/python-list