加入预置变量功能支持
This commit is contained in:
23
README.md
23
README.md
@@ -7,19 +7,20 @@
|
|||||||
2. 接收数据,自定义脚本解析输出
|
2. 接收数据,自定义脚本解析输出
|
||||||
3. 数据显示,自定义文本编码
|
3. 数据显示,自定义文本编码
|
||||||
4. 预置数据,快速编辑、一键发送
|
4. 预置数据,快速编辑、一键发送
|
||||||
5. 接收数据,自定义分帧间隔
|
5. 预置变量,传递参数给预置数据
|
||||||
6. 串口开关状态灯指示
|
6. 接收数据,自定义分帧间隔
|
||||||
7. HEX格式、时间戳、循环发送、保存文件等
|
7. 串口开关状态灯指示
|
||||||
|
8. HEX格式、时间戳、循环发送、保存文件等
|
||||||
|
|
||||||
|
|
||||||
## 安装运行
|
## 安装运行
|
||||||
```bash
|
```bash
|
||||||
# install python3
|
# install python3
|
||||||
python3 scomm.py
|
python scomm.py
|
||||||
|
|
||||||
# windows下安装py2exe可导出成exe文件
|
# windows下安装py2exe可导出成exe文件
|
||||||
# pip install pyyaml pyserial py2exe
|
# pip install pyyaml pyserial py2exe
|
||||||
# python3 setup.py py2exe
|
# python setup.py py2exe
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -56,6 +57,18 @@ python3 scomm.py
|
|||||||
HEX格式请注意检测数据是否有效,程序中未对数据有效性作检查。
|
HEX格式请注意检测数据是否有效,程序中未对数据有效性作检查。
|
||||||
|
|
||||||
|
|
||||||
|
## 预置变量
|
||||||
|
以逗号分割的字符串数组变量,传递给预置数据。
|
||||||
|
调用*eval*函数解析预置数据并发送执行结果。
|
||||||
|
|
||||||
|
```python
|
||||||
|
# data为预置变量字符数组
|
||||||
|
# 例如预置数据如下,选中HEX格式,预置变量设置为"1,3"
|
||||||
|
# 则对应要发送的数据解析为55 AA 03 F8 01 EE
|
||||||
|
"55 AA 03 F8 5A %02X EE" % int(data[0])
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## 分帧间隔
|
## 分帧间隔
|
||||||
电脑端系统驱动层有数据接收缓存,不能保证接收到的数据都是按数据帧分开的。
|
电脑端系统驱动层有数据接收缓存,不能保证接收到的数据都是按数据帧分开的。
|
||||||
请合理设置分帧间隔字段,以确保数据显示符合预期。
|
请合理设置分帧间隔字段,以确保数据显示符合预期。
|
||||||
|
|||||||
19
app.ui
19
app.ui
@@ -174,11 +174,17 @@
|
|||||||
"column": 2,
|
"column": 2,
|
||||||
"row": 20
|
"row": 20
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name":"label-uservar",
|
||||||
|
"text":"预置变量:",
|
||||||
|
"column": 2,
|
||||||
|
"row": 40
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name":"label-encoding",
|
"name":"label-encoding",
|
||||||
"text":"数据编码:",
|
"text":"数据编码:",
|
||||||
"column": 2,
|
"column": 2,
|
||||||
"row": 40
|
"row": 42
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Entry":[
|
"Entry":[
|
||||||
@@ -186,6 +192,11 @@
|
|||||||
"name":"entry-encoding",
|
"name":"entry-encoding",
|
||||||
"width":10,
|
"width":10,
|
||||||
"column": 2,
|
"column": 2,
|
||||||
|
"row": 43
|
||||||
|
},{
|
||||||
|
"name":"entry-uservar",
|
||||||
|
"width":10,
|
||||||
|
"column": 2,
|
||||||
"row": 41
|
"row": 41
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -269,12 +280,6 @@
|
|||||||
"text":"data-08",
|
"text":"data-08",
|
||||||
"column": 2,
|
"column": 2,
|
||||||
"row": 28
|
"row": 28
|
||||||
},
|
|
||||||
{
|
|
||||||
"name":"btn-data09",
|
|
||||||
"text":"data-09",
|
|
||||||
"column": 2,
|
|
||||||
"row": 29
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
10
scomm.py
10
scomm.py
@@ -291,6 +291,9 @@ class TopWin():
|
|||||||
_cfg = self.root.usercfg.get(btn, {})
|
_cfg = self.root.usercfg.get(btn, {})
|
||||||
if _cfg:
|
if _cfg:
|
||||||
val = _cfg.get('value')
|
val = _cfg.get('value')
|
||||||
|
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('entry-sendText').var.set(val)
|
||||||
self.root.get('ckbtn-shex').var.set(_cfg.get('hex') and 1 or 0)
|
self.root.get('ckbtn-shex').var.set(_cfg.get('hex') and 1 or 0)
|
||||||
self.root.get('btn-send').invoke()
|
self.root.get('btn-send').invoke()
|
||||||
@@ -301,7 +304,6 @@ class TopWin():
|
|||||||
self.root.usercfg[btn] = dat
|
self.root.usercfg[btn] = dat
|
||||||
encoding = self.root.get('entry-encoding').var.get()
|
encoding = self.root.get('entry-encoding').var.get()
|
||||||
f.write(json.dumps(self.root.usercfg,indent=4,sort_keys=True).encode(encoding,'ignore'))
|
f.write(json.dumps(self.root.usercfg,indent=4,sort_keys=True).encode(encoding,'ignore'))
|
||||||
self.set_unpack(btn)
|
|
||||||
self.root.get(btn).configure(text=dat.get('title'))
|
self.root.get(btn).configure(text=dat.get('title'))
|
||||||
def win_data(self, event):
|
def win_data(self, event):
|
||||||
def _save(w):
|
def _save(w):
|
||||||
@@ -324,6 +326,7 @@ class TopWin():
|
|||||||
dat = {'title':self.root.get('entry-ufile').var.get()}
|
dat = {'title':self.root.get('entry-ufile').var.get()}
|
||||||
dat['value'] = self.root.get('text-usetting').get('1.0','end -1 chars')
|
dat['value'] = self.root.get('text-usetting').get('1.0','end -1 chars')
|
||||||
self.save_cfg(w,dat)
|
self.save_cfg(w,dat)
|
||||||
|
self.set_unpack(w)
|
||||||
self.WinUnpack.destroy()
|
self.WinUnpack.destroy()
|
||||||
if self.WinUnpack: self.WinUnpack.destroy()
|
if self.WinUnpack: self.WinUnpack.destroy()
|
||||||
self.WinUnpack = self.root.toplevel('unpack.ui', title='解析脚本')
|
self.WinUnpack = self.root.toplevel('unpack.ui', title='解析脚本')
|
||||||
@@ -343,7 +346,7 @@ if __name__ == '__main__':
|
|||||||
# 读取用户数据文件
|
# 读取用户数据文件
|
||||||
root.usercfg = json.load(open('usercfg.json')) if os.path.isfile('usercfg.json') else {}
|
root.usercfg = json.load(open('usercfg.json')) if os.path.isfile('usercfg.json') else {}
|
||||||
# 预置数据回调函数
|
# 预置数据回调函数
|
||||||
for i in range(10):
|
for i in range(20):
|
||||||
name = 'btn-data%02d'%(i+1)
|
name = 'btn-data%02d'%(i+1)
|
||||||
try:
|
try:
|
||||||
btn = root.get(name)
|
btn = root.get(name)
|
||||||
@@ -357,7 +360,7 @@ if __name__ == '__main__':
|
|||||||
pass
|
pass
|
||||||
# 解析脚本回调函数
|
# 解析脚本回调函数
|
||||||
var = tkinter.IntVar()
|
var = tkinter.IntVar()
|
||||||
for i in range(10):
|
for i in range(20):
|
||||||
name = 'btn-unpack%02d'%(i+1)
|
name = 'btn-unpack%02d'%(i+1)
|
||||||
try:
|
try:
|
||||||
btn = root.get(name)
|
btn = root.get(name)
|
||||||
@@ -385,6 +388,7 @@ if __name__ == '__main__':
|
|||||||
root.entry('entry-cycle').set('1024ms')
|
root.entry('entry-cycle').set('1024ms')
|
||||||
root.entry('entry-baud').set('9600')
|
root.entry('entry-baud').set('9600')
|
||||||
root.entry('entry-encoding').set('gbk')
|
root.entry('entry-encoding').set('gbk')
|
||||||
|
root.entry('entry-uservar').set('0')
|
||||||
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())
|
||||||
root.button('btn-onoff', cmd=lambda:comm.openCloseSerial())
|
root.button('btn-onoff', cmd=lambda:comm.openCloseSerial())
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -14,5 +14,5 @@ setup(
|
|||||||
},
|
},
|
||||||
windows = [{ 'script':'scomm.py', 'icon_resources':[(1, 'app.ico')]}],
|
windows = [{ 'script':'scomm.py', 'icon_resources':[(1, 'app.ico')]}],
|
||||||
zipfile = None,
|
zipfile = None,
|
||||||
data_files = [('', ['usercfg.json','app.ui','unpack.ui','data.ui'])]
|
data_files = [('', ['usercfg.json','app.ui','unpack.ui','data.ui','README.md'])]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user