Last active
December 28, 2015 11:29
-
-
Save ilonajulczuk/7493698 to your computer and use it in GitHub Desktop.
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
import serial | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-p", "--port", type=str, | |
help="name of port", | |
default='/dev/ttyUSB0') | |
parser.add_argument("-o", "--output_filename", type=str, | |
help="filename of output file", | |
default='data.txt') | |
def main(): | |
args = parser.parse_args() | |
port = args.port | |
output = args.output_filename | |
ser = serial.Serial(port, 9600, timeout=1) | |
with open(output, 'a+') as f: | |
while True: | |
line = ser.readline() # read a '\n' terminated line | |
f.write(line) | |
ser.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple script for reading from serial.
Reads from serial on selected port and writes to file.
usage:
$ python from_serial_to_file.py [-h] [-p PORT] [-o OUTPUT_FILENAME]
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT name of port
-o OUTPUT_FILENAME, --output_filename OUTPUT_FILENAME
filename of output file