How to pass python "byte" param to python interface called from matlab ?

6 visualizaciones (últimos 30 días)
烨
el 18 de Feb. de 2024
Respondida: Rushikesh el 18 de Sept. de 2024
  1. python call interface from c++ dll
  2. the input data type of interface is unsigned char*
  3. python use bytes object(b'\x10') to pass param to dll interface
  4. how matlab?

Respuestas (1)

Rushikesh
Rushikesh el 18 de Sept. de 2024
Hello @烨,
I understand that you wish to call an interface from a C++ DLL in MATLAB, which requires an unsigned char* as input data. As you mentioned, in Python, we can use the bytes data type, which is compatible with the unsigned char* data type in C++. You can achieve similar functionality in MATLAB using two approaches:
  1. C++ uses unsigned char* for binary data, and Python uses the bytes data type for binary data, which is compatible with unsigned char* in C++. In MATLAB, you can handle binary data using uint8 arrays. This array can then be converted to a Python bytes object
  2. Another approach is to create a Python bytes data object directly in MATLAB. This is possible because MATLAB allows the use of Python code with the 'py.' prefix.
Please refer to the example below for guidance:
/* MATLAB array equivalent to b'\x10' in Python */
data = uint8([16]);
pyData = py.bytes(data);
/* Another way, create bytes data in MATLAB Python. */
pyBytes = py.bytes([16]);
You can try to send MATLAB uint8 array directly to C++ DLL interface but this method is more complex and requires handling data conversion and memory management carefully.
Let me know if this helps.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by