加入接收回调支持
This commit is contained in:
27
scomm.py
27
scomm.py
@@ -62,19 +62,28 @@ class UIproc():
|
||||
self.lastCursor = "end"
|
||||
self.lastRecvData = b''
|
||||
elif cate == 'recv':
|
||||
_ic = 'end'
|
||||
if(ts-self.lastRecvTicks>splitms):
|
||||
self.lastCursor = self.text_recv.index('end')
|
||||
self.lastRecvData = data
|
||||
text += '< '
|
||||
text += self.ckbtn_rhex.var.get() and tohex(data) or data.decode(encoding, 'ignore')
|
||||
self.text_recv.insert('end', '\n'+text)
|
||||
#self.text_recv.insert('end', '\n'+text)
|
||||
#print('##### todo:recv1 = %sbytes'%len(data))
|
||||
else:
|
||||
data = self.lastRecvData + data
|
||||
self.lastRecvData = data
|
||||
text += '< '
|
||||
text += self.ckbtn_rhex.var.get() and tohex(data) or data.decode(encoding, 'ignore')
|
||||
_i0 = self.lastCursor
|
||||
_i0 = self.lastCursor; _ic = _i0
|
||||
self.text_recv.delete(_i0,'end')
|
||||
self.text_recv.insert(_i0, '\n'+text)
|
||||
#self.text_recv.insert(_i0, '\n'+text)
|
||||
#print('##### todo:recv2 = %sbytes'%len(data))
|
||||
for cb in self.root.unpack.values():
|
||||
try:
|
||||
if cb: text += '\n[%s] %s'%(cb['title'],eval(cb['value'], {"data":data}))
|
||||
except: pass
|
||||
self.text_recv.insert(_ic, '\n'+text)
|
||||
self.lastRecvTicks = ts
|
||||
bg,fg='','blue'
|
||||
_i1 = self.text_recv.index('end')
|
||||
@@ -152,12 +161,11 @@ class SerComm():
|
||||
if True:
|
||||
data = self.com.read(self.com.in_waiting)
|
||||
if data:
|
||||
self.ui.log('%s: recv %s bytes: %s...' % (self.com.port,len(data),str(data)[:-1]))
|
||||
self.ui.log('%s: recv %s bytes: %s...' % (self.com.port,len(data),str(data)[:16]))
|
||||
self.ui.dmesg('recv', data)
|
||||
time.sleep(0.050)
|
||||
time.sleep(0.01)
|
||||
#except Exception as e:
|
||||
else:
|
||||
self.ui.log('%s: receive trace: %s' % (self.com.port,str(e)))
|
||||
# self.ui.log('%s: receive trace: %s' % (self.com.port,str(e)))
|
||||
|
||||
def sendData(self):
|
||||
#try:
|
||||
@@ -170,7 +178,7 @@ class SerComm():
|
||||
self.com.write(data)
|
||||
self.sendCount += len(data)
|
||||
self.ui.dmesg('send', data)
|
||||
self.ui.log('%s: send %s bytes: %s...' % (self.com.port,len(data),str(data)[:-1]))
|
||||
self.ui.log('%s: send %s bytes: %s...' % (self.com.port,len(data),str(data)[:16]))
|
||||
# scheduled send
|
||||
#if self.sendSettingsScheduledCheckBox.isChecked():
|
||||
# if not self.isScheduledSending:
|
||||
@@ -252,8 +260,7 @@ class TopWin():
|
||||
self.root.get('ckbtn-shex').var.set(_cfg.get('hex') and 1 or 0)
|
||||
self.root.get('btn-send').invoke()
|
||||
def set_unpack(self, btn):
|
||||
self.root.unpack[btn] = self.root.get(btn).var.get() and self.root.usercfg.get(btn,{}).get('value') or None
|
||||
print(self.root.unpack)
|
||||
self.root.unpack[btn] = self.root.get(btn).var.get() and self.root.usercfg.get(btn) or None
|
||||
def save_cfg(self, btn, dat):
|
||||
with open('usercfg.json', 'wb+') as f:
|
||||
self.root.usercfg[btn] = dat
|
||||
|
||||
30
usercfg.json
30
usercfg.json
@@ -14,36 +14,8 @@
|
||||
"title": "\u4e2d\u6587\u6d4b\u8bd5",
|
||||
"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"
|
||||
},
|
||||
"btn-pack01": {
|
||||
"title": "btn-pack01",
|
||||
"value": ""
|
||||
},
|
||||
"btn-pack03": {
|
||||
"title": "btn-pack03",
|
||||
"value": ""
|
||||
},
|
||||
"btn-pack04": {
|
||||
"title": "btn-pack04",
|
||||
"value": ""
|
||||
},
|
||||
"btn-unpack01": {
|
||||
"title": "HEX print",
|
||||
"value": "''.join(['%02X'%x for x in data])"
|
||||
},
|
||||
"btn-unpack02": {
|
||||
"title": "btn-unpack02",
|
||||
"value": ""
|
||||
},
|
||||
"btn-unpack03": {
|
||||
"title": "btn-unpack03",
|
||||
"value": ""
|
||||
},
|
||||
"btn-unpack04": {
|
||||
"title": "btn-unpack04",
|
||||
"value": ""
|
||||
},
|
||||
"btn-unpack05": {
|
||||
"title": "btn-unpack05",
|
||||
"value": ""
|
||||
"value": "' '.join(['%02X'%x for x in data])"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user