Created
May 20, 2021 09:33
-
-
Save wolkenarchitekt/4a525463895f381f9bd7307e97871bc5 to your computer and use it in GitHub Desktop.
TR-1F Logging example using pySerial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import argparse | |
import io | |
import logging | |
import serial | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="TR-1F Logger") | |
parser.add_argument( | |
"--device", help="Serial device, example: /dev/ttyUSB0", required=True | |
) | |
parser.add_argument("--baudrate", help="Baud rate", default=115200) | |
parser.add_argument("--file", help="Output file", required=True) | |
args = parser.parse_args() | |
ser = serial.Serial( | |
port=args.device, | |
baudrate=args.baudrate, | |
stopbits=serial.STOPBITS_ONE, | |
timeout=1, | |
) | |
ser.flushInput() | |
ser.flushOutput() | |
ser_text = io.TextIOWrapper(ser, newline="\r\n") | |
logging.basicConfig( | |
filename=args.file, | |
level=logging.DEBUG, | |
format="%(asctime)s > %(message)s", | |
) | |
logger = logging.getLogger() | |
while True: | |
line = ser_text.readline().strip() | |
if line: | |
logger.info(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment