接收前清空缓冲区
This commit is contained in:
13
scomm.py
13
scomm.py
@@ -20,6 +20,12 @@ def strnow():
|
|||||||
def tohex(b):
|
def tohex(b):
|
||||||
return ' '.join(['%02X'%x for x in b])
|
return ' '.join(['%02X'%x for x in b])
|
||||||
|
|
||||||
|
def uint16(b):
|
||||||
|
return b[0]*256+b[1]
|
||||||
|
def int16(b):
|
||||||
|
d = (b[0]*256+b[1])
|
||||||
|
return d>=0x80 and (d-0x10000) or d
|
||||||
|
|
||||||
class UIproc():
|
class UIproc():
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.root = app
|
self.root = app
|
||||||
@@ -115,7 +121,7 @@ class UIproc():
|
|||||||
#self.text_recv.insert(_i0, '\n'+text)
|
#self.text_recv.insert(_i0, '\n'+text)
|
||||||
for cb in self.root.unpack.values():
|
for cb in self.root.unpack.values():
|
||||||
try:
|
try:
|
||||||
if cb: text += '\n[%s] %s'%(cb['title'],eval(cb['value'], {"data":data}))
|
if cb: text += eval(cb['value'],{'data':data, 'uint16':uint16,'int16':int16}) or ''
|
||||||
except: pass
|
except: pass
|
||||||
self.text_recv.delete(_i0,'end')
|
self.text_recv.delete(_i0,'end')
|
||||||
_i0 = self.text_recv.index('end')
|
_i0 = self.text_recv.index('end')
|
||||||
@@ -208,6 +214,7 @@ class SerComm():
|
|||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
def receiveDataLoop(self):
|
def receiveDataLoop(self):
|
||||||
|
self.com.flush()
|
||||||
while not self.comProgressStop:
|
while not self.comProgressStop:
|
||||||
try:
|
try:
|
||||||
if self.com.is_open:
|
if self.com.is_open:
|
||||||
@@ -215,7 +222,7 @@ class SerComm():
|
|||||||
if data:
|
if data:
|
||||||
self.ui.log('%s: recv %s bytes: %s' % (self.com.port,len(data),str(data)))
|
self.ui.log('%s: recv %s bytes: %s' % (self.com.port,len(data),str(data)))
|
||||||
self.ui.dmesg('recv', data)
|
self.ui.dmesg('recv', data)
|
||||||
time.sleep(0.01)
|
time.sleep(0.05)
|
||||||
else:
|
else:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -277,8 +284,6 @@ class SerComm():
|
|||||||
self.com.write_timeout = 0
|
self.com.write_timeout = 0
|
||||||
self.com.inter_byte_timeout = 0
|
self.com.inter_byte_timeout = 0
|
||||||
self.com.open()
|
self.com.open()
|
||||||
self.com.reset_input_buffer()
|
|
||||||
self.com.reset_output_buffer()
|
|
||||||
self.ui.serial_open()
|
self.ui.serial_open()
|
||||||
self.ui.log('%s: open success' % self.com.port)
|
self.ui.log('%s: open success' % self.com.port)
|
||||||
self.comProgressStop = False
|
self.comProgressStop = False
|
||||||
|
|||||||
43
usercfg.json
43
usercfg.json
@@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"baud": "9600",
|
"baud": "9600",
|
||||||
"btn-data01": {
|
"btn-data01": {
|
||||||
"hex": 0,
|
"hex": 1,
|
||||||
"title": "\u63e1\u624b\u5305",
|
"title": "fan on",
|
||||||
"value": "hello"
|
"value": "01 10 30 12 00 01 02 00 01 54 E1"
|
||||||
},
|
},
|
||||||
"btn-data02": {
|
"btn-data02": {
|
||||||
"hex": 1,
|
"hex": 1,
|
||||||
"title": "HEX\u6d4b\u8bd5",
|
"title": "fan off",
|
||||||
"value": "01 02 03 04 05"
|
"value": "01 10 30 12 00 01 02 00 02 14 E0"
|
||||||
},
|
},
|
||||||
"btn-data03": {
|
"btn-data03": {
|
||||||
"hex": 0,
|
"hex": 1,
|
||||||
"title": "\u4e2d\u6587\u6d4b\u8bd5",
|
"title": "reboot",
|
||||||
"value": "\u82b1\u95f4\u4e00\u58f6\u9152\uff0c\u72ec\u914c\u65e0\u76f8\u4eb2\u3002\n\u4e3e\u676f\u9080\u660e\u6708\uff0c\u5bf9\u5f71\u6210\u4e09\u4eba\u3002\n\u6708\u65e2\u4e0d\u89e3\u996e\uff0c\u5f71\u5f92\u968f\u6211\u8eab\u3002\n\u6682\u4f34\u6708\u5c06\u5f71\uff0c\u884c\u4e50\u987b\u53ca\u6625\u3002\n\u6211\u6b4c\u6708\u5f98\u5f8a\uff0c\u6211\u821e\u5f71\u96f6\u4e71\u3002\n\u9192\u65f6\u76f8\u4ea4\u6b22\uff0c\u9189\u540e\u5404\u5206\u6563\u3002\n\u6c38\u7ed3\u65e0\u60c5\u6e38\uff0c\u76f8\u671f\u9088\u4e91\u6c49\u3002"
|
"value": "01 10 30 11 00 01 02 00 01 54 D2"
|
||||||
},
|
},
|
||||||
"btn-data04": {
|
"btn-data04": {
|
||||||
"hex": 0,
|
"hex": 0,
|
||||||
@@ -25,6 +25,21 @@
|
|||||||
"title": "reset RTS",
|
"title": "reset RTS",
|
||||||
"value": "{\"rts\":1,\"text\":\"\"}"
|
"value": "{\"rts\":1,\"text\":\"\"}"
|
||||||
},
|
},
|
||||||
|
"btn-data06": {
|
||||||
|
"hex": 1,
|
||||||
|
"title": "silent",
|
||||||
|
"value": "01 10 30 03 00 01 02 00 00 96 60"
|
||||||
|
},
|
||||||
|
"btn-data07": {
|
||||||
|
"hex": 1,
|
||||||
|
"title": "read.cfg",
|
||||||
|
"value": "01 03 30 00 00 16 5A EE"
|
||||||
|
},
|
||||||
|
"btn-data08": {
|
||||||
|
"hex": 1,
|
||||||
|
"title": "auto report",
|
||||||
|
"value": "01 10 30 03 00 01 02 00 01 57 A0"
|
||||||
|
},
|
||||||
"btn-unpack01": {
|
"btn-unpack01": {
|
||||||
"title": "HEX print",
|
"title": "HEX print",
|
||||||
"value": "' '.join(['%02X'%x for x in data])"
|
"value": "' '.join(['%02X'%x for x in data])"
|
||||||
@@ -33,8 +48,16 @@
|
|||||||
"title": "C style print",
|
"title": "C style print",
|
||||||
"value": "'\\\\x'+'\\\\x'.join('%02x'%x for x in data)"
|
"value": "'\\\\x'+'\\\\x'.join('%02x'%x for x in data)"
|
||||||
},
|
},
|
||||||
"cycle": "10",
|
"btn-unpack03": {
|
||||||
|
"title": "hex2dec[-3:-2]",
|
||||||
|
"value": "len(data)==26 and '\\t['+'%5d' % (data[-2]*256+data[-3])+']'"
|
||||||
|
},
|
||||||
|
"btn-unpack05": {
|
||||||
|
"title": "s17-eeprom",
|
||||||
|
"value": "'\\nad0fix=%s\\n' % (uint16(data[17:]))"
|
||||||
|
},
|
||||||
|
"cycle": "100",
|
||||||
"encoding": "gbk",
|
"encoding": "gbk",
|
||||||
"split": "99ms",
|
"split": "500",
|
||||||
"uservar": ""
|
"uservar": ""
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user