python-3.x - 如何在 python 中使用 ESCape 键与串口交互?
问题描述
我正在尝试使用 ESCape 键返回菜单页面,但似乎无法将其实现到 if 语句中。一旦按下 ESCape 键,它应该返回到主菜单。我正在使用 Python 3.7
import serial
import Keyboard
ser = serial.Serial ('COM18', baudrate = 115200, timeout = 1) #USB Serial Device
def getMenuData():
PhoenixMainMenu = ser.readline().decode('ascii')
return PhoenixMainMenu
def printScreen():
n=20
while n <= 20: #as long as
print(getMenuData())
n-=1
if n >= 0:
print (getMenuData())
n-=1
else:
break
while True:
print (printScreen())
print ('Escape Key brings you back to main menu')
UserInput = input('To access option type its coresponding number: ')
if UserInput == '1':
ser.write(b'1') #HW test
print ('first is the worst')
secondInput = input('To access the function type letter: ')
if secondInput == 'a':
ser.write(b'a')
else:
print ('Invalid entry. Please Try again.')
break
elif UserInput == keyboard.wait('esc')
ser.write(b'0x1b')
print ('Main MEnu')
print (printScreen())
break
else:
print ('Invalid entry. Please Try again.')
解决方案
推荐阅读
- sendgrid - 在单个 SendGrid 请求中向同一用户发送多封电子邮件
- r - 是否有一个选项可以限制带有显着性标签的ggplot中呈现的轴值而不在R中将它们切断
- c - 制作具有特定大小的数组,其中包含数据结构数据类型中的元素
- r - 移动块引导的覆盖概率问题
- python - 来自 C++ 奇怪输出的 Python 复数
- c# - 在 unity2d 中制作 2d 布娃娃
- javascript - 更新订单项目总计中的增量数量?
- android - Crashlytics 不报告 Firebase 中的崩溃
- typescript - 打字稿中的剂量[索引:字符串]是什么意思
- python - 如何配置 python mysql.connector 以转换没有字节数组 b'' 的长文本字段