Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time
- import serial
- def convertCmdToBytes(str_cmd):
- if(str_cmd[-1] != '\r'):
- str_cmd += '\r' # Cmd MUST end in carriage return
- cmd_bytearray = bytes(str_cmd, 'utf-8')
- # Return array of individual byte literals
- individual_bytes = [cmd_bytearray[i:i+1] for i in range(len(cmd_bytearray))]
- return individual_bytes
- try:
- baudrate = 230400
- ser = serial.Serial('COM5', baudrate=baudrate, timeout=1)
- # cmd = 'usbid\r'
- cmd = 'read\r'
- for b in convertCmdToBytes(cmd):
- ser.write(b)
- time.sleep(0.001) # Delay between sending consecutive bytes
- line = ser.readline()
- print(line)
- except KeyboardInterrupt:
- print('bye')
- sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement