public W_Port1(Device001.Port.C_MyPort v_Port, string V_NameDeice) { InitializeComponent(); this.Title = V_NameDeice; V_Port = v_Port; foreach (var v_n in C_PortOptions.F_GetPortNames()) { CB_NamePort.Items.Add(v_n); } if (C_PortOptions.F_GetPortNames().Count() != 0) { CB_NamePort.SelectedIndex = 0; } if (C_PortOptions.F_GetPortNames().Contains(v_Port.Fv_PortName)) { CB_NamePort.SelectedIndex = Array.FindIndex(C_PortOptions.F_GetPortNames(), x => x == v_Port.Fv_PortName); } foreach (var v_sb in C_PortOptions.F_GetStopBits()) { CB_StopBits.Items.Add(C_PortOptions.F_StopBits(v_sb)); } if (CB_StopBits.Items.Contains(C_PortOptions.F_StopBits(v_Port.Fv_StopBits))) { CB_StopBits.SelectedIndex = CB_StopBits.Items.IndexOf(C_PortOptions.F_StopBits(v_Port.Fv_StopBits)); } foreach (var v_sb in C_PortOptions.F_GetParity()) { CB_Parity.Items.Add(C_PortOptions.F_Parity(v_sb)); } if (CB_Parity.Items.Contains(C_PortOptions.F_Parity(v_Port.Fv_Parity))) { CB_Parity.SelectedIndex = CB_Parity.Items.IndexOf(C_PortOptions.F_Parity(v_Port.Fv_Parity)); } foreach (var v_sb in C_PortOptions.F_GetBaudRate()) { CB_BaudRate.Items.Add(C_PortOptions.F_BaudRate(v_sb)); } if (CB_BaudRate.Items.Contains(C_PortOptions.F_BaudRate(v_Port.Fv_BaudRate))) { CB_BaudRate.SelectedIndex = CB_BaudRate.Items.IndexOf(C_PortOptions.F_BaudRate(v_Port.Fv_BaudRate)); } Cb_OnOff.IsChecked = V_Port.V_Status; }
private S_SerializablePortOptions V_SerializableOptions_v01; // Для сохранения настроек /// <summary> /// Установака и сохранение новых значений /// </summary> public Task <bool> F_SetAndSaveOptions(C_MyPort v_PortOptions) { V_SerializableOptions_v01.Fv_BaudRate = Fv_BaudRate = v_PortOptions.Fv_BaudRate; V_SerializableOptions_v01.Fv_Parity = Fv_Parity = v_PortOptions.Fv_Parity; V_SerializableOptions_v01.Fv_PortName = Fv_PortName = v_PortOptions.Fv_PortName; V_SerializableOptions_v01.Fv_StopBits = Fv_StopBits = v_PortOptions.Fv_StopBits; V_SerializableOptions_v01.Fv_OnOff = V_Status = v_PortOptions.V_Status; return(Task.Run(() => { using (FileStream fs = new FileStream(V_FileName, FileMode.OpenOrCreate)) // Подумать насчёт исключений { V_formatter.Serialize(fs, V_SerializableOptions_v01); } return true; })); }