Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###################################################
- # Write log from COM port to file for Arduino #
- # Requires Python 2.7 with PySerial installed #
- # Install PySerial: pip install pyserial #
- ###################################################
- import serial
- COM_PORT = 'COM7'
- COM_BAUD = 9600
- LOG_FILE = 'data_log.txt'
- def create_port(name, baud, timeout = 1):
- return serial.Serial(
- port=name,
- baudrate=baud,
- bytesize=8,
- parity=serial.PARITY_NONE,
- stopbits=1,
- rtscts=False,
- dsrdtr=False,
- timeout=timeout
- )
- if __name__ == '__main__':
- com = create_port(COM_PORT, COM_BAUD)
- print "Logging started"
- with open(LOG_FILE, "a") as log:
- while True:
- try:
- line = com.readline().strip()
- if len(line):
- print(line)
- log.write(line + "\r\n")
- log.flush()
- except:
- break
- print("Logging stopped\r\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement