Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import serial
- # configure the serial connections (the parameters differs on the device you are connecting to)
- ser = serial.Serial(
- port='/dev/ttyUSB0',
- baudrate=115200,
- parity=serial.PARITY_NONE,
- stopbits=serial.STOPBITS_ONE,
- bytesize=serial.EIGHTBITS
- )
- ser.isOpen()
- answer = "test"
- while 1 :
- answer = input("Select a spot:")
- if answer == 'exit':
- ser.close()
- exit()
- else:
- # send the character to the device
- # (note that I happend a \r\n carriage return and line feed to the characters - this is requested by my device)
- ser.write(answer.encode())
- out = ''
- # let's wait one second before reading output (let's give device time to answer)
- time.sleep(1)
- while ser.inWaiting() > 0:
- temp = ""
- out += str(ser.read(1),"utf-8")
- if out != '':
- print (">>" + out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement