简体   繁体   English

如何在Arduino响应之前暂停python的for循环

[英]How to pause python's for loop until Arduino responds

I've created a python code (Tkinter GUI) that is supposed to communicate with Arduino via serial communication. 我创建了一个python代码(Tkinter GUI),该代码应该通过串行通信与Arduino通信。

I have a table that I need to send over, column by column. 我有一个需要逐列发送的表。 but before I send the next column I need to wait for the Arduino to finish processing the previous one. 但是在发送下一列之前,我需要等待Arduino完成对上一列的处理。

Here is a code that iterates through the table: 这是遍历表的代码:

def send():

    for row in rows:
        for col in row:
            print(col.get()),
        print(" ")

Here is how the table was created: 这是创建表的方式:

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

the arduino will surely signal somehow once it is ready for more data ... for example perhaps it sends a '>' ... ill assume you have a ser variable that is an instance of pyserial.Serial (since you didnt include any thing indicating a serial connection) 一旦准备好获取更多数据,arduino肯定会发出某种信号...例如,它可能会发送一个'>' ...假设您有一个ser变量是pyserial.Serial的实例(因为您没有包含任何东西)表示串行连接)

ser.write(columnData)
response = ser.read_until(">")
print("Probably can send the next column...")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM