0

シリアルポートをリッスンして、15 秒ごとに保存したい。しかし、ループで時間を使用することはできません。

以下のようにエラーになります。

ファイル "serial-reader.py"、13 行目 timer.start() ^ IndentationError: インデントされたブロックが必要です

どうすればこの問題を解決できますか?

    import threading
from contextlib import closing
import serial
counter = 0
continue_looping = True
def stopper():
    global continue_looping
    continue_looping = False

timer = threading.Timer(15, stopper)

while (counter < 9 ):
timer.start()
with open("/Users/macproretina/Desktop/data.txt", 'w') as out_file:
    with closing(serial.Serial('/dev/tty.usbmodem1411', 9600, timeout=1)) as ser:
        while continue_looping:
            line = ser.readline()   # read a '\n' terminated line
            out_file.write(line.decode('utf-8'))
            out_file.flush()
            counter = counter +1
4

2 に答える 2

2
while True:       # True must be upper-case!
    timer.start() # This is inside a loop so must be indented!
    ...

受け取ったエラー メッセージは、インデントする必要があることを正確に示していることに注意してください。

于 2013-05-24T02:40:17.150 に答える