/// <summary> /// 添加受控风扇 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addBtn_Click(object sender, RoutedEventArgs e) { int newFanNo = ecviewDataList.Count + 1; if (newFanNo > 4) { MessageBox.Show("无法增加更多受控风扇", "提示", MessageBoxButton.OK, MessageBoxImage.Information); return; } else { MessageBoxResult res = MessageBox.Show("增加受控风扇?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (res == MessageBoxResult.OK) { ECViewBinding ec = new ECViewBinding(); int[] ecData = ECLib.FanCtrl.GetTempFanDuty(newFanNo); ec.CpuRemote = ecData[1] + "℃"; ec.FanDutyStr = ecData[2] + "%"; ec.FanDuty = ecData[2]; ec.FanNo = newFanNo; ec.FanSet = "未设置"; ec.FanSetModel = 0; ec.Ope = "设置"; ec.UpdateFlag = true; ecviewDataList.Add(ec); } } }
////////////////////////////////////////////////////////界面事件//////////////////////////////////////////////////////// /// <summary> /// DataGrid点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ECEditor_Click(object sender, RoutedEventArgs e) { //读取选择的参数行 var datagrid = sender as System.Windows.Controls.DataGrid; index = datagrid.SelectedIndex; ECViewBinding selectFan = (ECViewBinding)datagrid.SelectedItem; int fanduty = ECLib.FanCtrl.GetTempFanDuty(index + 1)[2]; //加载窗体 ECEditor ecWindow = new ECEditor(this, index, fanduty, selectFan.FanSetModel); ecWindow.ShowDialog(); }
public MainWindow() { InitializeComponent(); //检测服务 CheckService(); //数据绑定 ecviewData = (ECViewBinding)ECViewGrid.DataContext; ecviewDataList = (ECViewCollec)ECDataGrid.DataContext; //当前工作目录 currentDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; //初始化数据 InitECData(); //CPU更新线程 _getTemp_Task(); }
/// <summary> /// 初始化数据 /// </summary> private void InitECData() { //模具型号 ecviewData.NbModel = "当前模具型号为:"; foreach (var baseBoard in Searcher_BaseBoard.Get()) { ecviewData.NbModel += Convert.ToString((baseBoard)["Product"]); } //EC版本 ecviewData.ECVersion = "当前EC版本为:1."; ecviewData.ECVersion += ECLib.FanCtrl.GetECVersion(); //风扇数量 FANCount = ECLib.FanCtrl.GetFanCount(); if (FANCount > 4) { FANCount = 0; } if (FANCount == 0) { FANCount = 1; } //判断配置文件是否存在 if (System.IO.File.Exists(currentDirectory + "ecview.cfg")) { List <ECLib.FanCtrl.ConfigPara> configParaList = ECLib.FanCtrl.ReadCfgFile(currentDirectory + "ecview.cfg"); //风扇转速与温度信息 for (int i = 0; i < configParaList.Count; i++) { ECViewBinding ec = new ECViewBinding(); int[] ecData = ECLib.FanCtrl.GetTempFanDuty(i + 1); ec.FanNo = i + 1; foreach (ECLib.FanCtrl.ConfigPara configPara in configParaList) { if (ec.FanNo == configPara.FanNo) { ec.FanSetModel = configPara.SetMode; ec.FanSet = configPara.FanSet; if (configPara.SetMode == 1) { //若上次配置为自动调节,设置风扇自动调节 ecData = ECLib.FanCtrl.SetFanduty(configPara.FanNo, 0, true); } else if (configPara.SetMode == 2) { //若为上次配置手动调节,设置风扇转速 ecData = ECLib.FanCtrl.SetFanduty(configPara.FanNo, (int)(configPara.FanDuty * 2.55m), false); } else { } } } ecviewData.CpuRemote = ecData[1] + "℃"; ec.UpdateFlag = false; ec.FanDutyStr = ecData[2] + "%"; ec.FanDuty = ecData[2]; ec.Ope = "设置"; ecviewDataList.Add(ec); } } else { //风扇转速与温度信息 for (int i = 0; i < FANCount; i++) { ECViewBinding ec = new ECViewBinding(); int[] ecData = ECLib.FanCtrl.GetTempFanDuty(i + 1); ecviewData.CpuRemote = ecData[1] + "℃"; ec.FanDutyStr = ecData[2] + "%"; ec.FanDuty = ecData[2]; ec.FanNo = i + 1; ec.FanSet = "未设置"; ec.FanSetModel = 0; ec.Ope = "设置"; ec.UpdateFlag = false; ecviewDataList.Add(ec); } } }
/// <summary> /// 移除受控风扇 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rmvBtn_Click(object sender, RoutedEventArgs e) { ECViewBinding selectFan = ECDataGrid.SelectedItem as ECViewBinding; ecviewDataList.Remove(selectFan); }