Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import serial
- # configure the serial connections (the parameters differs on the device you are connecting to)
- ser = serial.Serial( # port='/dev/ttyUSB0',
- port='/dev/ttyUSB0',
- baudrate=9600, #writeTimeout = 2,
- parity=serial.PARITY_NONE,
- stopbits=serial.STOPBITS_ONE,
- bytesize=serial.EIGHTBITS
- )
- try: # pokud uz byl port ortevreny, zkusim ho zavrit
- if ser.isOpen():
- ser.close()
- except Exception, e:
- print "error open serial port: " + str(e)
- exit()
- try:
- ser.open()
- except Exception, e:
- print "error open serial port: " + str(e)
- exit()
- if ser.isOpen():
- ser.flushInput() # flush input buffer, discarding all its contents
- ser.flushOutput() # flush output buffer, aborting current output
- t1 = float( raw_input("Zadej teplotu 1: ") )
- t2 = float( raw_input("Zadej teplotu 2: ") )
- print "Teplota 1=", t1
- print "Teplota 2=", t2
- t1a = int(t1 / 256)
- t1b = int(t1 % 256)
- t2a = int(t2 / 256)
- t2b = int(t2 % 256)
- teploty = str(t1a) + "," + str(t1b) + "," + str(t2a) + "," + str(t2b)
- poslat = '<EEPROM,0,100,200,2,3,4,5,' + teploty + '>'
- print "POSILAM: " + poslat
- ser.write(poslat)
- #ser.write("<EEPROM,0,100,200,2,3,4,5, 0,190,0,231>")
- ser.flushOutput()
- else:
- print "cannot open serial port "
- # ----------------------- VYSTUP:
- /usr/bin/python2.7 /home/martin/PycharmProjects/topeni/topeni.py
- Zadej teplotu 1: 23.9
- Zadej teplotu 2: 24.1
- Teplota 1= 23.9
- Teplota 2= 24.1
- POSILAM: <EEPROM,0,100,200,2,3,4,5,0,23,0,24>
- Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment