|
python3.5.2 C扩展中,读串口函数:
static PyObject * DtuCom_Read(PyObject *self, PyObject *args) {
int len,fd,i;
int timeout,ACK;
int status,port;
char rst[1024];
if (!(PyArg_ParseTuple(args, "iii", &fd, &len, &timeout))) {
return NULL; //(PyObject *)Py_BuildValue("[i,i]",0 ,-1);
}
status = ReadCom(fd,warehouse,&len,timeout);
warehouse[len] = '\0';
return (PyObject *)Py_BuildValue("is",status,rst);
}
python 接收数据报错:
File "/SCP_new/CoroutineDtuSerials.py", line 148, in ReadSerial
status,rst=DtuCom.Read(fd,nCount,timeout).decode("UTF-8", 'ignore')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf8 in position 0: invalid start byte
root@EC4218:/SCP_new#
串口实际接收到的数据是:OK\r\n+IOTSEND: OK
为什么出现编码错误?
|
|