diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f980ab9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/ProductionSystem/Forms/HomeForm.cs b/ProductionSystem/Forms/HomeForm.cs index 368ac2a..868816b 100644 --- a/ProductionSystem/Forms/HomeForm.cs +++ b/ProductionSystem/Forms/HomeForm.cs @@ -42,6 +42,7 @@ namespace ProductionSystem.Forms private static string iniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemConfig.ini"); private bool topIsCanRound = true;//展示PLC采集数据时,是否可以进入下一次循环 private bool middleIsCanRound = true;//展示PLC采集数据时,是否可以进入下一次循环 + private bool middleIsCanRound2 = true;//展示PLC采集数据时,是否可以进入下一次循环 private static List _curveKes = new List();//曲线名称 CancellationToken cureCancellationToken; @@ -65,27 +66,33 @@ namespace ProductionSystem.Forms cmbProductType.SelectedItem = new ListItem { Value = Program.ProductType, Text = Program.ProductType }; + //var temp = _paraConfigService.GetParaTargetVal(ModeTypeEnum.BZ1_DB); + //string str1 = temp.PZF1.TargetVal; + //string str2 = temp.PZF1.Lin; + //string str3 = temp.PZF1.Com; - } - private void HomeForm_Load(object sender, EventArgs e) - { - - #region 各工序的采集点位 - Program.BZ1 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ1").ToList(); + private void Init() + { + Program.BZ1 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ1").ToList(); Program.BZ2 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ2").ToList(); - - - Program.BZ3 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ3").ToList(); Program.BZ4 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ4").ToList(); Program.BZ5 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ5").ToList(); Program.BZ6 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ6").ToList(); Program.BZ7 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ7").ToList(); Program.BZ8 = Program.MiddlePointKeyValues.Where(m => m.ParaCategory == "BZ8").ToList(); + } + + private void HomeForm_Load(object sender, EventArgs e) + { + + #region 各工序的采集点位 + + Init(); @@ -164,16 +171,25 @@ namespace ProductionSystem.Forms Task.Run(() => { ShowMiddleData(); - + + }, cancellationTokenSource.Token); + + + Task.Run(() => + { + + ShowMiddleData2(); + + }, cancellationTokenSource.Token); + + hslCurveHistory.RemoveAllCurve(); - ShowMiddleData2(); - ShowMiddleData2(); - ShowMiddleData2(); - ShowMiddleData2(); + + } @@ -576,16 +592,27 @@ namespace ProductionSystem.Forms testValPoint.Val = val; this.Invoke(new Action(() => { + + var LblItemText = topMyResultControls[i].LblItemText; + + topMyResultControls[i].SetForeColor(Color.Black); topMyResultControls[i].TestValText = testValPoint.Val; - if (testValPoint.Val == "0.000") - { - topMyResultControls[i].TestValText = "停止"; - } - else - if (testValPoint.Val == "1.000") + + if (LblItemText.Contains("模式") || LblItemText.Contains("状态")) { - topMyResultControls[i].TestValText = "启动"; + if (testValPoint.Val == "0.000") + { + topMyResultControls[i].TestValText = "关闭"; + topMyResultControls[i].SetForeColor(Color.Red); + } + else + if (testValPoint.Val == "1.000") + { + topMyResultControls[i].TestValText = "启动"; + topMyResultControls[i].SetForeColor(Color.Green); + } } + })); //if (M249.Val != "0.000" && M249.Val != "10.000") //{ @@ -806,15 +833,19 @@ namespace ProductionSystem.Forms private void ShowMiddleData2() { - Thread.Sleep(Program.ReadPlcRate); + while (!cancellationTokenSource.IsCancellationRequested) + { + GetPlc(Program.BZ1, "BZ1"); + GetPlc(Program.BZ2, "BZ2"); + GetPlc(Program.BZ3, "BZ3"); + GetPlc(Program.BZ4, "BZ4"); + GetPlc(Program.BZ5, "BZ5"); + GetPlc(Program.BZ6, "BZ6"); - GetPlc(Program.BZ1, "BZ1"); - GetPlc(Program.BZ2, "BZ2"); - GetPlc(Program.BZ3, "BZ3"); - GetPlc(Program.BZ4, "BZ4"); - GetPlc(Program.BZ5, "BZ5"); - GetPlc(Program.BZ6, "BZ6"); + Thread.Sleep(Program.ReadPlcRate); + } + } @@ -1226,6 +1257,11 @@ namespace ProductionSystem.Forms + + /// + /// 显示Db块的数据 + /// + /// private void SetMiddleData(string paraCategory) { try diff --git a/ProductionSystem/Forms/SystemSetting/ParaSettingForm.cs b/ProductionSystem/Forms/SystemSetting/ParaSettingForm.cs index 5021b10..a8f04e2 100644 --- a/ProductionSystem/Forms/SystemSetting/ParaSettingForm.cs +++ b/ProductionSystem/Forms/SystemSetting/ParaSettingForm.cs @@ -420,12 +420,14 @@ namespace ProductionSystem.Forms.SystemSetting if (textEditControl != null) { var protocolConfigCode = textEditControl.TargetText.Trim(); + T_ParaConfig t_ParaConfig = new T_ParaConfig { ProductType = productType, ParaCategory = paraCategory, ParaCode = textEditControl.LblItemCode, - Remark = protocolConfigCode, + TargetVal = protocolConfigCode.ToDecimal(), + Remark= protocolConfigCode, CreatedTime = DateTime.Now, CreatedBy = CurrentUser.Id }; diff --git a/ProductionSystem_Model/Enum/ModeTypeEnum.cs b/ProductionSystem_Model/Enum/ModeTypeEnum.cs new file mode 100644 index 0000000..eaa65b2 --- /dev/null +++ b/ProductionSystem_Model/Enum/ModeTypeEnum.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProductionSystem_Model.Enum +{ + /// + /// 模式枚举 + /// + public enum ModeTypeEnum + { + [Description("步骤(模式)1")] + BZ1_DB = 1, + [Description("步骤(模式)2")] + BZ2_DB = 2, + [Description("步骤(模式)3")] + BZ3_DB = 3, + [Description("步骤(模式)4")] + BZ4_DB = 4, + [Description("步骤(模式)5")] + BZ5_DB = 5, + [Description("步骤(模式)6")] + BZ6_DB = 6, + } +} diff --git a/ProductionSystem_Model/ProductionSystem_Model.csproj b/ProductionSystem_Model/ProductionSystem_Model.csproj index 7a4f5fd..5c229e5 100644 --- a/ProductionSystem_Model/ProductionSystem_Model.csproj +++ b/ProductionSystem_Model/ProductionSystem_Model.csproj @@ -117,6 +117,7 @@ + @@ -137,7 +138,7 @@ - + diff --git a/ProductionSystem_Model/ViewModel/Response/Para/EditionType.cs b/ProductionSystem_Model/ViewModel/Response/Para/EditionType.cs new file mode 100644 index 0000000..0549097 --- /dev/null +++ b/ProductionSystem_Model/ViewModel/Response/Para/EditionType.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProductionSystem_Model.ViewModel.Response.Para +{ + public class EditionPara + { + //目标值 + public string TargetVal { get; set; } + //通讯方式 + public string Lin { get; set; } + //端口号 + public string Com { get; set; } + //错误信息 + public string Err { get; set; } + } + + public class EditonType + { + + public EditonType() + { + STF1 = new EditionPara(); + STF2 = new EditionPara(); + PZF1 = new EditionPara(); + PZF2 = new EditionPara(); + SB1 = new EditionPara(); + SB2 = new EditionPara(); + SB3 = new EditionPara(); + } + public EditionPara STF1 { get; set; } + public EditionPara STF2 { get; set; } + public EditionPara PZF1 { get; set; } + public EditionPara PZF2 { get; set; } + public EditionPara SB1 { get; set; } + public EditionPara SB2 { get; set; } + public EditionPara SB3{ get; set; } + } + +} diff --git a/ProductionSystem_Model/ViewModel/Response/Para/ParaTargetValVM.cs b/ProductionSystem_Model/ViewModel/Response/Para/ParaTargetValVM.cs deleted file mode 100644 index 0fe6d18..0000000 --- a/ProductionSystem_Model/ViewModel/Response/Para/ParaTargetValVM.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProductionSystem_Model.ViewModel.Response.Para -{ - public class ParaTargetValVM - { - public string STF1TargetVal { get; set; } - public string STF2TargetVal { get; set; } - public string PZF1TargetVal { get; set; } - public string PZF2TargetVal { get; set; } - public string SB1TargetVal { get; set; } - public string SB2TargetVal { get; set; } - public string SB3TargetVal { get; set; } - } -} diff --git a/ProductionSystem_Service/ExvService.cs b/ProductionSystem_Service/ExvService.cs new file mode 100644 index 0000000..d92e66c --- /dev/null +++ b/ProductionSystem_Service/ExvService.cs @@ -0,0 +1,49 @@ +using ProductionSystem_Log; + +using ProductionSystem_Model; +using ProductionSystem_Model.DbModel; +using ProductionSystem_Model.DbModel.Para; +using ProductionSystem_Model.ViewModel.Response.Para; +using SqlSugar; +using System; +using System.Collections.Generic; + +namespace ProductionSystem_Service +{ + public class ExvService : DbContext + { + + public void Add(Exv ex) + { + db.Insertable(ex).ExecuteCommand(); + } + + + } + + public class UxService : DbContext + { + public void Add(Ux entity) + { + db.Insertable(entity).ExecuteCommand(); + } + } + + public class UYService : DbContext + { + public void Add(Uy entity) + { + db.Insertable(entity).ExecuteCommand(); + } + } + + public class StoneService : DbContext + { + public void Add(Stone entity) + { + db.Insertable(entity).ExecuteCommand(); + } + + } + +} diff --git a/ProductionSystem_Service/ParaConfigService.cs b/ProductionSystem_Service/ParaConfigService.cs index 0c3fbd3..b1f6210 100644 --- a/ProductionSystem_Service/ParaConfigService.cs +++ b/ProductionSystem_Service/ParaConfigService.cs @@ -1,9 +1,12 @@ using ProductionSystem_Log; using ProductionSystem_Model.DbModel.Para; +using ProductionSystem_Model.DbModel.Protocol; +using ProductionSystem_Model.Enum; using ProductionSystem_Model.ViewModel.Response.Para; using SqlSugar; using System; using System.Collections.Generic; +using System.Linq; namespace ProductionSystem_Service { @@ -95,63 +98,121 @@ namespace ProductionSystem_Service { try { - var temp = db.Queryable().Where(m => m.ParaCategory == paraCategory && m.IsActive); - return temp; + var temp1 = db.Queryable().Where(m => m.ParaCategory == paraCategory && m.IsActive); + return temp1; }catch (Exception ex) { LogHelper.Error(ex, "执行ParaConfigService下QueryTargetValWithParaCodeByParaCategery时异常"); return null; } } + private T_ParaColumnConfig QueryLinByParaCategeryAndParaCode(string paraCategory,string paraCode) + { + + T_ParaColumnConfig temp1 = db.Queryable(). + Where(m => m.ParaCategory == paraCategory && m.ParaCode == paraCode && m.IsActive). + First(); + if (temp1 == null) + { + throw new Exception("未维护数据!请先维护!"); + } + else + { + var temp2 = db.Queryable(). + Where(m => m.ParaCategory == paraCategory && m.ParaCode == paraCode && m.IsActive). + First().ProtocolType; + if (temp2 == null) + { + temp2 = "未配置通讯方式"; + } + return db.Queryable().Where(m => m.ParaCategory == paraCategory && m.ParaCode == paraCode && m.IsActive).First(); + } + } + private T_Protocol_Config QueryComByLin(string lin) + { + T_Protocol_Config temp1 = db.Queryable().Where(m => m.ProtocolCode == lin && m.IsActive).First(); + if (temp1 == null) + { + throw new Exception("未维护数据!请先维护!"); + } + string temp3 = db.Queryable().Where(m => m.ProtocolCode == lin && m.IsActive).First().ProtocolType; + if (temp3 == null) + { + temp3 = "未配置串口"; + } + return db.Queryable().Where(m => m.ProtocolCode == lin && m.IsActive).First(); + } /// - /// 根据参数种类查询有效参数配置项,例如传“BZ1”、“BZ2” + /// 根据参数种类查询有效参数配置项,例如传“BZ1_DB”、“BZ2_DB” /// /// /// - public ParaTargetValVM GetParaTargetVal(string paraCategory) + public EditonType GetParaTargetVal(ModeTypeEnum modeTypeEnum) { - ParaTargetValVM paraTargetVal = new ParaTargetValVM(); - var paraConfig = QueryTargetValWithParaCodeByParaCategery(paraCategory).ToList(); + EditonType editonType = new EditonType(); + var paraConfig = QueryTargetValWithParaCodeByParaCategery(modeTypeEnum.ToString()).ToList(); for (int i = 0; i < paraConfig.Count; i++) { - if(paraConfig[i].ParaCode == "STF1MS") + if(paraConfig[i].ParaCode == modeTypeEnum.ToString()) { - paraTargetVal.STF1TargetVal = paraConfig[i].TargetVal.ToString(); + if (paraConfig[i].TargetVal != null) { editonType.STF1.TargetVal = paraConfig[i].TargetVal.ToString(); } + else { editonType.STF1.TargetVal = "空值"; } + editonType.STF1.Lin = QueryLinByParaCategeryAndParaCode(modeTypeEnum.ToString(), paraConfig[i].ParaCode).ProtocolType; + editonType.STF1.Com = QueryComByLin(editonType.STF1.Lin).Port; continue; } - else if (paraConfig[i].ParaCode == "STF2MS") + else if (paraConfig[i].ParaCode == "FKSTF2ZT_DB") { - paraTargetVal.STF2TargetVal = paraConfig[i].TargetVal.ToString(); + if (paraConfig[i].TargetVal != null) { editonType.STF2.TargetVal = paraConfig[i].TargetVal.ToString(); } + else { editonType.STF2.TargetVal = "空值"; } + editonType.STF2.Lin = QueryLinByParaCategeryAndParaCode(modeTypeEnum.ToString(), paraConfig[i].ParaCode).ProtocolType; + editonType.STF2.Com = QueryComByLin(editonType.STF2.Lin).Port; continue; } - else if (paraConfig[i].ParaCode == "DZPZF1") + else if (paraConfig[i].ParaCode == "DZPZF1_DB") { - paraTargetVal.PZF1TargetVal = paraConfig[i].TargetVal.ToString(); + if (paraConfig[i].TargetVal != null) { editonType.PZF1.TargetVal = paraConfig[i].TargetVal.ToString(); } + else { editonType.PZF1.TargetVal = "空值"; } + editonType.PZF1.Lin = QueryLinByParaCategeryAndParaCode(modeTypeEnum.ToString(), paraConfig[i].ParaCode).ProtocolType; + editonType.PZF1.Com = QueryComByLin(editonType.PZF1.Lin).Port; continue; } - else if (paraConfig[i].ParaCode == "DZPZF2") + else if (paraConfig[i].ParaCode == "DZPZF2_DB") { - paraTargetVal.PZF2TargetVal = paraConfig[i].TargetVal.ToString(); + + if (paraConfig[i].TargetVal != null) { editonType.PZF2.TargetVal = paraConfig[i].TargetVal.ToString(); } + else { editonType.PZF2.TargetVal = "空值"; } + editonType.PZF2.Lin = QueryLinByParaCategeryAndParaCode(modeTypeEnum.ToString(), paraConfig[i].ParaCode).ProtocolType; + editonType.PZF2.Com = QueryComByLin(editonType.PZF2.Lin).Port; continue; } - else if (paraConfig[i].ParaCode == "SB1ZS") + else if (paraConfig[i].ParaCode == "SB1ZS_DB") { - paraTargetVal.SB1TargetVal = paraConfig[i].TargetVal.ToString(); + if (paraConfig[i].TargetVal != null) { editonType.SB1.TargetVal = paraConfig[i].TargetVal.ToString(); } + else { editonType.SB1.TargetVal = "空值"; } + editonType.SB1.Lin = QueryLinByParaCategeryAndParaCode(modeTypeEnum.ToString(), paraConfig[i].ParaCode).ProtocolType; + editonType.SB1.Com = QueryComByLin(editonType.SB1.Lin).Port; continue; } - else if (paraConfig[i].ParaCode == "SB2ZS") + else if (paraConfig[i].ParaCode == "SB2ZS_DB") { - paraTargetVal.SB2TargetVal = paraConfig[i].TargetVal.ToString(); + if (paraConfig[i].TargetVal != null) { editonType.SB2.TargetVal = paraConfig[i].TargetVal.ToString(); } + else { editonType.SB2.TargetVal = "空值"; } + editonType.SB2.Lin = QueryLinByParaCategeryAndParaCode(modeTypeEnum.ToString(), paraConfig[i].ParaCode).ProtocolType; + editonType.SB2.Com = QueryComByLin(editonType.SB2.Lin).Port; continue; } - else if (paraConfig[i].ParaCode == "SB3ZS") + else if (paraConfig[i].ParaCode == "SB3ZS_DB") { - paraTargetVal.SB3TargetVal = paraConfig[i].TargetVal.ToString(); + if (paraConfig[i].TargetVal != null) { editonType.SB3.TargetVal = paraConfig[i].TargetVal.ToString(); } + else { editonType.SB3.TargetVal = "空值"; } + editonType.SB3.Lin = QueryLinByParaCategeryAndParaCode(modeTypeEnum.ToString(), paraConfig[i].ParaCode).ProtocolType; + editonType.SB3.Com = QueryComByLin(editonType.SB3.Lin).Port; continue; } } - return paraTargetVal; + return editonType; } /// diff --git a/ProductionSystem_Service/ProductionSystem_Service.csproj b/ProductionSystem_Service/ProductionSystem_Service.csproj index 5533a5b..3ee7d6c 100644 --- a/ProductionSystem_Service/ProductionSystem_Service.csproj +++ b/ProductionSystem_Service/ProductionSystem_Service.csproj @@ -105,6 +105,7 @@ + diff --git a/ProductionSystem_UserControl/ExtendedControls/MyResultControl.cs b/ProductionSystem_UserControl/ExtendedControls/MyResultControl.cs index e17cf4d..4b85262 100644 --- a/ProductionSystem_UserControl/ExtendedControls/MyResultControl.cs +++ b/ProductionSystem_UserControl/ExtendedControls/MyResultControl.cs @@ -33,23 +33,29 @@ namespace ProductionSystem_UserControl.ExtendedControls get { return txtTestVal.Text; } set { - if (txtTestVal.Text == "停止") - { - txtTestVal.ForeColor = Color.Red; - } - else if(txtTestVal.Text == "启动") - { - txtTestVal.ForeColor = Color.Green; - } - else - { - txtTestVal.ForeColor = Color.Black; - } + //if (txtTestVal.Text == "停止") + //{ + // txtTestVal.ForeColor = Color.Red; + //} + //else if(txtTestVal.Text == "启动") + //{ + // txtTestVal.ForeColor = Color.Green; + //} + //else + //{ + // txtTestVal.ForeColor = Color.Black; + //} _testValText = value; txtTestVal.Text = _testValText; } } + + public void SetForeColor(Color color) + { + this.txtTestVal.ForeColor = color; + } + //添加背景颜色 ///