1111 from Combobox import ComboBox
1212 from i18n import _
1313 from widgets import TextEdit , PlainTextEdit
14- import utils_ui
14+ import utils , utils_ui
1515 from widgets import statusBar
1616 from widgets import EditRemarDialog
1717except ImportError :
@@ -75,6 +75,7 @@ def onInit(self, config):
7575 "version" : 1 ,
7676 "sendAscii" : True ,
7777 "useCRLF" : False ,
78+ "sendRecord" : False ,
7879 "sendEscape" : True ,
7980 "code" : defaultProtocols .copy (),
8081 "currCode" : "default" ,
@@ -266,18 +267,22 @@ def onWidgetSettings(self, parent):
266267 self .sendSettingsCRLF = QCheckBox (_ ("<CRLF>" ))
267268 self .sendSettingsCRLF .setToolTip (_ ("Select to send \\ r\\ n instead of \\ n" ))
268269 self .sendSettingsCRLF .setChecked (False )
270+ self .sendSettingsRecord = QCheckBox (_ ("Record" ))
271+ self .sendSettingsRecord .setToolTip (_ ("Record send data" ))
269272 self .sendSettingsEscape = QCheckBox (_ ("Escape" ))
270273 self .sendSettingsEscape .setToolTip (_ ("Enable escape characters support like \\ t \\ r \\ n \\ x01 \\ 001" ))
271274 serialSendSettingsLayout .addWidget (self .sendSettingsAscii ,0 ,0 ,1 ,1 )
272275 serialSendSettingsLayout .addWidget (self .sendSettingsHex ,0 ,1 ,1 ,1 )
273276 serialSendSettingsLayout .addWidget (self .sendSettingsCRLF , 1 , 0 , 1 , 1 )
274277 serialSendSettingsLayout .addWidget (self .sendSettingsEscape , 1 , 1 , 1 , 1 )
278+ serialSendSettingsLayout .addWidget (self .sendSettingsRecord , 2 , 0 , 1 , 1 )
275279
276280 rootLayout .addWidget (sendGroup )
277281 rootLayout .addWidget (setingGroup )
278282 # event
279283 self .sendSettingsAscii .clicked .connect (lambda : self .bindVar (self .sendSettingsAscii , self .config , "sendAscii" , bool ))
280284 self .sendSettingsHex .clicked .connect (lambda : self .bindVar (self .sendSettingsHex , self .config , "sendAscii" , bool , invert = True ))
285+ self .sendSettingsRecord .clicked .connect (lambda : self .bindVar (self .sendSettingsRecord , self .config , "sendRecord" , bool ))
281286 self .sendSettingsCRLF .clicked .connect (lambda : self .bindVar (self .sendSettingsCRLF , self .config , "useCRLF" , bool ))
282287 self .sendSettingsEscape .clicked .connect (lambda : self .bindVar (self .sendSettingsEscape , self .config , "sendEscape" , bool ))
283288 self .saveCodeBtn .clicked .connect (self .saveCode )
@@ -301,6 +306,7 @@ def onUiInitDone(self):
301306 self .config ["customSendItems" ] = newItems
302307 self .sendSettingsAscii .setChecked (self .config ["sendAscii" ])
303308 self .sendSettingsHex .setChecked (not self .config ["sendAscii" ])
309+ self .sendSettingsRecord .setChecked (self .config ["sendRecord" ])
304310 self .sendSettingsCRLF .setChecked (self .config ["useCRLF" ])
305311 self .sendSettingsEscape .setChecked (self .config ["sendEscape" ])
306312 self .showReceiveDataSignal .connect (self .showReceivedData )
@@ -471,11 +477,24 @@ def onReceived(self, data : bytes):
471477 plugin .onReceived (data )
472478 if type (data ) != str :
473479 data = self .decodeReceivedData (data , self .configGlobal ["encoding" ], not self .config ["sendAscii" ], self .config ["sendEscape" ])
474- self .showReceiveDataSignal .emit (data + "\n " )
480+ if self .config ["sendRecord" ]:
481+ head = '<= '
482+ self .showReceiveDataSignal .emit (head + data + "\n " )
483+ else :
484+ self .showReceiveDataSignal .emit (data + "\n " )
475485
476486 def sendData (self , data_bytes = None ):
477487 try :
478488 data_bytes = self .encodeMethod (data_bytes )
489+ if self .config ["sendRecord" ]:
490+ head = '=> '
491+ if not self .config ["sendAscii" ]:
492+ head += "[HEX] "
493+ sendStr = utils .hexlify (data_bytes , ' ' ).decode (encoding = self .configGlobal ["encoding" ])
494+ else :
495+ head += "[ASCII] "
496+ sendStr = data_bytes .decode (encoding = self .configGlobal ["encoding" ])
497+ self .showReceiveDataSignal .emit (head + sendStr + "\n " )
479498 except Exception as e :
480499 self .hintSignal .emit ("error" , _ ("Error" ), _ ("Run encode error" ) + " " + str (e ))
481500 return
0 commit comments