bacup codes
This commit is contained in:
21
scomm.py
21
scomm.py
@@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
import os,sys,json
|
import os,sys,json,string
|
||||||
import serial
|
import serial
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
import tkinter
|
import tkinter
|
||||||
@@ -19,6 +19,8 @@ def strnow():
|
|||||||
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
||||||
def tohex(b):
|
def tohex(b):
|
||||||
return ' '.join(['%02X'%x for x in b])
|
return ' '.join(['%02X'%x for x in b])
|
||||||
|
def human_string(data, is_hex=False, encoding=False):
|
||||||
|
return is_hex and tohex(data) or data.decode(encoding,'ignore')
|
||||||
|
|
||||||
def uint16(b):
|
def uint16(b):
|
||||||
return b[0]*256+b[1]
|
return b[0]*256+b[1]
|
||||||
@@ -102,7 +104,7 @@ class UIproc():
|
|||||||
_i0,fg='end','black'
|
_i0,fg='end','black'
|
||||||
if cate == 'send' and self.ckbtn_sendshow.var.get():
|
if cate == 'send' and self.ckbtn_sendshow.var.get():
|
||||||
text += MARK('> ')
|
text += MARK('> ')
|
||||||
text += self.ckbtn_shex.var.get() and tohex(data) or data.decode(encoding, 'ignore')
|
text += human_string(data, self.ckbtn_shex.var.get(), encoding)
|
||||||
_i0 = self.text_recv.index('end')
|
_i0 = self.text_recv.index('end')
|
||||||
self.text_recv.insert('end', '\n%s'%text.translate({0:'<00>'}))
|
self.text_recv.insert('end', '\n%s'%text.translate({0:'<00>'}))
|
||||||
self.lastRecvTicks = 0
|
self.lastRecvTicks = 0
|
||||||
@@ -113,13 +115,13 @@ class UIproc():
|
|||||||
self.lastCursor = self.text_recv.index('end')
|
self.lastCursor = self.text_recv.index('end')
|
||||||
self.lastRecvData = data
|
self.lastRecvData = data
|
||||||
text += MARK('< ')
|
text += MARK('< ')
|
||||||
text += self.ckbtn_rhex.var.get() and tohex(data) or data.decode(encoding, 'ignore')
|
text += human_string(data, self.ckbtn_rhex.var.get(), encoding)
|
||||||
#self.text_recv.insert('end', '\n'+text)
|
#self.text_recv.insert('end', '\n'+text)
|
||||||
else:
|
else:
|
||||||
data = self.lastRecvData + data
|
data = self.lastRecvData + data
|
||||||
self.lastRecvData = data
|
self.lastRecvData = data
|
||||||
text += MARK('< ')
|
text += MARK('< ')
|
||||||
text += self.ckbtn_rhex.var.get() and tohex(data) or data.decode(encoding, 'ignore')
|
text += human_string(data, self.ckbtn_rhex.var.get(), encoding)
|
||||||
_i0 = self.lastCursor
|
_i0 = self.lastCursor
|
||||||
#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():
|
||||||
@@ -128,7 +130,7 @@ class UIproc():
|
|||||||
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')
|
||||||
self.text_recv.insert(_i0, '\n%s'%text.translate({0:'<00>'}))
|
self.text_recv.insert(_i0, '\n%s'%str(text))
|
||||||
self.lastRecvTicks = ts
|
self.lastRecvTicks = ts
|
||||||
fg='blue'
|
fg='blue'
|
||||||
_i1 = self.text_recv.index('end')
|
_i1 = self.text_recv.index('end')
|
||||||
@@ -315,7 +317,12 @@ class SerComm():
|
|||||||
self.ui.log('%s: openClose trace' % (self.com.port))
|
self.ui.log('%s: openClose trace' % (self.com.port))
|
||||||
|
|
||||||
def clearWin(self):
|
def clearWin(self):
|
||||||
self.ui.clear_recvtext()
|
if self.com.is_open:
|
||||||
|
self.com.is_open = False
|
||||||
|
self.ui.clear_recvtext()
|
||||||
|
self.com.is_open = True
|
||||||
|
else:
|
||||||
|
self.ui.clear_recvtext()
|
||||||
|
|
||||||
def saveFile(self):
|
def saveFile(self):
|
||||||
self.ui.save_recvtext()
|
self.ui.save_recvtext()
|
||||||
@@ -457,7 +464,7 @@ if __name__ == '__main__':
|
|||||||
root.entry('entry-split').set(root.usercfg.get('split','99ms'))
|
root.entry('entry-split').set(root.usercfg.get('split','99ms'))
|
||||||
root.entry('entry-cycle').set(root.usercfg.get('cycle','1024ms'))
|
root.entry('entry-cycle').set(root.usercfg.get('cycle','1024ms'))
|
||||||
root.entry('entry-baud').set(root.usercfg.get('baud','9600'))
|
root.entry('entry-baud').set(root.usercfg.get('baud','9600'))
|
||||||
root.entry('entry-encoding').set(root.usercfg.get('encoding','gbk'))
|
root.entry('entry-encoding').set(root.usercfg.get('encoding','utf8'))
|
||||||
root.entry('entry-uservar').set(root.usercfg.get('uservar',''))
|
root.entry('entry-uservar').set(root.usercfg.get('uservar',''))
|
||||||
root.entry('entry-sendText', key='<Return>', cmd=lambda x:comm.sendData()).set('')
|
root.entry('entry-sendText', key='<Return>', cmd=lambda x:comm.sendData()).set('')
|
||||||
root.button('btn-scan', cmd=lambda:comm.detectSerialPort())
|
root.button('btn-scan', cmd=lambda:comm.detectSerialPort())
|
||||||
|
|||||||
32
usercfg.json
32
usercfg.json
@@ -2,18 +2,18 @@
|
|||||||
"baud": "9600",
|
"baud": "9600",
|
||||||
"btn-data01": {
|
"btn-data01": {
|
||||||
"hex": 1,
|
"hex": 1,
|
||||||
"title": "DOWN",
|
"title": "\u88ab\u52a8\u6a21\u5f0f",
|
||||||
"value": "55 AA 0A FC 01 10 01 01 10 02 01 00 05 EE EE"
|
"value": " 0A 00 35 00 02 04 02 06 01 44 18"
|
||||||
},
|
},
|
||||||
"btn-data02": {
|
"btn-data02": {
|
||||||
"hex": 1,
|
"hex": 1,
|
||||||
"title": "UP",
|
"title": "\u5de1\u68c0\u6a21\u5f0f",
|
||||||
"value": "55 AA 0A FC 01 10 01 01 10 02 01 00 04 EE EE"
|
"value": "0A 00 35 01 02 04 02 06 01 6F 1C"
|
||||||
},
|
},
|
||||||
"btn-data03": {
|
"btn-data03": {
|
||||||
"hex": 1,
|
"hex": 1,
|
||||||
"title": "reboot",
|
"title": "F3\u5de1\u68c0",
|
||||||
"value": "55 AA 0A FC 01 10 01 01 10 04 01 01 FF EE EE"
|
"value": "5A A5 07 A2 A4 10 10 00 01 F3 EE EE"
|
||||||
},
|
},
|
||||||
"btn-data04": {
|
"btn-data04": {
|
||||||
"hex": 0,
|
"hex": 0,
|
||||||
@@ -26,19 +26,19 @@
|
|||||||
"value": "{\"dtr\":1,\"rts\":1,\"hex\":\"18FF\"}"
|
"value": "{\"dtr\":1,\"rts\":1,\"hex\":\"18FF\"}"
|
||||||
},
|
},
|
||||||
"btn-data06": {
|
"btn-data06": {
|
||||||
"hex": 0,
|
"hex": 1,
|
||||||
"title": "random",
|
"title": "F1\u91cd\u542f",
|
||||||
"value": "'%s'%__import__('random').random()"
|
"value": "5A A5 07 FE A1 10 10 00 01 F1 EE EE\n"
|
||||||
},
|
},
|
||||||
"btn-data07": {
|
"btn-data07": {
|
||||||
"hex": 1,
|
"hex": 1,
|
||||||
"title": "wake",
|
"title": "\u5f00\u9501F3-0022",
|
||||||
"value": "55 AA 0A FC 01 10 01 01 10 04 01 03 00 EE EE\n"
|
"value": "5A A5 14 A2 A4 10 20 00 0E 12 0C 5A A5 07 00 16 10 10 04 01 03 FF EE FF EE"
|
||||||
},
|
},
|
||||||
"btn-data08": {
|
"btn-data08": {
|
||||||
"hex": 1,
|
"hex": 1,
|
||||||
"title": "page1",
|
"title": "R:2000+18",
|
||||||
"value": "55 AA 0A FC 01 10 01 01 10 04 01 02 01 EE EE\n"
|
"value": "5A A5 06 FE A1 03 20 00 18 EE EE"
|
||||||
},
|
},
|
||||||
"btn-unpack01": {
|
"btn-unpack01": {
|
||||||
"title": "HEX print",
|
"title": "HEX print",
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
"value": "len(data)>=25 and data[2]==0x14 and '\\n\\K=%s\\nKuser=%s\\nad0fix=%s\\nmlevel=%s\\nfofactor=%s\\nKntc=%s\\n' % (\nuint16(data[9:]),\nuint16(data[11:]),\nuint16(data[13:]),\nuint16(data[15:]),\nuint16(data[17:]),\nuint16(data[19:]))\n\n"
|
"value": "len(data)>=25 and data[2]==0x14 and '\\n\\K=%s\\nKuser=%s\\nad0fix=%s\\nmlevel=%s\\nfofactor=%s\\nKntc=%s\\n' % (\nuint16(data[9:]),\nuint16(data[11:]),\nuint16(data[13:]),\nuint16(data[15:]),\nuint16(data[17:]),\nuint16(data[19:]))\n\n"
|
||||||
},
|
},
|
||||||
"cycle": "100",
|
"cycle": "100",
|
||||||
"encoding": "gbk",
|
"encoding": "utf8",
|
||||||
"split": "100",
|
"split": "50",
|
||||||
"uservar": "HELLO"
|
"uservar": "2,32200,0,0"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user