Advertisement
Guest User

Untitled

a guest
Aug 12th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import time
  2. import serial
  3.  
  4. ser = serial.Serial(
  5.     port='/dev/ttyO4',
  6.     baudrate=9600,
  7.     parity=serial.PARITY_ODD,
  8.     stopbits=serial.STOPBITS_TWO,
  9.     bytesize=serial.SEVENBITS
  10. )
  11.  
  12. ser.open()
  13. ser.isOpen()
  14.  
  15. print 'Enter your commands below.\r\nEnter "exit" to leave the application.'
  16.  
  17. input=1
  18. while 1 :
  19.     # get keyboard input
  20.     input = raw_input(">> ")
  21.     if input == 'exit':
  22.         ser.close()
  23.         exit()
  24.     else:
  25.         # send the character to the device
  26.         ser.write(input + '\r\n')
  27.         out = ''
  28.         # wait 1 second before reading output
  29.         time.sleep(1)
  30.         while ser.inWaiting() > 0:
  31.             out += ser.read(1)
  32.            
  33.         if out != '':
  34.             print ">>" + out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement