2012-10-02 15:46:12 +00:00
|
|
|
#!/usr/bin/python
|
2012-10-26 06:45:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-10-02 15:46:12 +00:00
|
|
|
|
2012-10-26 06:45:05 +00:00
|
|
|
import serial, struct, time
|
2012-10-25 15:07:09 +00:00
|
|
|
|
2012-10-26 06:45:05 +00:00
|
|
|
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=2)
|
|
|
|
|
|
|
|
|
|
|
|
buf = ""
|
|
|
|
alles = []
|
|
|
|
|
|
|
|
#def parse():
|
|
|
|
#buffer = list()
|
2012-10-25 15:07:09 +00:00
|
|
|
#while 1:
|
2012-10-26 06:45:05 +00:00
|
|
|
#try:
|
|
|
|
#i = ser.read(1)
|
|
|
|
#if ord(i) == 255:
|
|
|
|
#except Exception, e:
|
|
|
|
#print e
|
|
|
|
#else:
|
|
|
|
|
|
|
|
def recv_config():
|
|
|
|
ser.write(chr(255))
|
|
|
|
ser.flush()
|
|
|
|
read(30)
|
|
|
|
ser.flushInput()
|
|
|
|
data = struct.unpack("hhhhhhhhhhhhhhh", buf)
|
|
|
|
print
|
|
|
|
print "Profile:"
|
|
|
|
print "ts_min:", data[0]
|
|
|
|
print "ts_max:", data[1]
|
|
|
|
print "tl:", data[2]
|
|
|
|
print "tp:", data[3]
|
|
|
|
print "time_max:", data[4]
|
|
|
|
print "ramp_up_min:", data[5]
|
|
|
|
print "ramp_up_max:", data[6]
|
|
|
|
print "ramp_down_min:", data[7]
|
|
|
|
print "ramp_down_max:", data[8]
|
|
|
|
|
|
|
|
print "ts_duration_min:", data[9]
|
|
|
|
print "ts_duration_max:", data[10]
|
|
|
|
print "tl_duration_min:", data[11]
|
|
|
|
print "tl_duration_max:", data[12]
|
|
|
|
print "tp_duration_min:", data[13]
|
|
|
|
print "tp_duration_max:", data[14]
|
|
|
|
print
|
|
|
|
|
|
|
|
|
|
|
|
def recv_state():
|
|
|
|
ser.write(chr(254))
|
|
|
|
ser.flush()
|
|
|
|
read(11)
|
|
|
|
data = struct.unpack("hhhhhb", buf)
|
|
|
|
print "time: %ds, temperature: %d°C, last temperature: %d°C, state: %d, error condition: %d, heating: %d" % data
|
|
|
|
|
|
|
|
|
|
|
|
def send_config():
|
|
|
|
ser.write(chr(253))
|
|
|
|
ser.write(buf)
|
|
|
|
ser.flushInput()
|
|
|
|
|
|
|
|
|
|
|
|
def read(l):
|
|
|
|
global buf
|
|
|
|
global alles
|
|
|
|
buf = ""
|
|
|
|
while len(buf) < l:
|
|
|
|
try:
|
|
|
|
buf += ser.read(l)
|
|
|
|
alles.append(buf)
|
|
|
|
except Exception, e:
|
|
|
|
print e
|
|
|
|
ser.flushInput()
|
|
|
|
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
recv_config()
|
|
|
|
while 1:
|
|
|
|
recv_state()
|
|
|
|
time.sleep(1)
|
2012-10-25 15:07:09 +00:00
|
|
|
|