我正在开发一个基于 python 的闪亮应用程序,用于通过串行传输线驱动流体泵。配置具有设定幅度和运行时间的流量曲线后,可以通过按操作按钮“p1”启动串行传输。
我面临的问题是与按钮“p1”相关的内部缺乏反应性reactive.event(input.p1):我想确保通过单击“p1”开始传输,从而触发可以reactive.event(input.p1)随时通过单击“p2”终止传输。
然而,当前的实现导致停止消息 inreactive.event(input.p2)排队并在传输reactive.event(input.p1)结束后发送。
我怎样才能解决这个问题?有什么方法可以确保我的程序仍然对其他输入做出反应?我希望单击“p2”后立即停止传输。两个按钮的实现都放在下面。
@reactive.Effect
@reactive.event(input.p1)
def _():
y = yg.get() # fetch np.array y from reactive value yg, numbers in y correspond to driving voltages
for e in y: # iterate over array
msg = "1:1:"+str(e)+":100" # formatted string containing the driving voltage
#print(msg) # print to console in debug mode
ser.write(bytes(msg,'utf-8')) # send the formatted string
t0 = time.time() # time stamp
while(((time.time()-t0)<=2)): # next driving voltage …Run Code Online (Sandbox Code Playgroud)