|
@@ -0,0 +1,186 @@
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
+using SCADA;
|
|
|
+using SCADA.BarcodeReader;
|
|
|
+using SCADA.Comm;
|
|
|
+using SCADA.Drive;
|
|
|
+using SCADA_DAQ.Plugin.Machine;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.ComponentModel;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace SCADA_DAQ.Customer.Machines
|
|
|
+{
|
|
|
+ [DisplayName("东洋(TOYO)")]
|
|
|
+ public class TOYOSampleMachine : VirtualDevice
|
|
|
+ {
|
|
|
+ public TOYOSampleMachine()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ public TOYOSampleMachine(IComm comm, int address)
|
|
|
+ {
|
|
|
+ ListenReg.Add("报警时间", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "AlarmTime",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "AlarmTime", Annotation = "报警时间", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("报警代码", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "AlarmCode",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "AlarmCode", Annotation = "报警代码", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("报警信息", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "AlarmInfo",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "AlarmInfo", Annotation = "报警信息", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("报警DATA1", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "AlarmDATA1",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "AlarmDATA1", Annotation = "报警DATA1", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("报警DATA2", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "AlarmDATA2",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "AlarmDATA2", Annotation = "报警DATA2", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("模式切换时间", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "ModeTime",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "ModeTime", Annotation = "模式切换时间", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("模式代码", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "ModeCode",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "ModeCode", Annotation = "模式代码", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("模式信息", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "ModeInfo",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "ModeInfo", Annotation = "模式信息", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("产量推送时间", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "OutPutTime",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "OutPutTime", Annotation = "产量推送时间", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ ListenReg.Add("产量", new RegInfo
|
|
|
+ {
|
|
|
+ RegName = "OutPutQty",
|
|
|
+ Protocol = this,
|
|
|
+ RegKind = RegKind.IO,
|
|
|
+ StringValue = null,
|
|
|
+ Comment = new RegAnnotation { Variable = "OutPutQty", Annotation = "产量", IsReadOnly = true, ViewType = RegViewType.String }
|
|
|
+ });
|
|
|
+ //comm.ResponseInfos =
|
|
|
+ if (comm != null)
|
|
|
+ {
|
|
|
+ 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 override void Dispose()
|
|
|
+ {
|
|
|
+ if (Comm != null)
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|