public static SettingData Load() { FileStream fs = null; SettingData model = null; App ap = App.Current as App; string file = Path.Combine(ap.StartUpFolder, SAVE_FILE_NAME); try { fs = new FileStream(file, System.IO.FileMode.Open); var serializer = new XmlSerializer(typeof(SettingData)); model = (SettingData)serializer.Deserialize(fs); fs.Close(); } catch (Exception) { model = new SettingData(); if (fs != null) { fs.Close(); } } return(model); }
private void comportOpen() { var config = SettingData.Load(); _ports = new SerialPort(config.SerialPortSettingData.PortNum); _ports.BaudRate = (int)config.SerialPortSettingData.BaudRate; _ports.Parity = config.SerialPortSettingData.Parity; _ports.StopBits = config.SerialPortSettingData.StopBit; _ports.DataBits = config.SerialPortSettingData.Databit; _ports.Handshake = config.SerialPortSettingData.FlowControl; //_ports.RtsEnable = true; _ports.DataReceived -= _ports_DataReceived; _ports.DataReceived += _ports_DataReceived; try { _ports.Open(); } catch (Exception e) { var asmttl = (System.Reflection.AssemblyTitleAttribute)Attribute.GetCustomAttribute( System.Reflection.Assembly.GetExecutingAssembly(), typeof(System.Reflection.AssemblyTitleAttribute)); MessageBox.Show(e.Message, asmttl.Title, MessageBoxButton.OK, MessageBoxImage.Error); _ports.Dispose(); _ports = null; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { var config = SettingData.Load(); cmbPortNo.Text = config.SerialPortSettingData.PortNum; cmbRate.Text = config.SerialPortSettingData.BaudRate.ToString(); cmbData.Text = config.SerialPortSettingData.Databit.ToString(); cmbParity.Text = config.SerialPortSettingData.Parity.ToString(); cmbStopBit.Text = config.SerialPortSettingData.StopBit.ToString(); cmbFlowCtl.Text = config.SerialPortSettingData.FlowControl.ToString(); }
/// <summary> /// インスタンスの取得 /// </summary> /// <returns></returns> public static SettingData GetInstance() { if (_current == null) { _current = SettingData.Load(); if (_current == null) { _current = new SettingData(); } } return(_current); }
private void OkButton_Click(object sender, RoutedEventArgs e) { var config = SettingData.Load(); config.SerialPortSettingData.PortNum = cmbPortNo.Text; config.SerialPortSettingData.BaudRate = int.Parse(cmbRate.Text); config.SerialPortSettingData.Databit = int.Parse(cmbData.Text); config.SerialPortSettingData.Parity = (Parity)Enum.Parse(typeof(Parity), cmbParity.Text); config.SerialPortSettingData.StopBit = (StopBits)Enum.Parse(typeof(StopBits), cmbStopBit.Text); config.SerialPortSettingData.FlowControl = (Handshake)Enum.Parse(typeof(Handshake), cmbFlowCtl.Text); config.Save(); IsCancel = false; this.Close(); }