Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial, json
- ser = serial.Serial(
- port = '/dev/ttyUSB0',
- baudrate = 115200,
- timeout = 10,
- xonxoff = False
- )
- val = 0
- command = ''
- command = input("Enter command: ")
- command += str('\n')
- val = ser.write(command.encode(encoding = 'ascii', errors = 'strict'))
- print("Bytes written: ", val)
- in_data = ''
- in_data = ser.read_until(b'}')
- print(json.dumps(json.loads(in_data.decode()), indent = 4))
Advertisement
Add Comment
Please, Sign In to add comment