Created
September 18, 2017 23:50
-
-
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.
This file contains hidden or 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 | |
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