-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlog_serial.py
More file actions
35 lines (28 loc) · 786 Bytes
/
log_serial.py
File metadata and controls
35 lines (28 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import serial
import time
PORT = "COM5"
BAUD = 115200
OUTFILE = "ir_log.csv"
# FOR BT
# PORT = "COM7"
# BAUD = 115200
# OUTFILE = "bt_log.txt"
def main():
ser = serial.Serial(PORT, BAUD, timeout=1)
time.sleep(2)
print(f"Logging from {PORT} at {BAUD} baud...")
print(f"Saving to {OUTFILE}")
print("Press Ctrl+C to stop.\n")
with open(f"./logs/{OUTFILE}", "w", encoding="utf-8") as f:
while True:
try:
line = ser.readline().decode("utf-8", errors="ignore").strip()
if line:
print(line)
f.write(line + "\n")
except KeyboardInterrupt:
print("\nStopped logging.")
break
ser.close()
if __name__ == "__main__":
main()