def __init__(self, name, port, baudrate, interval, handleTask = None): self._name = name self._port = port self._baudrate = baudrate self._interval = interval self._device_set = deviceSet.deviceSet(name) import copy self._cycleList = copy.deepcopy(self._device_set.getCmdSet()) self._cycleList.append({"id" : 0, "cmd" : "", "dev_id" : -1}) self._ctrlCmdList = [] self._ctrlCmdLock = threading.Lock() self._errorList = [] self._errorStartTime = time.time() self._resultQueue = multiprocessing.Queue() self._taskQueue = multiprocessing.Queue() self._rlock = multiprocessing.Lock() self._tlock = multiprocessing.Lock() self._com = None self._handleTask = handleTask self._alive = False
u'空调外机通道' : '/dev/ttyUSB0', } def HexToString(array): snd = '' for i in array: snd += '%02x' % i return snd sqlConnection = torndb.Connection("127.0.0.1:3306", "smarthome", user = "******", password = "******") sql = 'select * from sessions' mset = sqlConnection.query(sql) for item in mset: print item['session_name'] print item['session_id'] add = deviceSet(item['session_name']) line_cmdList = [] cmdCount = 0 for cmd in add.getCmdSet(): print cmd cmdCount += 1 line_cmdList.append({"id" : (++cmdCount), "cmd" : HexToString(cmd), "nbcount" : 0}) # print port_dict[item['session_name']] try : print item['session_name'],line_cmdList if len(line_cmdList) != 0: session = Session(port_dict[item['session_name']], 9600, line_cmdList, 0.5,add) server.addSession(port_dict[item['session_name']], session) except : pass