-
Notifications
You must be signed in to change notification settings - Fork 1
/
SerialSettingDialog.py
83 lines (68 loc) · 3.06 KB
/
SerialSettingDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
'''
串口设置窗口
Created on 2013-12-4
@author: Administrator
'''
import wx
from GroundStationBase import frame_serial_setting
from communication.XBeeComm import XBee
import serial.tools.list_ports as lstprt
class SerialSetting(frame_serial_setting):
'''
串口设置窗口类
'''
def __init__(self,parent, option_arg = None):
'''
初始化
@param parent: 父窗口
@param option_arg: 可选参数,表示串口设置的dict
'''
frame_serial_setting.__init__(self,parent)
self.comm = parent.comm
serial_info = self.comm.get_supported_info()
self.parity_table = {}
for s in serial_info['parity']:
self.parity_table[s[0]] = s
self.stopbit_table = {}
for s in serial_info['stopbit']:
self.stopbit_table[float(s)] = s
self.init_options(serial_info)
if option_arg is None:
option = {'com' : serial_info['com'][0],
'baudrate': 9600,
'bytesize': 8,
'parity' : 'None',
'stopbit' : 1,
'RtsCts' : False,#hard flow control
'XonXoff' : False,#software flow control
}
else:
option = option_arg
self.set_options(option)
def on_see_com_info(self, event):
wx.MessageBox(self.comm.get_com_info(), u"串口信息",wx.OK | wx.ICON_INFORMATION)
def get_options(self):
option = {'com' : self.m_choice_com.GetStringSelection(),
'baudrate': int(self.m_choice_baudrate.GetStringSelection()),
'bytesize': int(self.m_choice_bytesize.GetStringSelection()),
'parity' : self.m_choice_parity.GetStringSelection()[0],
'stopbit' : float(self.m_choice_stopbit.GetStringSelection()),
'RtsCts':self.m_checkBox_RtsCts.IsChecked(),
'XonXoff':self.m_checkBox_XonXoff.IsChecked(),
}
return option
def set_options(self,option):
self.m_choice_com. SetStringSelection(str(option['com']))
self.m_choice_baudrate. SetStringSelection(str(option['baudrate']))
self.m_choice_bytesize. SetStringSelection(str(option['bytesize']))
self.m_choice_stopbit. SetStringSelection(self.stopbit_table[option['stopbit']])
self.m_choice_parity. SetStringSelection(self.parity_table[option['parity']])
self.m_checkBox_RtsCts. SetValue(option['RtsCts'])
self.m_checkBox_XonXoff.SetValue(option['XonXoff'])
def init_options(self,info):
self.m_choice_com.SetItems([each[0] for each in lstprt.comports()])
self.m_choice_baudrate.SetItems(info['baudrate'])
self.m_choice_bytesize.SetItems(info['bytesize'])
self.m_choice_parity.SetItems(info['parity'])
self.m_choice_stopbit.SetItems(info['stopbit'])