Skip to content

Instantly share code, notes, and snippets.

@apherio
Created November 20, 2018 08:17
Show Gist options
  • Save apherio/973ea7c80674516e38b3eae16b1d6e69 to your computer and use it in GitHub Desktop.
Save apherio/973ea7c80674516e38b3eae16b1d6e69 to your computer and use it in GitHub Desktop.
import serial, time
ser = serial.Serial()
ser.port = '/dev/ttyACM1'
#ser.port = 'COM10'
ser.baudrate = 115200
ser.bytesize = serial.EIGHTBITS
ser.parity =serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.timeout = 1
ser.open()
ser.write(b'\r\r')
time.sleep(1)
ser.write(b'lep\r')
ser.close()
while True:
try:
ser.open()
value=ser.readline()
ser.close()
print(value)
except KeyboardInterrupt:
ser.flushInput()
ser.flushOutput()
ser.close()
print("Connection closed")
break
except Exception as e:
ser.close()
print(e)
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment