在控制台的两个输入之间运行一个函数

我有一个运行良好的脚本,但我想为其添加一个实现。首先,我使用脚本通过 PyVISA 与几个设备(频率发生器和示波器)进行通信并进行一些测量。在此过程中的某个步骤,我必须手动调整一个带有旋钮的光电探测器(不能与 PyVISA 一起使用,但连接到示波器的物理设备),该旋钮非常敏感并且可能会损坏。我正在使用我自己的功能来控制通过示波器测量电压的损坏,名为 PreventAPD。该功能主要读取示波器的电压,如果大于某个电平,则停止系统。


运行脚本时,控制台中会显示一条消息以进行调整,此时我想开始运行 PreventAPD 功能,并且在调整完成后停止运行,我在再次控制台。调整时间可能需要不确定的时间,有时是 1 分钟或 3 分钟。


下面的代码显示了我的问题的一个示例。


print('Adjust manually the Gain from the APD')

input('Press Enter to continue')               <---- From here

PreventAPD()                                   <---- Function to run

PreventLD()                                    <---- Function to run

M = int(input("Insert the value of M: "))

print(f"The value of M is {M}")

input('Press Enter to continue')               <---- Until here

有人有什么主意吗?


莫回无
浏览 92回答 1
1回答

ITMISS

...脚本在控制台中的两个输入之间运行函数,但只运行一次。…我希望它在一个循环中运行,该循环从一个输入控制台开始,到另一个输入控制台停止。您可以使用KeyboardInterrupt异常来中断循环:print('Adjust manually the Gain from the APD')input('Press Enter to continue')print('Press Interrupt (Ctrl-C) to enter M')try:&nbsp; &nbsp; while True:&nbsp; &nbsp; &nbsp; &nbsp; PreventAPD()&nbsp; &nbsp; &nbsp; &nbsp; PreventLD()except KeyboardInterrupt:&nbsp; &nbsp; passM = int(input("Insert the value of M: "))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python