/// <summary> /// 加载配置信息 /// </summary> private bool LoadConfig() { Configuration config = Configuration.Read(@"Config\default.conf"); if (config == null) { return(false); } // 获取波特率 string baudRateStr = config.GetString("baudRate"); baudRateComboBox.Text = baudRateStr; // 获取奇偶校验位 int parityIndex = config.GetInt("parity"); parityComboBox.SelectedIndex = parityIndex; // 获取数据位 int dataBitsIndex = config.GetInt("dataBits"); dataBitsComboBox.SelectedIndex = dataBitsIndex; // 获取停止位 int stopBitsIndex = config.GetInt("stopBits"); stopBitsComboBox.SelectedIndex = stopBitsIndex; // 获取编码 int encodingIndex = config.GetInt("encoding"); encodingComboBox.SelectedIndex = encodingIndex; // 获取发送区内容 string sendDataText = config.GetString("sendDataTextBoxText"); sendDataTextBox.Text = sendDataText; // 获取自动发送数据时间间隔 string interval = config.GetString("autoSendDataInterval"); int timeUnitIndex = config.GetInt("timeUnit"); autoSendIntervalTextBox.Text = interval; timeUnitComboBox.SelectedIndex = timeUnitIndex; // 窗口状态 if (config.GetBool("maxmized")) { this.WindowState = WindowState.Maximized; } double width = config.GetDouble("windowWidth"); double height = config.GetDouble("windowHeight"); double top = config.GetDouble("windowTop"); double left = config.GetDouble("windowLeft"); this.Width = width; this.Height = height; this.Top = top; this.Left = left; // 面板显示状态 if (config.GetBool("serialPortConfigPanelVisible")) { serialSettingViewMenuItem.IsChecked = true; serialPortConfigPanel.Visibility = Visibility.Visible; } else { serialSettingViewMenuItem.IsChecked = false; serialPortConfigPanel.Visibility = Visibility.Collapsed; } if (config.GetBool("autoSendConfigPanelVisible")) { autoSendDataSettingViewMenuItem.IsChecked = true; autoSendConfigPanel.Visibility = Visibility.Visible; } else { autoSendDataSettingViewMenuItem.IsChecked = false; autoSendConfigPanel.Visibility = Visibility.Collapsed; } if (config.GetBool("serialCommunicationConfigPanelVisible")) { serialCommunicationSettingViewMenuItem.IsChecked = true; serialCommunicationConfigPanel.Visibility = Visibility.Visible; } else { serialCommunicationSettingViewMenuItem.IsChecked = false; serialCommunicationConfigPanel.Visibility = Visibility.Collapsed; } // 加载接收模式 receiveMode = (ReceiveMode)config.GetInt("receiveMode"); switch (receiveMode) { case ReceiveMode.Character: recvCharacterRadioButton.IsChecked = true; break; case ReceiveMode.Hex: recvHexRadioButton.IsChecked = true; break; case ReceiveMode.Decimal: default: break; } // 加载发送模式 sendMode = (SendMode)config.GetInt("sendMode"); switch (sendMode) { case SendMode.Character: sendCharacterRadioButton.IsChecked = true; break; case SendMode.Hex: sendHexRadioButton.IsChecked = true; break; default: break; } //加载追加内容 appendContent = config.GetString("appendContent"); switch (appendContent) { case "": appendNoneRadioButton.IsChecked = true; break; case "\r": appendReturnRadioButton.IsChecked = true; break; case "\n": appednNewLineRadioButton.IsChecked = true; break; case "\r\n": appendReturnNewLineRadioButton.IsChecked = true; break; default: break; } return(true); }
/// <summary> /// 加载配置信息 /// </summary> private bool LoadConfig() { Configuration config = Configuration.Read(@"Config\default.conf"); if (config == null) { return(false); } // 获取波特率 string baudRateStr = config.GetString("baudRate"); baudRateComboBox.Text = baudRateStr; // 获取奇偶校验位 int parityIndex = config.GetInt("parity"); parityComboBox.SelectedIndex = parityIndex; // 获取数据位 int dataBitsIndex = config.GetInt("dataBits"); dataBitsComboBox.SelectedIndex = dataBitsIndex; // 获取停止位 int stopBitsIndex = config.GetInt("stopBits"); stopBitsComboBox.SelectedIndex = stopBitsIndex; // 窗口状态 if (config.GetBool("maxmized")) { this.WindowState = WindowState.Maximized; } double width = config.GetDouble("windowWidth"); double height = config.GetDouble("windowHeight"); double top = config.GetDouble("windowTop"); double left = config.GetDouble("windowLeft"); this.Width = width; this.Height = height; this.Top = top; this.Left = left; // 面板显示状态 if (config.GetBool("serialPortConfigPanelVisible")) { serialSettingViewMenuItem.IsChecked = true; serialPortConfigPanel.Visibility = Visibility.Visible; } else { serialSettingViewMenuItem.IsChecked = false; serialPortConfigPanel.Visibility = Visibility.Collapsed; } if (config.GetBool("serialCommunicationConfigPanelVisible")) { serialCommunicationSettingViewMenuItem.IsChecked = true; serialCommunicationConfigPanel.Visibility = Visibility.Visible; } else { serialCommunicationSettingViewMenuItem.IsChecked = false; serialCommunicationConfigPanel.Visibility = Visibility.Collapsed; } // 加载接收模式 receiveMode = (ReceiveMode)config.GetInt("receiveMode"); switch (receiveMode) { case ReceiveMode.Character: recvCharacterRadioButton.IsChecked = true; break; case ReceiveMode.Hex: recvHexRadioButton.IsChecked = true; break; case ReceiveMode.Decimal: recvDecRadioButton.IsChecked = true; break; case ReceiveMode.Octal: recvOctRadioButton.IsChecked = true; break; case ReceiveMode.Binary: recvBinRadioButton.IsChecked = true; break; default: break; } showReceiveData = config.GetBool("showReceiveData"); showRecvDataCheckBox.IsChecked = showReceiveData; return(true); }