mengshunguo 1 месяц назад
Родитель
Сommit
0707cd6b5c
1 измененных файлов с 87 добавлено и 44 удалено
  1. 87 44
      SCADA_DAQ/Customer/Machines/TOYOSampleMachine.cs

+ 87 - 44
SCADA_DAQ/Customer/Machines/TOYOSampleMachine.cs

@@ -2,6 +2,7 @@
 using SCADA;
 using SCADA.BarcodeReader;
 using SCADA.Comm;
+using SCADA.Drive;
 using SCADA_DAQ.Plugin.Machine;
 using System;
 using System.Collections.Generic;
@@ -12,59 +13,101 @@ using System.Threading.Tasks;
 
 namespace SCADA_DAQ.Customer.Machines
 {
-    public class TOYOSampleMachine : BaseDevice
+    [DisplayName("东洋(TOYO)")]
+    public class TOYOSampleMachine : VirtualDevice
     {
-        
+        public TOYOSampleMachine()
+        {
+
+        }
+        public TOYOSampleMachine(IComm comm, int address)
+        {
+            ListenReg.Add("报警触发时间", new RegInfo
+            { RegName = "报警触发时间",Protocol=this, RegKind = RegKind.IO,
+                Comment = new RegAnnotation { Variable = "报警触发时间", Annotation = "扫描周期(ms)", IsReadOnly = true } });
+            ListenReg.Add("报警代码", new RegInfo() { RegName = "报警代码", Comment = new RegAnnotation { } });
+            ListenReg.Add("报警信息", new RegInfo() { RegName = "报警信息", Comment = new RegAnnotation { } });
+            ListenReg.Add("报警DATA1", new RegInfo() { RegName = "报警DATA1", Comment = new RegAnnotation { } });
+            ListenReg.Add("报警DATA2", new RegInfo() { RegName = "报警DATA2", Comment = new RegAnnotation { } });
+            ListenReg.Add("模式触发时间", new RegInfo() { RegName = "模式触发时间", Comment = new RegAnnotation { } });
+            ListenReg.Add("模式代码", new RegInfo() { RegName = "模式代码", Comment = new RegAnnotation { } });
+            ListenReg.Add("模式信息", new RegInfo() { RegName = "模式信息", Comment = new RegAnnotation { } });
+            ListenReg.Add("产量推送时间", new RegInfo() { RegName = "产量推送时间", Comment = new RegAnnotation { } });
+            ListenReg.Add("产量信息", new RegInfo() { RegName = "产量信息", Comment = new RegAnnotation { } });
+            //comm.ResponseInfos = 
+            comm.ResponseInfos = new List<ResponseInfo>() { new ResponseInfo() { ResponseType = ResponseType.UnKnown } };
+            comm.DataReceived += Comm_DataReceived;
+            Comm = comm;
+        }
+        public TOYOSampleMachine(IComm comm, string address) : this(comm, 0)
+        {
+
+        }
 
-        public string ip = new BarcodeReader(Comm,);
 
-        private TcpComm comm;
 
-        public string MachieID;
+        public override void Dispose()
+        {
+            Comm.DataReceived -= Comm_DataReceived;
+            base.Dispose();
+        }
+        private void Comm_DataReceived(object sender, DataReceivedEventArg e)
+        {
+            string triggerTime;
+            string identifier;
+            string schemaCode;
+            string patternCharacters;
+            string data1;
+            string data2;
+            string qty;
+            var receiveMSGStr = e.ReceiveMsg.Replace(" ", "");
+            var receiveMSGArray = receiveMSGStr.Split(',');
+            identifier = receiveMSGArray[1];
+            if (identifier == "32" || identifier == "30")
+            {
+                if (identifier == "32")
+                {
+                    triggerTime = $"{receiveMSGArray[2]}/{receiveMSGArray[3]}";
+                    schemaCode = receiveMSGArray[4];
+                    patternCharacters = receiveMSGArray[5];
+                    ListenReg["模式触发时间"].StringValue = triggerTime;
+                    ListenReg["模式代码"].StringValue = schemaCode;
+                    ListenReg["模式信息"].StringValue = patternCharacters;
+                    //log($"收到设备模式数据,设备名{MachieID},触发时间{triggerTime},模式代码{schemaCode},模式字符{patternCharacters}");
+                }
+                else
+                {
+                    triggerTime = $"{receiveMSGArray[2]}/{receiveMSGArray[3]}";
+                    schemaCode = receiveMSGArray[4];
+                    data1 = receiveMSGArray[5];
+                    data2 = receiveMSGArray[6];
+                    patternCharacters = receiveMSGArray[7];
+                    ListenReg["报警触发时间"].StringValue = triggerTime;
+                    ListenReg["报警代码"].StringValue = schemaCode;
+                    ListenReg["报警信息"].StringValue = patternCharacters;
+                    ListenReg["报警DATA1"].StringValue = data1;
+                    ListenReg["报警DATA2"].StringValue = data2;
+                    //Log.Info($"收到设备报警数据,设备名{MachieID},触发时间{triggerTime},报警代码{schemaCode},报警字符{patternCharacters},DATA1{data1},DATA2{data2}");
+                }
+
+            }
+            else if (identifier == "33")
+            {
+                triggerTime = $"{receiveMSGArray[2]}-{receiveMSGArray[3]}-{receiveMSGArray[4]}/{receiveMSGArray[5]}:{receiveMSGArray[6]}:{receiveMSGArray[7]}";
+                qty = receiveMSGArray[8];
+                ListenReg["产量推送时间"].StringValue = triggerTime;
+                ListenReg["产量信息"].StringValue = qty;
+                //Log.Info($"收到设备报警数据,设备名{MachieID},生产时间{triggerTime},产量{qty}PCS");
+            }
+        }
+
+        //public string MachieID;
 
         public override ExecuteResult<bool> WriteReg(string regName, params int[] @params)
         {
             throw new NotImplementedException();
-        }
 
-        //private void Comm_DataReceived(object sender, DataReceivedEventArg e)
-        //{
-        //    string triggerTime;
-        //    string identifier;
-        //    string schemaCode;
-        //    string patternCharacters;
-        //    string data1;
-        //    string data2;
-        //    string qty;
-        //    var receiveMSGStr = e.ReceiveMsg.Replace(" ", "");
-        //    var receiveMSGArray = receiveMSGStr.Split(',');
-        //    identifier = receiveMSGArray[1];
-        //    if (identifier == "32" || identifier == "30")
-        //    {
-        //        if (identifier == "32")
-        //        {
-        //            triggerTime = $"{receiveMSGArray[2]}/{receiveMSGArray[3]}";
-        //            schemaCode = receiveMSGArray[4];
-        //            patternCharacters = receiveMSGArray[5];
-        //            //Log.Info($"收到设备模式数据,设备名{MachieID},触发时间{triggerTime},模式代码{schemaCode},模式字符{patternCharacters}");
-        //        }
-        //        else
-        //        {
-        //            triggerTime = $"{receiveMSGArray[2]}/{receiveMSGArray[3]}";
-        //            schemaCode = receiveMSGArray[4];
-        //            data1 = receiveMSGArray[5];
-        //            data2 = receiveMSGArray[6];
-        //            patternCharacters = receiveMSGArray[7];
-        //            //Log.Info($"收到设备报警数据,设备名{MachieID},触发时间{triggerTime},报警代码{schemaCode},报警字符{patternCharacters},DATA1{data1},DATA2{data2}");
-        //        }
+        }
 
-        //    }
-        //    else if (identifier == "33")
-        //    {
-        //        triggerTime = $"{receiveMSGArray[2]}-{receiveMSGArray[3]}-{receiveMSGArray[4]}/{receiveMSGArray[5]}:{receiveMSGArray[6]}:{receiveMSGArray[7]}";
-        //        qty =receiveMSGArray[8];
-        //        //Log.Info($"收到设备报警数据,设备名{MachieID},生产时间{triggerTime},产量{qty}PCS");
-        //    }
-        //}
     }
 }