如何使用python从串口读取数据?

2024-04-25 06:55:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试使用python打印来自串行端口的gps数据时遇到问题

用于打印数据的代码:

while True:
    serialInst.write('at+cgpsinfo\r'.encode('utf-8'))
    sleep(1)
    packet = serialInst.readline()
    packet_decodificat = packet.decode('utf-8')
    print(packet_decodificat)

但这就是结果:

OK



                        <-- here is printing an empty line where the gps data should've been...

output

这是我使用simcom工具发送AT命令时的输出:

2021-05-11 19:18:15:065[Send->]at+cgpsinfo
2021-05-11 19:18:15:073[Recv<-]

OK

2021-05-11 19:18:15:790[Recv<-]

+CGPSINFO: 478.215547,N,2734.862213,E,100521,161816.0,80.4,0.0,0.0

我是python新手,所以我的代码中可能有一个我不知道的明显错误:D


Tags: 数据端口代码truepacketokatgps