使用python将串口引脚设置为高电平 [英] Set serial port pin high using python

查看:79
本文介绍了使用python将串口引脚设置为高电平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用python(或C)将串口的一个引脚连续设置为高电平?如果是,如何?

Is it possible to set one pin of the serial port continuously high using python (or C)? If yes, how?

推荐答案

使用 pyserial 方法 setRTS(level=True)setDTR(level=True) 你可以随意控制RTS和DTR线路.例如,以下代码将切换第一个串行端口的 RTS 引脚.(有关详细信息,请参阅 pyserial 文档).

Using the pyserial methods setRTS(level=True) and setDTR(level=True) you can control the RTS and DTR lines at will. For instance, the following code will toggle the RTS pin of the first serial port. (See the pyserial documentation for the details).

import time
import serial

ser = serial.Serial(0)
ser.setRTS(False)
time.sleep(0.5)
ser.setRTS(True)
time.sleep(0.5)
ser.setRTS(False)

这篇关于使用python将串口引脚设置为高电平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆