using System.Collections.Generic; using System.ComponentModel; using VirtualConveyor.Cache.Entity; using VirtualConveyor.Common.Entity; using VirtualConveyor.Conveyor.EnumType; using System; using System.Linq; namespace VirtualConveyor.Conveyor.Entity { public class GateEntity: BindableBase { /// /// 拥有更多该输送点的输送机 /// public ConveyorEntity Conveyor { get; private set; } /// /// 端口名称 /// public string Name { get; private set; } /// /// 4允许放货 /// private bool wPutDownLicense = true; public bool WPutDownLicense { get { return wPutDownLicense; } set { SetProperty(ref wPutDownLicense, value); } } /// /// 4允许取货 /// private bool wPickUpLicense = true; public bool WPickUpLicense { get { return wPickUpLicense; } set { SetProperty(ref wPickUpLicense, value); } } /// /// 到位信号 /// private bool wOccupied = true; public bool WOccupied { get { return wOccupied; } set { SetProperty(ref wOccupied, value); } } /// /// 7滚动开始 /// private bool wStartRotation = true; public bool WStartRotation { get { return wStartRotation; } set { SetProperty(ref wStartRotation, value); } } /// /// 8手动允许取货(输送机空闲) /// private bool wPickUpLicenseManual = true; public bool WPickUpLicenseManual { get { return wPickUpLicenseManual; } set { SetProperty(ref wPickUpLicenseManual, value); } } /// /// 9滚料完成 /// private bool wLayingOffComplete = true; public bool WLayingOffComplete { get { return wLayingOffComplete; } set { SetProperty(ref wLayingOffComplete, value); } } /// /// 10人工抽样结果 /// private int wCheckResult = -1; public int WCheckResult { get { return wCheckResult; } set { SetProperty(ref wCheckResult, value); } } /// /// 任务号 /// private string wtaskId; public string WTaskId { get { return wtaskId; } set { SetProperty(ref wtaskId, value); } } /// /// 任务号 /// private string taskId; public string TaskId { get { return taskId; } set { SetProperty(ref taskId, value); } } /// /// 5放货完成 /// private bool putSymbol; public bool PutSymbol { get { return putSymbol; } set { SetProperty(ref putSymbol, value); } } /// /// 6取货完成 /// private bool pickSymbol; public bool PickSymbol { get { return pickSymbol; } set { SetProperty(ref pickSymbol, value); } } /// /// 7手动放货完成 /// private bool putSymbolManual; public bool PutSymbolManual { get { return putSymbolManual; } set { SetProperty(ref putSymbolManual, value); } } /// /// WCS需要写入的OPC地址 /// public OpcWriteItem OpcWriteItems { get; set; } /// /// WCS需要读取的OPC地址 /// public OpcReadItem OpcReadItems { get; set; } private bool flag = false; /// /// 构造函数 /// /// 调用该货口的输送机 public GateEntity(ConveyorEntity conveyor,string name) { this.Conveyor = conveyor; this.Name = name; switch(name) { //输送机Conveyor1 //起始点 case "gate11": OpcReadItems = new OpcReadItem { TaskId = "S7:[@LOCALSERVER]DB1,STRING164.254", //任务号 PutSymbol = "S7:[@LOCALSERVER]DB1,X682.0",//放货完成 PutSymbolManual = "S7:[@LOCALSERVER]DB1,X682.2"//手动放货完成 }; OpcWriteItems = new OpcWriteItem { PutDownLicense = "S7:[@LOCALSERVER]DB1,X684.0",//允许放货 Occupied = "S7:[@LOCALSERVER]DB1,X684.1",//到位信号 StartRotation = "S7:[@LOCALSERVER]DB1,X688.0",//滚动开始 PickUpLicenseManual = "S7:[@LOCALSERVER]DB1,X688.1"//允许手动放货 }; break; //目标点立库入库口 case "gate12": OpcReadItems = new OpcReadItem { PickSymbol = "S7:[@LOCALSERVER]DB1,X952.1"//取货完成 }; OpcWriteItems = new OpcWriteItem { TaskId = "S7:[@LOCALSERVER]DB1,STRING164.254", //任务号 PickUpLicense = "S7:[@LOCALSERVER]DB1,X1466.0",//允许取货 Occupied = "S7:[@LOCALSERVER]DB1,X1466.1",//到位信号 CheckResult = "S7:[@LOCALSERVER]DB1,INT1988"//人工检验结果 }; break; //输送机conveyor2 //起始点立库出库口 case "gate21": OpcReadItems = new OpcReadItem { TaskId = "S7:[@LOCALSERVER]DB1,STRING1990.254", //任务号 PutSymbol = "S7:[@LOCALSERVER]DB1,X2250.0",//放货完成 S7:[@LOCALSERVER]DB1,X2250.1 }; OpcWriteItems = new OpcWriteItem { PutDownLicense = "S7:[@LOCALSERVER]DB1,X2508.1",//允许放货 Occupied = "S7:[@LOCALSERVER]DB1,X2508.0",//到位信号 StartRotation = "S7:[@LOCALSERVER]DB1,X2508.2",//滚动开始 }; break; //目标点 case "gate22": OpcReadItems = new OpcReadItem { PickSymbol = "S7:[@LOCALSERVER]DB1,X2766.0"//取货完成 }; OpcWriteItems = new OpcWriteItem { TaskId = "S7:[@LOCALSERVER]DB1,STRING1990.254", //任务号 PickUpLicense = "S7:[@LOCALSERVER]DB1,X3018.1",//允许取货 Occupied = "S7:[@LOCALSERVER]DB1,X3018.0",//到位信号 }; break; } this.PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged); var items = new List(); var values = new List(); if (!string.IsNullOrEmpty(this.OpcReadItems.TaskId)) { items.Add(this.OpcReadItems.TaskId); values.Add(0); } if (!string.IsNullOrEmpty(this.OpcReadItems.PutSymbol)) { items.Add(this.OpcReadItems.PutSymbol); values.Add(false); } if (!string.IsNullOrEmpty(this.OpcReadItems.PickSymbol)) { items.Add(this.OpcReadItems.PickSymbol); values.Add(false); } if (!string.IsNullOrEmpty(this.OpcReadItems.PutSymbolManual)) { items.Add(this.OpcReadItems.PutSymbolManual); values.Add(false); } CacheEntity.OpcWcfServiceClient.WriteValues(items.ToArray(), values.ToArray()); } /// /// GateEntity实体属性变化时触发的事件 /// /// /// private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case "WPickUpLicense": if (!string.IsNullOrEmpty(this.OpcWriteItems.PickUpLicense)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.PickUpLicense, this.WPickUpLicense); } break; case "WPutDownLicense": if (!string.IsNullOrEmpty(this.OpcWriteItems.PutDownLicense)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.PutDownLicense, this.WPutDownLicense); } break; case "WOccupied": if (!string.IsNullOrEmpty(this.OpcWriteItems.Occupied)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.Occupied, this.WOccupied); if(WOccupied) { if(!string.IsNullOrEmpty(this.OpcReadItems.PickSymbol)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcReadItems.PickSymbol,false); } } } break; case "WTaskId": if (!string.IsNullOrEmpty(this.OpcWriteItems.TaskId)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.TaskId, this.TaskId); } break; case "WStartRotation": if (!string.IsNullOrEmpty(this.OpcWriteItems.StartRotation)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.StartRotation, this.WStartRotation); } break; case "WPickUpLicenseManual": if (!string.IsNullOrEmpty(this.OpcWriteItems.PickUpLicenseManual)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.PickUpLicenseManual, this.WPickUpLicenseManual); } break; case "WLayingOffComplete": if (!string.IsNullOrEmpty(this.OpcWriteItems.LayingOffComplete)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.LayingOffComplete, this.WLayingOffComplete); } break; case "WCheckResult": if (!string.IsNullOrEmpty(this.OpcWriteItems.CheckResult)) { CacheEntity.OpcWcfServiceClient.WriteValue(this.OpcWriteItems.CheckResult, this.WCheckResult); } break; } } /// /// 接收任务 /// /// public bool ReceiveTask(out string msg) { msg = ""; var toPort = ""; switch(Name) { case "gate11": toPort = "gate12"; break; case "gate21": toPort = "gate22"; break; } var task = new TaskEntity { TaskId = TaskId, FromPort = Name, ToPort = toPort, Status = (int)ETaskStatus.未开始 }; if(!string.IsNullOrEmpty(OpcWriteItems.StartRotation)) { WStartRotation = false; } Conveyor.Tasks.Add(task); return true; } public bool StartTask(out string msg) { msg = ""; if (!PutSymbol || !PutSymbolManual) { msg = string.Format("端口{0}没有手动开始标志", Name); return false; } var task = Conveyor.Tasks.FirstOrDefault(x => x.FromPort == Name && x.Status == (int)ETaskStatus.未开始) ; if (task == null) { msg = string.Format("端口{0}没有找到未开始的任务", Name); return false; } task.Status = (int)ETaskStatus.执行中; if (!string.IsNullOrEmpty(OpcReadItems.PutSymbol)) { CacheEntity.OpcWcfServiceClient.WriteValue(OpcReadItems.PutSymbol, false); } if (!string.IsNullOrEmpty(OpcReadItems.PutSymbolManual)) { CacheEntity.OpcWcfServiceClient.WriteValue(OpcReadItems.PutSymbolManual, false); } PutSymbol = false; PutSymbolManual = false; flag = false; return true; } public bool FinishTask(out string msg) { msg = ""; if (!WOccupied) { msg = string.Format("端口{0}没有到位", Name); return false; } var name = Name; switch(Name) { case "gate11": name = "gate12"; break; case "gate21": name = "gate22"; break; } var task = Conveyor.Tasks.FirstOrDefault(x => x.ToPort == name && x.Status == (int)ETaskStatus.执行中); if (task == null) { msg = string.Format("端口{0}没有找到待完成的任务", name); return false; } task.Status = (int)ETaskStatus.已结束; return true; } } }