Browse Source

临时提交

谢翼翔 1 year ago
parent
commit
8dd01cbc11

+ 102 - 86
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Machines/CP1HMachine.cs

@@ -4,6 +4,7 @@ using SCADA.CommonLib;
 using SCADA.CommonLib.Data.DIL;
 using SCADA.Drive;
 using SCADA_DAQ.Customer.Models;
+using SCADA_DAQ.Plugin.Machine.Device;
 using SqlSchema.DBNames;
 using System;
 using System.Collections.Generic;
@@ -99,15 +100,12 @@ namespace SCADA_DAQ.Customer.Machines
                     {
                         if (ConnectState == SCADA.Comm.ConnectStates.Connected)
                         {
-                            var reg = (RegInfo)sender;
+                            var repairTime = this.GetListenReg("维修时间");
                             int RepairValueRegFlag = 0;
-                            if (reg.Comment.Variable == "维修时间")
-                            {
-
-                                RepairValueRegFlag = (int)reg.Value;
-                                if (reg.Value == 1)
+                            RepairValueRegFlag =(int)repairTime.Value;
+                            if (repairTime.Value == 1)
                                 {
-                                    RepairValueRegTrue = reg.Value == 1;
+                                    RepairValueRegTrue = true;
                                     RepairTime.OnOrgID_Str = Guid.NewGuid().ToString();
                                     RepairTime.StateOnTime_Dt = DateTime.Now;
                                     Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
@@ -117,26 +115,24 @@ namespace SCADA_DAQ.Customer.Machines
                                     new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "维修时间"));
 
                                 }
-                                else if (reg.Value == 0)
+                                else if (repairTime.Value == 0)
                                 {
-                                    RepairValueRegFalse = reg.Value == 0;
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                    $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
-                                    RepairTime.OnOrgID_Str = "";
-
-
-                                }
+                                    if (RepairTime.OnOrgID_Str != "")
+                                    {
+                                       RepairValueRegTrue = false;
+                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
+                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
+                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
+                                        RepairTime.OnOrgID_Str = "";
+                                    }
+                               
 
                             }
 
-
-                            if (reg.Comment.Variable == "运行标志位" && RepairValueRegFalse)
-                            {
-
-                                if (reg.Value == 1)
+                            var runTIme = this.GetListenReg("运行标志位");
+                              if (runTIme.Value == 1 &&  RepairValueRegTrue != true)
                                 {
                                     ProgramStart.OnOrgID_Str = Guid.NewGuid().ToString();
                                     ProgramStart.StateOnTime_Dt = DateTime.Now;
@@ -146,23 +142,23 @@ namespace SCADA_DAQ.Customer.Machines
                                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
                                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "运行标志位"));
                                 }
-                                else if (reg.Value == 0)
+                                else if (runTIme.Value == 0)
                                 {
+                                    if (ProgramStart.OnOrgID_Str != "")
+                                    {
+                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                       $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
+                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
+                                        ProgramStart.OnOrgID_Str = "";
 
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
-                                    ProgramStart.OnOrgID_Str = "";
+                                    }
 
 
                                 }
 
-                            }
-
-                            if (reg.Comment.Variable == "换模标志位" && RepairValueRegFalse)
-                            {
-                                if (reg.Value == 0)
+                            var changeMoldTime = this.GetListenReg("换模标志位");
+                               if (changeMoldTime.Value == 0 && RepairValueRegTrue != true)
                                 {
                                     ChangeModel.OnOrgID_Str = Guid.NewGuid().ToString();
                                     ChangeModel.StateOnTime_Dt = DateTime.Now;
@@ -174,18 +170,22 @@ namespace SCADA_DAQ.Customer.Machines
                                 }
                                 else
                                 {
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                        //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
-                                    ChangeModel.OnOrgID_Str = "";
+                                    if (ChangeModel.OnOrgID_Str != "")
+                                    {
+                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                      $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                                      new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                      //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
+                                      new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
+                                        ChangeModel.OnOrgID_Str = "";
+                                    }
+                                  
                                 }
-                            }
+                           
                             var runFlag = this.GetListenReg("运行标志位");
                             var toolChangeFlag = this.GetListenReg("换模标志位");
                             var repairFlag = this.GetListenReg("维修时间");
-                            reg = runFlag.Value == 1 ? runFlag : toolChangeFlag.Value == 0 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
+                            RegInfo reg = runFlag.Value == 1 ? runFlag : toolChangeFlag.Value == 0 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
                             if (reg == null)
                             {
                                 if (WaitNameStateCode != "停止标志位")
@@ -203,14 +203,19 @@ namespace SCADA_DAQ.Customer.Machines
                             }
                             else
                             {
-                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                        //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
-                                WaitTime.OnOrgID_Str = "";
-                                WaitNameStateCode = "";
+                                if (WaitTime.OnOrgID_Str != "")
+                                {
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                      $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
+                                      new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                      //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
+                                      new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                                    WaitTime.OnOrgID_Str = "";
+                                    WaitNameStateCode = "";
+                                }
+
                             }
+
                         }
                         else
                         {
@@ -244,7 +249,7 @@ namespace SCADA_DAQ.Customer.Machines
                         RepairValueRegFlag = (int)reg.Value;
                         if (reg.Value == 1)
                         {
-                            RepairValueRegTrue = reg.Value == 1;
+                            RepairValueRegTrue = true;
                             RepairTime.OnOrgID_Str = Guid.NewGuid().ToString();
                             RepairTime.StateOnTime_Dt = DateTime.Now;
                             Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
@@ -256,13 +261,17 @@ namespace SCADA_DAQ.Customer.Machines
                         }
                         else if (reg.Value == 0)
                         {
-                            RepairValueRegFalse = reg.Value == 0;
-                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                            $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
-                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
-                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
-                            RepairTime.OnOrgID_Str = "";
+                            RepairValueRegTrue = false;
+                            if (RepairTime.OnOrgID_Str != "")
+                            {
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                               $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
+                               new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                               new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
+                               new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
+                                RepairTime.OnOrgID_Str = "";
+                            }
+
 
 
                         }
@@ -270,7 +279,7 @@ namespace SCADA_DAQ.Customer.Machines
                     }
 
 
-                    if (reg.Comment.Variable == "运行标志位" && RepairValueRegFalse)
+                    if (reg.Comment.Variable == "运行标志位" && RepairValueRegTrue==false)
                     {
 
                         if (reg.Value == 1)
@@ -285,19 +294,20 @@ namespace SCADA_DAQ.Customer.Machines
                         }
                         else if (reg.Value == 0)
                         {
-
-                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                            if (ProgramStart.OnOrgID_Str != "")
+                            {
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
                                 $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
                                 new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
                                 new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
-                            ProgramStart.OnOrgID_Str = "";
-
+                                ProgramStart.OnOrgID_Str = "";
+                            }
 
                         }
 
                     }
 
-                    if (reg.Comment.Variable == "换模标志位" && RepairValueRegFalse)
+                    if (reg.Comment.Variable == "换模标志位" && RepairValueRegTrue == false)
                     {
                         if (reg.Value == 0)
                         {
@@ -311,12 +321,16 @@ namespace SCADA_DAQ.Customer.Machines
                         }
                         else
                         {
-                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
-                            ChangeModel.OnOrgID_Str = "";
+                            if (ChangeModel.OnOrgID_Str != "")
+                            {
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                         $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                         //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
+                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
+                                ChangeModel.OnOrgID_Str = "";
+                            }
+
                         }
                     }
                     var runFlag = this.GetListenReg("运行标志位");
@@ -341,13 +355,17 @@ namespace SCADA_DAQ.Customer.Machines
                     }
                     else
                     {
-                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
-                        WaitTime.OnOrgID_Str = "";
-                        WaitNameStateCode = "";
+                        if (WaitTime.OnOrgID_Str != "")
+                        {
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                              $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
+                              new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                              //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
+                              new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                            WaitTime.OnOrgID_Str = "";
+                            WaitNameStateCode = "";
+                        }
+
                     }
                 }
                 else
@@ -373,7 +391,6 @@ namespace SCADA_DAQ.Customer.Machines
             {
                 if (ConnectState != SCADA.Comm.ConnectStates.Connected)
                 {
-                    DeviceUpdate();
                     PowerOn.OnOrgID_Str = Guid.NewGuid().ToString();
                     Env.SqlDAL.App_Vertiv_WorkTime.Insert(
                         new UpdateItem(T_Col_Name.App_Vertiv_WorkTime.OrgID_Str, PowerOn.OnOrgID_Str),
@@ -403,7 +420,13 @@ namespace SCADA_DAQ.Customer.Machines
                         PowerOn.OnOrgID_Str = "";
                     }
 
-
+                    if (WaitTime.OnOrgID_Str != "")
+                    {
+                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                       $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
+                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                    }
 
 
                 }
@@ -443,7 +466,7 @@ namespace SCADA_DAQ.Customer.Machines
             {
                 if (ConnectState != SCADA.Comm.ConnectStates.Connected)
                 {
-                    if (WaitTime.OnOrgID_Str != null)
+                    if (WaitTime.OnOrgID_Str != "")
                     {
                         Env.SqlDAL.App_Vertiv_MachineInfo.Update(
                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
@@ -489,13 +512,6 @@ namespace SCADA_DAQ.Customer.Machines
             }
         }
 
-        public void DeviceUpdate()
-        {
-
-
-
-        }
-
 
         public override void Dispose()
         {

+ 17 - 14
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Machines/SampleMachine.cs

@@ -36,7 +36,7 @@ namespace SCADA_DAQ.Customer.Machines
 
         public DateTime StartTime { get; set; }
 
-
+        public string HoldID { get; set; }
         /// <summary>
         /// 计划停止时间
         /// </summary>
@@ -97,23 +97,26 @@ namespace SCADA_DAQ.Customer.Machines
                                 new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, name),
                                 new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "计划停止时间")
                                 );
+                                HoldID = OrgID;//缓存唯一码 防止设备掉线 计划停止时间结束更新不了
                             }
-
+                           
                             if (Value.EndTime.Hours == DateTime.Now.Hour &&
                                     Value.EndTime.Minutes == DateTime.Now.Minute)
                             {
-                                IsOpenTime = false;
-                                var stopTimeValue = DateTime.Now;
-                                var lastTime = stopTimeValue - StartTime;
-                                var lastTimeInt = (stopTimeValue - StartTime).TotalSeconds;
-                                Env.SqlDAL.App_Vertiv_MachineInfo.Update
-                                       (
-                                   $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{OrgID}'",
-                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, stopTimeValue),
-                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, lastTime),
-                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, lastTimeInt)
-                                       );
-                                OrgID = null;
+                               
+                                    IsOpenTime = false;
+                                    var stopTimeValue = DateTime.Now;
+                                    var lastTime = stopTimeValue - StartTime;
+                                    var lastTimeInt = (stopTimeValue - StartTime).TotalSeconds;
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update
+                                           (
+                                       $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{HoldID}'",
+                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, stopTimeValue),
+                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, lastTime),
+                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, lastTimeInt)
+                                           );
+                                    OrgID = null;
+                                    HoldID = null;
 
                             }
 

+ 1 - 1
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Env.cs

@@ -31,7 +31,7 @@ namespace SCADA_DAQ
         //public static SqlSchema.DIL.DILDB SqlDAL = new SqlSchema.DIL.DILDB("10.163.96.79", "Vertiv", "sa", "1qaz2wsx");
 
         public static SqlSchema.DIL.DILDB SqlDAL = new SqlSchema.DIL.DILDB("127.0.0.1", "Vertiv", "sa", "M+123456");
-       //public static SqlSchema.DIL.DILDB SqlDAL = new SqlSchema.DIL.DILDB("10.163.96.79", "Vertiv", "sa", "1qaz2wsx");
+        //public static SqlSchema.DIL.DILDB SqlDAL = new SqlSchema.DIL.DILDB("10.163.96.79", "Vertiv", "sa", "1qaz2wsx");
 
         //public static SqlSchema.DIL.DILDB SqlDAL;