tuxmartin

topeni - UI

Jan 25th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import serial
  4.  
  5. # configure the serial connections (the parameters differs on the device you are connecting to)
  6. ser = serial.Serial(  # port='/dev/ttyUSB0',
  7.                       port='/dev/ttyUSB0',
  8.                       baudrate=9600,  #writeTimeout = 2,
  9.                       parity=serial.PARITY_NONE,
  10.                       stopbits=serial.STOPBITS_ONE,
  11.                       bytesize=serial.EIGHTBITS
  12. )
  13.  
  14. try:  # pokud uz byl port ortevreny, zkusim ho zavrit
  15.     if ser.isOpen():
  16.         ser.close()
  17. except Exception, e:
  18.     print "error open serial port: " + str(e)
  19.     exit()
  20.  
  21. try:
  22.     ser.open()
  23. except Exception, e:
  24.     print "error open serial port: " + str(e)
  25.     exit()
  26.  
  27. if ser.isOpen():
  28.     ser.flushInput()  # flush input buffer, discarding all its contents
  29.     ser.flushOutput()  # flush output buffer, aborting current output
  30.  
  31.     t1 = float( raw_input("Zadej teplotu 1: ") )
  32.     t2 = float( raw_input("Zadej teplotu 2: ") )
  33.     print "Teplota 1=", t1
  34.     print "Teplota 2=", t2
  35.  
  36.     t1a = int(t1 / 256)
  37.     t1b = int(t1 % 256)
  38.  
  39.     t2a = int(t2 / 256)
  40.     t2b = int(t2 % 256)
  41.  
  42.     teploty = str(t1a) + "," + str(t1b) + "," + str(t2a) + "," + str(t2b)
  43.     poslat = '<EEPROM,0,100,200,2,3,4,5,' + teploty + '>'
  44.     print "POSILAM: " + poslat
  45.  
  46.     ser.write(poslat)
  47.     #ser.write("<EEPROM,0,100,200,2,3,4,5,    0,190,0,231>")
  48.     ser.flushOutput()
  49.  
  50. else:
  51.     print "cannot open serial port "
  52.  
  53.  
  54.  
  55. # ----------------------- VYSTUP:
  56. /usr/bin/python2.7 /home/martin/PycharmProjects/topeni/topeni.py
  57. Zadej teplotu 1: 23.9
  58. Zadej teplotu 2: 24.1
  59. Teplota 1= 23.9
  60. Teplota 2= 24.1
  61. POSILAM: <EEPROM,0,100,200,2,3,4,5,0,23,0,24>
  62.  
  63. Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment