diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 1021a8b..e10a650 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -465,6 +465,15 @@ namespace DyeingComputer.Properties { } } + /// + /// 查找类似 Malfunction 的本地化字符串。 + /// + public static string Malfunction { + get { + return ResourceManager.GetString("Malfunction", resourceCulture); + } + } + /// /// 查找类似 Measure 的本地化字符串。 /// @@ -834,6 +843,15 @@ namespace DyeingComputer.Properties { } } + /// + /// 查找类似 Sensor 的本地化字符串。 + /// + public static string Sensor { + get { + return ResourceManager.GetString("Sensor", resourceCulture); + } + } + /// /// 查找类似 StartTime 的本地化字符串。 /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index be71ab8..988388b 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -429,4 +429,10 @@ Heat insulating + + Malfunction + + + Sensor + \ No newline at end of file diff --git a/View/TechnologicalProcessView.xaml.cs b/View/TechnologicalProcessView.xaml.cs index 7cb4c5f..f8dd244 100644 --- a/View/TechnologicalProcessView.xaml.cs +++ b/View/TechnologicalProcessView.xaml.cs @@ -100,13 +100,16 @@ namespace DyeingComputer.View private void UserControl_KeyDown(object sender, KeyEventArgs e) //键盘监控 { - if ((MainWindowViewModel.WORK_RUN == 1) || (MainWindowViewModel.WORK_RUN == 0))//停止暂停时可以启用开始 + if (string.IsNullOrEmpty(MainWindowViewModel.Name_err.ToString()))//无错误信息 { - if (e.Key == Key.Y) //按键y + if ((MainWindowViewModel.WORK_RUN == 1) || (MainWindowViewModel.WORK_RUN == 0))//停止暂停时可以启用开始 { - MainWindowViewModel.STEP_START(Numder, Convert.ToDouble(P1), Convert.ToDouble(P2), Convert.ToDouble(P3), Convert.ToDouble(P4), Convert.ToDouble(P5)); - // MainWindowViewModel strart = new MainWindowViewModel();//实例 - // strart.STEP_START(Numder, Convert.ToDouble(P1), Convert.ToDouble(P2), Convert.ToDouble(P3), Convert.ToDouble(P4), Convert.ToDouble(P5));//传入参数开始 + if (e.Key == Key.Y) //按键y + { + MainWindowViewModel.STEP_START(Numder, Convert.ToDouble(P1), Convert.ToDouble(P2), Convert.ToDouble(P3), Convert.ToDouble(P4), Convert.ToDouble(P5)); + // MainWindowViewModel strart = new MainWindowViewModel();//实例 + // strart.STEP_START(Numder, Convert.ToDouble(P1), Convert.ToDouble(P2), Convert.ToDouble(P3), Convert.ToDouble(P4), Convert.ToDouble(P5));//传入参数开始 + } } } } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index f276783..2d3badc 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -152,7 +152,7 @@ namespace DyeingComputer.ViewModel disTimer.Start();//计时开始 }//时间周期初始化 - public static object Name_err; + public static object Name_err = ""; public static object WorkNumder; public static object Process_step; public static Int32 DIDETime; //空闲计时器 @@ -163,23 +163,25 @@ namespace DyeingComputer.ViewModel Work_Numder = WorkNumder.ToString(); if (LINK_OK) Modbus_link(); - DIDETime++; STEP_RUN(); - IO_data(); + IO_data(); + + if (!string.IsNullOrEmpty(Name_err.ToString())) Status_Str = Name_err.ToString(); } void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S { if (!LINK_OK) Modbus_link(); - if (Name_err != null) Status_Str = Name_err.ToString(); + + if (string.IsNullOrEmpty(Name_err.ToString()) && ((Selet_dtm("1010") < 10) || (Selet_dtm("1010") > 160))) + { Status_Str = Resources.Temperature + Resources.Sensor + Resources.Malfunction; } //温度故障提示 } void DisTimer_100MS(object sender, EventArgs e)//Tick_Event周期执行事件100MS { - + } - public static int WORK_RUN = 0; //运行状态0停止1暂停2运行 private static string STEP_ID = "0"; private static double STEP_P1 = 0; @@ -194,10 +196,11 @@ namespace DyeingComputer.ViewModel private static double TEMP_co = 0; //计算温度 public static void STEP_START(string ID,double P1,double P2,double P3,double P4,double P5) - { - if (ID == "001") + { + switch (STEP_ID) { - STEP_ID = "001"; + case "001": + STEP_ID = "001"; STEP_P1 = Convert.ToDouble(P1); STEP_P2 = Convert.ToDouble(P2); STEP_P3 = Convert.ToDouble(P3); @@ -211,79 +214,124 @@ namespace DyeingComputer.ViewModel STEP_TIME = Convert.ToInt16(STEP_P3) * 60; WORK_RUN = 2; SETP_runtime = true; + break; + case "007": + + break; + case "009": + + break; + case "013": + + break; + case "015": + + break; + case "017": + + break; + case "020": + + break; + case "022": + + break; + default: + break; } } TimeSpan ts=new TimeSpan(1);//1秒间隔 void STEP_RUN() { - if (WORK_RUN == 2) { if (SETP_runtime) { - if (STEP_ID == "001") + switch (STEP_ID) { - int TIME_H; - int TIME_M; - int TIME_S; - double TO = 0; - double T = Selet_dtm("1010"); //实际温度 - if (THL_mode == 0) //保温 - { - if (STEP_TIME == 0) { STEP_finish = true; } - else { STEP_TIME--; } - TO = pid.PID_iterate(STEP_P1, T, ts); - if (TO < 0) TO = 0; - - TIME_H = STEP_TIME / 3600; - TIME_M = (STEP_TIME - TIME_H * 3600) / 60; - TIME_S = STEP_TIME - TIME_H * 3600 - TIME_M * 60; - Status_Str = Resources.Heat_insulating+":" + Resources.Time + string.Format(" {0:D2}", TIME_H) + ":" + string.Format(" {0:D2}", TIME_M) + ":" + string.Format(" {0:D2}", TIME_S); - } - else if (THL_mode == 1)//升温 - { - TEMP_co = TEMP_co + (STEP_P2 / 600); - TO = pid.PID_iterate(TEMP_co, T, ts); - if (TO < 0) TO = 0; - if (STEP_P1 < T) + case "001": //功能模块001温度控制 + int TIME_H; + int TIME_M; + int TIME_S; + double TO = 0; + double T = Selet_dtm("1010"); //实际温度 + if (THL_mode == 0) //保温 { - THL_mode = 0; - TIME_M = 0; - } - else - { - TIME_M = Convert.ToInt16( (STEP_P1 - T) / (STEP_P2/10)); + if (STEP_TIME == 0) { STEP_finish = true; } + else { STEP_TIME--; } + TO = pid.PID_iterate(STEP_P1, T, ts); + if (TO < 0) TO = 0; + + TIME_H = STEP_TIME / 3600; + TIME_M = (STEP_TIME - TIME_H * 3600) / 60; + TIME_S = STEP_TIME - TIME_H * 3600 - TIME_M * 60; + Status_Str = Resources.Heat_insulating + ":" + Resources.Time + string.Format(" {0:D2}", TIME_H) + ":" + string.Format(" {0:D2}", TIME_M) + ":" + string.Format(" {0:D2}", TIME_S); } - Status_Str = Resources.Heats + ":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) + "°C" + Resources.Expected+ string.Format(" {0:D2}", TIME_M) + Resources.Min; - } - else if (THL_mode == 2)//降温 - { - TEMP_co = TEMP_co - (STEP_P2 / 600); - TO = pid.PID_iterate(TEMP_co, T, ts); - if (TO > 0) TO = 0; - TO = Math.Abs(TO); - if (STEP_P1 > T) - { - THL_mode = 0; - TIME_M = 0; + else if (THL_mode == 1)//升温 + { + TEMP_co = TEMP_co + (STEP_P2 / 600); + TO = pid.PID_iterate(TEMP_co, T, ts); + if (TO < 0) TO = 0; + if (STEP_P1 < T) + { + THL_mode = 0; + TIME_M = 0; + } + else + { + TIME_M = Convert.ToInt16((STEP_P1 - T) / (STEP_P2 / 10)); + } + Status_Str = Resources.Heats + ":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) + "°C" + Resources.Expected + string.Format(" {0:D2}", TIME_M) + Resources.Min; } - else + else if (THL_mode == 2)//降温 { - TIME_M = Convert.ToInt16((T - STEP_P1) / (STEP_P2 / 10)); + TEMP_co = TEMP_co - (STEP_P2 / 600); + TO = pid.PID_iterate(TEMP_co, T, ts); + if (TO > 0) TO = 0; + TO = Math.Abs(TO); + if (STEP_P1 > T) + { + THL_mode = 0; + TIME_M = 0; + } + else + { + TIME_M = Convert.ToInt16((T - STEP_P1) / (STEP_P2 / 10)); + } + Status_Str = Resources.Cooling + ":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) + "°C" + Resources.Expected + string.Format(" {0:D2}", TIME_M) + Resources.Min; } - Status_Str = Resources.Cooling +":" + Resources.Target + Resources.Temperature + string.Format(" {0:###.#}", STEP_P1) +"°C" + Resources.Expected + string.Format(" {0:D2}", TIME_M )+ Resources.Min; - } + updata_dtm("1004", TO); + updata_dtm("1005", TEMP_co); + break; + case "007": - updata_dtm("1004", TO); - updata_dtm("1005", TEMP_co); + break; + case "009": - } + break; + case "013": + + break; + case "015": + + break; + case "017": + + break; + case "020": + break; + case "022": + + break; + default: + break; + } } else { - if (Name_err == null) + if (string.IsNullOrEmpty(Name_err.ToString())) { Status_Str = Resources.Await; } @@ -296,7 +344,7 @@ namespace DyeingComputer.ViewModel else if (WORK_RUN == 0) { - if (Name_err == null) + if (string.IsNullOrEmpty(Name_err.ToString())) { int TIMEH = DIDETime / 3600; int TIMEM = (DIDETime - TIMEH * 3600) / 60; @@ -304,13 +352,8 @@ namespace DyeingComputer.ViewModel Status_Str = Resources.Dide + string.Format(" {0:D4}", TIMEH) + ":" + string.Format(" {0:D2}", TIMEM) + ":" + string.Format(" {0:D2}", TIMES); } } - } - - - - public static SerialPort port = new SerialPort();//创建串口 static ModbusFactory factory = new ModbusFactory(); // Create Modbus Master @@ -360,18 +403,14 @@ namespace DyeingComputer.ViewModel { master.WriteMultipleCoils(slaveId, 00000, DQ); //写入线圈 master.WriteMultipleRegisters(slaveId,07000,DW); //写入寄存器 - DO = master.ReadCoils(slaveId, 01000, DO_L); //读取线圈 - // DQ = master.ReadCoils(slaveId, 00000, DQ_L); RW = master.ReadHoldingRegisters(slaveId,06000, RW_L); //读取寄存器 - // RW = master.ReadHoldingRegisters(slaveId, 07000, RW_L); LINK_OK =true; } catch (Exception ex) { LINK_OK=false; LINK_ERR++; - // LogGing.LogGingDATA(ex.Message); Name_err = "PLC"+Properties.Resources.Connectionlost+"("+ ex.Message + ")"; } });