Created
October 7, 2015 09:25
-
-
Save bassdread/d56af71fe6e80d3f07e1 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
#!/usr/bin/python | |
import sys | |
import serial | |
import json | |
def main(device, load_json=False): | |
device_path = "/dev/{0}".format(device) | |
print "Opening {}".format(device_path) | |
serial_connection = serial.Serial(device_path, 9600, timeout=1) | |
print "Starting to read from serial... ctrl-c to stop" | |
while (True): | |
json_input = serial_connection.readline() | |
if json_input: | |
try: | |
print json_input | |
if load_json: | |
print "JSON Version: ", | |
print json.loads(json_input) | |
except Exception as e: | |
print e.message | |
if __name__ == "__main__": | |
device = "ttyUSB0" | |
load_json = False | |
if len(sys.argv) == 2: | |
device = sys.argv[1] | |
if len(sys.argv) == 3: | |
load_json = sys.argv[2] | |
main(device, load_json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment