Python中COM串口通信的调用与代码实现
本文介绍了在Python中调用COM串口的方法,通过serial库实现串口初始化、数据写入及状态判断。文中提供了完整的Python代码示例,涵盖端口配置、命令发送及交互逻辑,帮助开发者快速掌握串口通信的基本操作与实现细节。
Python调用COM串口的方法与代码实现
具体实现方式如下所示:
import serial
import time
t = serial.Serial('com6', 115200) #USB COM number on your PC and the transfer bit rate of the COM port.
print t.portstr #Display the working UART port number on your PC.
n = t.write('logcat -c \r')
n = t.write('ampclient_samples 2 -O 3 /mnt/media_rw/B278-E25A/video_google_clips/New_Webm/bunny_1080P.webm \r')
time.sleep(3)
print "Does the stream output normally? Yes=1 or No=2"
Input = int(raw_input())
if Input == 1:
print "Pass!!!"
n = t.write(chr(0x03)) #Call for Ctrl+C command in UART port
n = t.write('logcat -c \r')
else:
print "Fail!!!"
n = t.write(chr(0x03))
#n = t.write('logcat -v threadtime /r')
以上内容即为在Python中调用COM串口的方法详解,旨在为读者提供实用的参考。希望这些信息能对大家有所帮助,同时也欢迎大家继续支持本站,获取更多技术分享。
本站声明
本文内容仅供参考,不代表本站观点。转载或引用请注明出处。如发现内容问题,请通过联系我们页面反馈。













