Я пытаюсь создать оболочку Bluetooth Python для упаковки классов C ++. Это мой файл интерфейса SWIG:
%module blsdk
%include "pyabc.i"
%include "std_vector.i"
%include "cstring.i"
%include "cpointer.i"
%include "typemaps.i"
%include serialport.i
%include exploresearch.i
Вот мой serialport.i
%module serialport
%{
#include <string>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <termios.h>
#include <sys/poll.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <assert.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
#include <bluetooth/rfcomm.h>
#include "BTSerialPortBinding.h"
%}
%include "BTSerialPortBinding.h"
Мой BTSerialPortBinding.h имеет следующие функции:
static BTSerialPortBinding *Create(std::string address, int channelID);
int Connect();
void Close();
int Read(char *buffer, int length);
void Write(const char *write_buffer, int length);
bool IsDataAvailable();
Как можно Я обертываю int Read (символ * буфер, длина int) ? Я хочу иметь буфер char * в качестве вывода и длину в качестве ввода. Я попытался определить функцию чтения как int Read (char * OUTPUT, int length) , но это выдает ошибку: TypeError: требуется объект, похожий на байты, а не 'str' в моей программе, так как мне нужен байтовый объект в Python. Любая помощь будет очень высоко ценится.