Skip to content

Instantly share code, notes, and snippets.

@ssnover
Created September 18, 2017 23:50
Show Gist options
  • Save ssnover/414e382da9ca900a9a1e2daebced54b2 to your computer and use it in GitHub Desktop.
Save ssnover/414e382da9ca900a9a1e2daebced54b2 to your computer and use it in GitHub Desktop.
Reads from a hard-coded serial port relying on a hard-coded message format.
import serial
LOG_FILE = 'can-message-log.txt'
def main():
"""
:return:
"""
my_serial_port = serial.Serial(port='COM6',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS)
while my_serial_port.isOpen():
json_line = my_serial_port.read_until(terminator='\n')
file_handler = open(LOG_FILE, 'a')
file_handler.write(json_line + "\n")
file_handler.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment