private void AddNewSerialPortInfoWithSave(SerialPortSettingsInfo serialPortSettingsInfo, PLCSettingsInfo plcSettingsInfo) { var plcSerialPortInfo = new PLCSerialPortInfo(serialPortSettingsInfo.Current.Item1); PLCSerialPortInfos.Add(plcSerialPortInfo); var deviceSettings = PLCDeviceSettings.GetPLCDeviceSettings(); deviceSettings.SerialPortSettings.Add(new PLCSerialPortSettings(serialPortSettingsInfo.Current.Item1)); if (PLCDeviceService.SaveSettings()) { plcSerialPortInfo.AddPLCDeviceInfoWithSave(plcSettingsInfo.Current); } }
private void InitRemoveSerialPortCommand() { RemoveSerialPortCommand = new RelayCommand(() => { var dialog = new RemoveItemsView("删除通信串口", PLCSerialPortInfos.Select(s => s.PortName).ToList()); if (dialog.ShowDialog() == true) { var removePortNames = dialog.SelectedItems; foreach (var portName in removePortNames) { var serialPortInfo = PLCSerialPortInfos.FirstOrDefault(s => s.PortName == portName); if (serialPortInfo != null) { serialPortInfo.Cleanup(); PLCSerialPortInfos.Remove(serialPortInfo); } } PLCDeviceService.SaveSettings(); } }); }