python实现串口通信视频讲解_Python实现串口通信(pyserial)过程解析

pyserial模块封装了对串口的访问,兼容各种平台。

安装 pip insatll pyserial

初始化

简单初始化示例 import serial

ser = serial.Serial('com1', 9600, timeout=1)

所有参数 ser = serial.Serial(

port=None, # number of device, numbering starts at

# zero. if everything fails, the user

# can specify a device string, note

# that this isn't portable anymore

# if no port is specified an unconfigured

# an closed serial port object is created

baudrate=9600, # baud rate

bytesize=EIGHTBITS, # number of databits

parity=PARITY_NONE, # enable parity checking

stopbits=STOPBITS_ONE, # number of stopbits

timeout=None, # set a timeout value, None for waiting forever

xonxoff=0, # enable software flow control

rtscts=0, # enable RTS/CTS flow control

interCharTimeout=None # Inter-character timeout, None to disable

)

不同平台下初始化 ser=serial.Serial("/dev/ttyUSB0",9600,timeout=0.5) #使用USB连接串行口

ser=serial.Serial("/dev/ttyAMA0",9600,timeout=0.5) #使用树莓派的GPIO口连接串行口

ser=serial.Serial(1,9600,timeout=0.5)#winsows系统使用com1口连接串行口

ser=serial.Serial("com1",9600,timeout=0.5)#winsows系统使用com1口连接

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值