python - 如何暂停 python 的 for 循环,直到 Arduino 响应
问题描述
我创建了一个 python 代码(Tkinter GUI),它应该通过串行通信与 Arduino 进行通信。
我有一张表需要逐列发送。但在我发送下一列之前,我需要等待 Arduino 完成对前一列的处理。
这是一个遍历表的代码:
def send():
for row in rows:
for col in row:
print(col.get()),
print(" ")
以下是该表的创建方式:
rows = []
for i in range(1, 20):
cols = []
for j in range(6):
e = Entry(secondFrame, relief=RIDGE, justify=CENTER)
e.grid(row=i, column=j, sticky=NSEW)
#e.insert(END, '%d.%d' % (i, j))
e.insert(END, '-')
cols.append(e)
rows.append(cols
解决方案
一旦arduino准备好接收更多数据,它肯定会以某种方式发出信号......例如,它可能会发送一个'>'
......假设你有一个ser
变量是一个实例pyserial.Serial
(因为你没有包含任何指示串行连接的东西)
ser.write(columnData)
response = ser.read_until(">")
print("Probably can send the next column...")
推荐阅读
- python - VSCode 不会在 .ipynb 中导入 xgboost
- python - python中的立方体根在shell中不同
- java - JavaFX 和 ControlsFX - 自动完成文本字段 - 显示下拉菜单
- javascript - 使用 RequireJs + Karma + Jasmine 测试事件
- javascript - 如何在电子中获取添加的 BrowserView 的控制台输出?
- azure-functions - 来自未加入域的 PC 和 Function App 的 Key Vault
- angular - 在 Angular 的“jsencrypt”中找不到导出“JSEncrypt”
- java - 正则表达式验证一个字符串是否有 2 个连续的字母(不是 2 个连续的字母)
- javascript - 为什么我的数组被覆盖而不是使其成为一个包含对象的数组?
- javascript - 如何使用猫鼬填充?我有个问题