diff --git a/README.md b/README.md index cc89fb1..fb1dc68 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # scomm串口调试助手(Mac/Linux/Windows) -一款跨平台串口调试助手,助力Mac/Linux平台下的嵌入式开发。 +一款跨平台串口调试助手,助力Mac/Linux/Windows平台下的嵌入式开发。 ## 功能特色 @@ -56,6 +56,14 @@ python scomm.py 鼠标右键/中键选择对应预置数据按钮,可以打开编辑对话框。 HEX格式请注意检测数据是否有效,程序中未对数据有效性作检查。 +亦可按照字典形式设置流控等功能。 + +```json +# 设置RTS pin为高电平,同时发送hex字符串: 0x55 0xAA +# 注意:RTS/DTR引脚低电平有效 +{"rts":0, "text":"55 AA", "hex":1} +``` + ## 预置变量 以逗号分割的字符串数组变量,传递给预置数据。 diff --git a/scomm.py b/scomm.py index b4014b4..57e6fdb 100755 --- a/scomm.py +++ b/scomm.py @@ -44,17 +44,30 @@ class UIproc(): self.lastRecvTicks = 0 self.lastCursor = "end" self.lastRecvData = b'' - self.wait_sendData = b'' + self.wait_sendData = {'text':b'', 'rts':None, 'dtr':None} self._lock_dmesg = False self.event_init() + def setSendData(self, text=None, encoding=None, HEX=None, RTS=None, DTR=None): + if type(text) == type(''): + self.entry_sendText.var.set(text) + if type(encoding) == type(''): + self.entry_encoding.var.set(encoding) + if type(HEX) == type(1): + self.ckbtn_shex.var.set(HEX and 1 or 0) + self.wait_sendData['rts'] = RTS + self.wait_sendData['dtr'] = DTR def getSendData(self, cache=True): if not cache: + if self.root.pack: + self.log('send.data.pack:%s'%self.root.pack) + self.setSendData(**self.root.pack) + self.root.pack = None data = self.entry_sendText.var.get() encoding = self.entry_encoding.var.get() dat = self.ckbtn_shex.var.get() and bytes.fromhex(data) or data.encode(encoding, 'ignore') dat += self.ckbtn_0d.var.get() and b'\r' or b'' dat += self.ckbtn_0a.var.get() and b'\n' or b'' - self.wait_sendData = dat + self.wait_sendData['text'] = dat return self.wait_sendData def getSendDataLoop(self): while True: @@ -193,7 +206,8 @@ class SerComm(): while not self.comProgressStop: try: if self.com.is_open and self.ui.send_waitting(): - data = self.ui.getSendData(cache=True) + _data = self.ui.getSendData(cache=True) + data = _data.get('text') if data and len(data) > 0: self.com.write(data) self.sendCount += len(data) @@ -208,7 +222,18 @@ class SerComm(): if not self.com.is_open: self.ui.log('Serial Port not open') else: - data = self.ui.getSendData(cache=False) + _data = self.ui.getSendData(cache=False) + rts = _data.get('rts') + dtr = _data.get('dtr') + data = _data.get('text') + if type(rts) == type(True): + self.com.rts = rts + self.ui.log('%s: set rts=%s' % (self.com.port,rts)) + self.ui.setSendData(RTS=None) + if type(dtr) == type(True): + self.com.dtr = dtr + self.ui.log('%s: set dtr=%s' % (self.com.port,dtr)) + self.ui.setSendData(DTR=None) if data and len(data) > 0: self.com.write(data) self.sendCount += len(data) @@ -284,6 +309,7 @@ class TopWin(): def __init__(self, root): self.root = root self.root.unpack = {} + self.root.pack = None self.WinData = None self.WinPack = None self.WinUnpack = None @@ -294,8 +320,18 @@ class TopWin(): try: val = eval(val, {"data":self.root.get('entry-uservar').var.get().split(',')}) except: pass - self.root.get('entry-sendText').var.set(val) - self.root.get('ckbtn-shex').var.set(_cfg.get('hex') and 1 or 0) + if type(val) == type({}): + self.root.pack = { + 'text':val.get('text'), + 'encoding':val.get('encoding'), + 'HEX':val.get('hex') + } + if 'rts' in val: + self.root.pack['RTS'] = bool(val.get('rts')) + if 'dtr' in val: + self.root.pack['DTR'] = bool(val.get('dtr')) + else: + self.root.pack = {'text':val,'HEX':_cfg.get('hex')} 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) or None diff --git a/usercfg.json b/usercfg.json index aa83ce0..b0161b1 100644 --- a/usercfg.json +++ b/usercfg.json @@ -14,6 +14,16 @@ "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-data04": { + "hex": 0, + "title": "set RTS", + "value": "{\"rts\":0,\"text\":\"1B\",\"hex\":1}" + }, + "btn-data05": { + "hex": 0, + "title": "reset RTS", + "value": "{\"rts\":1,\"text\":\"\"}" + }, "btn-unpack01": { "title": "HEX print", "value": "' '.join(['%02X'%x for x in data])"