Issue sending data from C++ to Python

MRAB python at mrabarnett.plus.com
Wed May 18 13:37:15 EDT 2022


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));
...


More information about the Python-list mailing list