Advertisement
Narayan

readwriteSerial

Oct 5th, 2022
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import serial, json
  2.  
  3. ser = serial.Serial(
  4.         port = '/dev/ttyUSB0',
  5.         baudrate = 115200,
  6.         timeout = 10,
  7.         xonxoff = False
  8. )
  9. val = 0
  10. command = ''
  11. command = input("Enter command: ")
  12. command += str('\n')
  13. val = ser.write(command.encode(encoding = 'ascii', errors = 'strict'))
  14. print("Bytes written: ", val)
  15. in_data = ''
  16. in_data = ser.read_until(b'}')
  17. print(json.dumps(json.loads(in_data.decode()), indent = 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement