reflow/reflowctl/serialmon.py

82 lines
1.5 KiB
Python
Raw Permalink Normal View History

2012-11-18 14:40:32 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
import serial, struct, time
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=2)
buf = ""
alles = []
#def parse():
#buffer = list()
#while 1:
#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)