折腾了3天受不了来论坛求助各位大侠了
如下是raspberry的乱码输出(python和C语言版都一样的德性,居然还有PuTTY的字样,是什么原理呢?)
附件为windows串口调试助手截图,看看人家多乖:
无奈的来求助了
这是python的代码
import serial
from time import sleep
ser = serial.Serial('/dev/ttyUSB0', 9600, rtscts=1, timeout=0)
while True:
line = ser.read(ser.inWaiting())
if len(line)>0:
print line
sleep(1)
ser.close()
这是C语言的代码,fd还是那个ttyUSB0
while (1)
{
while((nread = read(fd, buff, 512))>0)
{
if(nread>0){
time(&now);
timenow = localtime(&now);
printf("len %d, data read in %s\n",nread,asctime(timenow));
buff[nread+1] = '\0';
printf( "%s\n", buff);
}
}
sleep(1);
}
|