找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2502|回复: 1

[求助] python3.5.2 UnicodeDecodeError: 'utf-8'

1

主题

1

帖子

1

积分

贫民

积分
1
youqinrumeng 发表于 2017-7-25 18:51:50 | 显示全部楼层 |阅读模式
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
为什么出现编码错误?


回复

使用道具 举报

1

主题

3

帖子

3

积分

贫民

积分
3
yexiaoz 发表于 2017-7-25 20:40:21 | 显示全部楼层
虽然我看不懂你的,但是可以看看我的问题吗,帮忙解决下吗?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表