diff --git a/HHWCSHost/View/Frm_Main.xaml.cs b/HHWCSHost/View/Frm_Main.xaml.cs index c009363..b614752 100644 --- a/HHWCSHost/View/Frm_Main.xaml.cs +++ b/HHWCSHost/View/Frm_Main.xaml.cs @@ -22,7 +22,8 @@ namespace HHWCSHost.View { #region 属性 - const string plcAdressPrefix = "S7:[S7 connection_1]"; + //const string plcAdressPrefix = "S7:[S7 connection_1]"; + private object locker = new object(); //所有子窗口 Dictionary<string, Window> windows = new Dictionary<string, Window>(); @@ -64,7 +65,7 @@ namespace HHWCSHost.View InitTimer(); InitOPC(); InitDeviceData(); - InitStockerAndStationMonitor(); + //InitStockerAndStationMonitor(); } #region 初始化 @@ -86,28 +87,28 @@ namespace HHWCSHost.View DevicePropEntities = temp3.Data; DeviceTypeEntities = temp4.Data; //属性地址校验 - //foreach (var item in DeviceEntities) - //{ - // if (DeviceAddressEntities.Count(t => t.DeviceId == item.Id) == 0) - // { - // String msg = "错误:设备" + item.Code + " " + item.Name + "无属性地址"; - // MessageBox.Show("msg"); - // AddLogToUI(msg, 2); - // btn_OpenPLCConnect.IsEnabled = false; - // return; - // } - // //todo:校验属性是否都存在 - // if (DevicePropEntities.Count(t => t.DeviceTypeId == item.DeviceTypeId) != DeviceAddressEntities.Count(t => t.DeviceId == item.Id)) - // { - // String msg = "错误:设备" + item.Code + " " + item.Name + "属性地址与类型属性规定不一致"; - // MessageBox.Show("msg"); - // AddLogToUI(msg, 2); - // btn_OpenPLCConnect.IsEnabled = false; - // return; - // } - //} + foreach (var item in DeviceEntities) + { + if (DeviceAddressEntities.Count(t => t.DeviceId == item.Id) == 0) + { + String msg = "错误:设备" + item.Code + " " + item.Name + "无属性地址"; + MessageBox.Show("msg"); + AddLogToUI(msg, 2); + btn_OpenPLCConnect.IsEnabled = false; + return; + } + //todo:校验属性是否都存在 + if (DevicePropEntities.Count(t => t.DeviceTypeId == item.DeviceTypeId) != DeviceAddressEntities.Count(t => t.DeviceId == item.Id)) + { + String msg = "错误:设备" + item.Code + " " + item.Name + "属性地址与类型属性规定不一致"; + MessageBox.Show("msg"); + AddLogToUI(msg, 2); + btn_OpenPLCConnect.IsEnabled = false; + return; + } + } //属性地址获取无误后初始化监控 - //InitStockerAndStationMonitor(); + InitStockerAndStationMonitor(); } private void InitStockerAndStationMonitor() @@ -164,7 +165,7 @@ namespace HHWCSHost.View try { PLCIP = ConfigurationManager.AppSettings["OPCServerIP"]; - PLC = new OPCHelp("192.168.10.100"); + PLC = new OPCHelp(PLCIP); } catch (Exception ex) { @@ -266,7 +267,7 @@ namespace HHWCSHost.View for (int i = 0; i < DeviceAddressEntities.Count; i++) { var temp = DeviceAddressEntities[i]; - ServerHandle[i] = PLC.AddAddr(plcAdressPrefix + temp.Address, i); + ServerHandle[i] = PLC.AddAddr(temp.Address, i); temp.ServerHandle = ServerHandle[i]; } } @@ -309,10 +310,45 @@ namespace HHWCSHost.View private void OnTimedEvent(object sender, ElapsedEventArgs e) { //同步线程防止重入 - if (Interlocked.Exchange(ref inTimer, 1) == 0) + //if (Interlocked.Exchange(ref inTimer, 1) == 0) + //{ + lock (locker) { + //AddLogToUI("线程" + Thread.CurrentThread.ManagedThreadId + "进入", 1); + //Thread.Sleep(5000); + //return; + //todo:完善主控时钟 + #region 检查是否连接正常 + if (PLC.GetConnStatus()) + { + this.Dispatcher.Invoke(new Action(() => + { + if (this.grid.Background == Brushes.Red) + { + this.grid.Background = Brushes.White; + } + })); + } + else + { + this.Dispatcher.Invoke(new Action(() => + { + if (this.grid.Background != Brushes.Red) + { + this.grid.Background = Brushes.Red; + } + if (!((TextBlock)this.LogInfo.list_Log.SelectedItem).Text.Contains("失去通讯连接,请关闭连接后重新打开")) + { + this.LogInfo.AddLogs("失去通讯连接,请关闭连接后重新打开", 2); + } + })); + //这里直接retrun,并没有更改inTimer的值,后续不会再次进入这个循环,需要关闭连接然后重新打开连接来重置这个参数; + return; + } + #endregion + #region 测试监控赋值 InitDeviceData(); @@ -320,16 +356,16 @@ namespace HHWCSHost.View DeviceEntities.ForEach(item => DeviceAddressEntities.FindAll(t => t.DeviceId == item.Id).Join(DevicePropEntities.FindAll(t => t.DeviceTypeId == item.DeviceTypeId && t.IsMonitor == 1), t => t.DevicePropCode, a => a.Code, (a, b) => new { a, b }).Where(t => t.a.value != t.b.MonitorCompareValue).Select(t => t.b).ToList().ForEach(t => AddLogToUI("报警:" + t.Name + " 信息:" + t.MonitorFailure, 2))); //底部面板 Dispatcher.Invoke(new Action(() => + { + foreach (var item in panel_Bottom.Children) + { + if (item is StockerInfo temp) { - foreach (var item in panel_Bottom.Children) - { - if (item is StockerInfo temp) - { - var a = DeviceEntities.Find(t => t.Code == temp.Name); - temp.SetProps(DeviceEntities.Find(t => t.Code == temp.Name), DevicePropEntities.FindAll(t => t.DeviceTypeId == a.DeviceTypeId), DeviceAddressEntities.FindAll(t => t.DeviceId == a.Id)); - } - }; + var a = DeviceEntities.Find(t => t.Code == temp.Name); + temp.SetProps(DeviceEntities.Find(t => t.Code == temp.Name), DevicePropEntities.FindAll(t => t.DeviceTypeId == a.DeviceTypeId), DeviceAddressEntities.FindAll(t => t.DeviceId == a.Id)); } + }; + } )); //图形监控 Dispatcher.Invoke(new Action(() => @@ -378,35 +414,6 @@ namespace HHWCSHost.View //return; #endregion - #region 检查是否连接正常 - if (PLC.GetConnStatus()) - { - this.Dispatcher.Invoke(new Action(() => - { - if (this.grid.Background == Brushes.Red) - { - this.grid.Background = Brushes.White; - } - })); - } - else - { - this.Dispatcher.Invoke(new Action(() => - { - if (this.grid.Background != Brushes.Red) - { - this.grid.Background = Brushes.Red; - } - if (!((TextBlock)this.LogInfo.list_Log.SelectedItem).Text.Contains("失去通讯连接,请关闭连接后重新打开")) - { - this.LogInfo.AddLogs("失去通讯连接,请关闭连接后重新打开", 2); - } - })); - //这里直接retrun,并没有更改inTimer的值,后续不会再次进入这个循环,需要关闭连接然后重新打开连接来重置这个参数; - return; - } - #endregion - #region 堆垛机操作 //找出所有堆垛机 var stockersResult = FindDevByType("stocker"); @@ -438,18 +445,71 @@ namespace HHWCSHost.View var readResult = ReadAddress(addresses); if (readResult.Success) { - if (ValidateStationForStockerIn(addresses)) + //if (ValidateStationForStockerIn(addresses)) + //{ + // //查询对应堆垛机是否达到可以入库的状态 + // var stocker = FindDevByType("stocker").Data.Find(t => t.Roadway == stationForStockerIn.Roadway); + // if (stocker != null) + // { + // if (ValidateStockerOut(DeviceAddressEntities.FindAll(t => t.DeviceId == stocker.Id))) + // { + // //todo:下发堆垛机任务,响应站台,待站台逻辑理清后再做处理 + // //待站台逻辑 + + // } + // } + //} + //这里先直接回应一个响应 + //如果PLC标记为3,则表示解析有误,这里报警 + if (addresses.Find(t => t.DevicePropCode == "Flag").value == "3") { - //查询对应堆垛机是否达到可以入库的状态 - var stocker = FindDevByType("stocker").Data.Find(t => t.Roadway == stationForStockerIn.Roadway); - if (stocker != null) + AddLogToUI("PLC解析站台" + stationForStockerIn + "数据失败,请检查基础数据!", 2); + continue; + } + //PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误 + if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1") + { + continue; + } + //PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息 + if (addresses.Find(t => t.DevicePropCode == "Flag").value != "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1") + { + var result = WriteWCSStationDataAddress(addresses, "0", "0", "0", "0", "0", "0", "", "0", "0"); + if (result.Success) { - if (ValidateStockerOut(DeviceAddressEntities.FindAll(t => t.DeviceId == stocker.Id))) - { - //todo:下发堆垛机任务,响应站台,待站台逻辑理清后再做处理 - //待站台逻辑 + AddLogToUI("清空" + stationForStockerIn + "WCS区地址成功", 1); + } + else + { + AddLogToUI("清空" + stationForStockerIn + "WCS区地址失败:" + result.Msg, 2); + } + continue; + } + //PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC + if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value != "1") + { + //判断报文类型 + if (addresses.Find(t => t.DevicePropCode == "Type").value == "1") + { + //地址请求 + AddLogToUI("堆垛机接入站台" + stationForStockerIn + "暂时没有实现地址请求", 1); + continue; + } + if (addresses.Find(t => t.DevicePropCode == "Type").value == "2") + { + //给他回一个位置到达 + //响应一个位置请求 + var temp = WriteWCSStationDataAddress(addresses, "1", "8", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, "", "0"); + if (temp.Success) + { + AddLogToUI("位置到达写入" + stationForStockerIn + "WCS区地址成功", 1); } + else + { + AddLogToUI("位置到达写入" + stationForStockerIn + "WCS区地址失败:" + temp.Msg, 2); + } + continue; } } } @@ -489,35 +549,7 @@ namespace HHWCSHost.View //PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息 if (addresses.Find(t => t.DevicePropCode == "Flag").value != "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1") { - List<DeviceAddressEntity> temp = new List<DeviceAddressEntity>(); - var wcsflag = addresses.Find(t => t.DevicePropCode == "WCSFlag"); - wcsflag.value = "0"; - var wcstype = addresses.Find(t => t.DevicePropCode == "WCSType"); - wcstype.value = "0"; - var wcsplcno = addresses.Find(t => t.DevicePropCode == "WCSPLCNo"); - wcsplcno.value = "0"; - var wcsloadstatus = addresses.Find(t => t.DevicePropCode == "LoadStatus"); - wcsloadstatus.value = "0"; - var wcsstationno = addresses.Find(t => t.DevicePropCode == "WCSStationNo"); - wcsstationno.value = "0"; - var wcstaskno = addresses.Find(t => t.DevicePropCode == "WCSTaskNo"); - wcstaskno.value = "0"; - var wcsbarcode = addresses.Find(t => t.DevicePropCode == "WCSBarcode"); - wcsbarcode.value = ""; - var wcstoaddress = addresses.Find(t => t.DevicePropCode == "WCSToAddress"); - wcstoaddress.value = "0"; - var wcsbackup = addresses.Find(t => t.DevicePropCode == "WCSBackUp"); - wcsbackup.value = "0"; - temp.Add(wcsflag); - temp.Add(wcstype); - temp.Add(wcsplcno); - temp.Add(wcsloadstatus); - temp.Add(wcsstationno); - temp.Add(wcstaskno); - temp.Add(wcsbarcode); - temp.Add(wcstoaddress); - temp.Add(wcsbackup); - var result = WriteAddress(temp); + var result = WriteWCSStationDataAddress(addresses, "0", "0", "0", "0", "0", "0", "", "0", "0"); if (result.Success) { AddLogToUI("清空" + stationForStockerOut + "WCS区地址成功", 1); @@ -543,35 +575,7 @@ namespace HHWCSHost.View if (station != null) { //写入响应数据 - List<DeviceAddressEntity> temp = new List<DeviceAddressEntity>(); - var wcsflag = addresses.Find(t => t.DevicePropCode == "WCSFlag"); - wcsflag.value = "1"; - var wcstype = addresses.Find(t => t.DevicePropCode == "WCSType"); - wcstype.value = "6"; - var wcsplcno = addresses.Find(t => t.DevicePropCode == "WCSPLCNo"); - wcsplcno.value = addresses.Find(t => t.DevicePropCode == "PLCNo").value; - var wcsloadstatus = addresses.Find(t => t.DevicePropCode == "LoadStatus"); - wcsloadstatus.value = "0"; - var wcsstationno = addresses.Find(t => t.DevicePropCode == "WCSStationNo"); - wcsstationno.value = addresses.Find(t => t.DevicePropCode == "StationNo").value; - var wcstaskno = addresses.Find(t => t.DevicePropCode == "WCSTaskNo"); - wcstaskno.value = addresses.Find(t => t.DevicePropCode == "TaskNo").value; - var wcsbarcode = addresses.Find(t => t.DevicePropCode == "WCSBarcode"); - wcsbarcode.value = addresses.Find(t => t.DevicePropCode == "Barcode").value; - var wcstoaddress = addresses.Find(t => t.DevicePropCode == "WCSToAddress"); - wcstoaddress.value = station.SelfAddress.ToString(); - var wcsbackup = addresses.Find(t => t.DevicePropCode == "WCSBackUp"); - wcsbackup.value = "0"; - temp.Add(wcsflag); - temp.Add(wcstype); - temp.Add(wcsplcno); - temp.Add(wcsloadstatus); - temp.Add(wcsstationno); - temp.Add(wcstaskno); - temp.Add(wcsbarcode); - temp.Add(wcstoaddress); - temp.Add(wcsbackup); - var result = WriteAddress(temp); + var result = WriteWCSStationDataAddress(addresses, "1", "6", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, station.SelfAddress.ToString(), "0"); if (result.Success) { AddLogToUI("写入" + stationForStockerOut + "WCS区地址成功", 1); @@ -585,7 +589,6 @@ namespace HHWCSHost.View { AddLogToUI("未找到出库站台", 2); } - } //hack:出库对位置到达和控制指令如何回复? @@ -628,35 +631,7 @@ namespace HHWCSHost.View //PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息 if (addresses.Find(t => t.DevicePropCode == "Flag").value != "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1") { - List<DeviceAddressEntity> temp = new List<DeviceAddressEntity>(); - var wcsflag = addresses.Find(t => t.DevicePropCode == "WCSFlag"); - wcsflag.value = "0"; - var wcstype = addresses.Find(t => t.DevicePropCode == "WCSType"); - wcstype.value = "0"; - var wcsplcno = addresses.Find(t => t.DevicePropCode == "WCSPLCNo"); - wcsplcno.value = "0"; - var wcsloadstatus = addresses.Find(t => t.DevicePropCode == "LoadStatus"); - wcsloadstatus.value = "0"; - var wcsstationno = addresses.Find(t => t.DevicePropCode == "WCSStationNo"); - wcsstationno.value = "0"; - var wcstaskno = addresses.Find(t => t.DevicePropCode == "WCSTaskNo"); - wcstaskno.value = "0"; - var wcsbarcode = addresses.Find(t => t.DevicePropCode == "WCSBarcode"); - wcsbarcode.value = ""; - var wcstoaddress = addresses.Find(t => t.DevicePropCode == "WCSToAddress"); - wcstoaddress.value = "0"; - var wcsbackup = addresses.Find(t => t.DevicePropCode == "WCSBackUp"); - wcsbackup.value = "0"; - temp.Add(wcsflag); - temp.Add(wcstype); - temp.Add(wcsplcno); - temp.Add(wcsloadstatus); - temp.Add(wcsstationno); - temp.Add(wcstaskno); - temp.Add(wcsbarcode); - temp.Add(wcstoaddress); - temp.Add(wcsbackup); - var result = WriteAddress(temp); + var result = WriteWCSStationDataAddress(addresses, "0", "0", "0", "0", "0", "0", "", "0", "0"); if (result.Success) { AddLogToUI("清空" + station + "WCS区地址成功", 1); @@ -668,12 +643,11 @@ namespace HHWCSHost.View continue; } - //PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value != "1") { //获取任务 - string pallet = addresses.Find(t => t.DevicePropCode == "").value; + string pallet = addresses.Find(t => t.DevicePropCode == "Barcode").value; var taskResult = Bll.GetTaskUncompleteByPalletCode(pallet); if (!taskResult.Success) { @@ -681,8 +655,6 @@ namespace HHWCSHost.View continue; } TaskEntity taskEntity = taskResult.Data; - //string pallet = addresses.Find(t => t.DevicePropCode == "").value; - //var taskResult = Bll.GetTaskUncompleteByPalletCode(pallet); //判断报文类型 if (addresses.Find(t => t.DevicePropCode == "Type").value == "1") { @@ -694,27 +666,97 @@ namespace HHWCSHost.View var locationResult = Bll.GetAllLocations(null, null, null, null, null, null, taskEntity.DestinationLocation); if (!locationResult.Success) { - AddLogToUI("未找到任务" + taskEntity.Id + "对应的"+taskEntity.DestinationLocation+"库位",2); + AddLogToUI("未找到任务" + taskEntity.Id + "对应的" + taskEntity.DestinationLocation + "库位", 2); + continue; + } + location = locationResult.Data[0]; + } + else if (taskEntity.Type == 200 || taskEntity.Type == 400 || taskEntity.Type == 700) + { + var locationResult = Bll.GetAllLocations(null, null, null, null, null, null, taskEntity.SourceLocation); + if (!locationResult.Success) + { + AddLogToUI("未找到任务" + taskEntity.Id + "对应的" + taskEntity.SourceLocation + "库位", 2); continue; } location = locationResult.Data[0]; } - if(taskEntity.Type == 200 || taskEntity.Type == 400 || taskEntity.Type == 700) + else + { + AddLogToUI("任务" + taskEntity.Id + "对应的类型" + taskEntity.Type + "不符合地址请求要求", 2); + continue; + } + //获取这个库位的目标巷道,从而得出对应的接入站台 + var stockerStationIns = DeviceEntities.Join(DeviceTypeEntities, t => t.DeviceTypeId, a => a.Id, (a, b) => new { a, b }).Where(t => t.b.Code == "stationForStockerIn" && t.a.Roadway == location.Roadway).Select(t => t.a).ToList(); + if (stockerStationIns.Count == 0) { - // + AddLogToUI("未找到任务" + taskEntity.Id + "对应的堆垛机接入站台,巷道:" + location.Roadway + ",托盘:" + taskEntity.ContainerCode, 2); + continue; + } + else + { + var stockerStationIn = stockerStationIns[0]; + //写入响应地址 + var result = WriteWCSStationDataAddress(addresses, "1", "06", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, stockerStationIn.SelfAddress.ToString(), "0"); + if (result.Success) + { + AddLogToUI("写入" + stockerStationIn + "WCS区地址成功", 1); + } + else + { + AddLogToUI("写入" + stockerStationIn + "WCS区地址失败:" + result.Msg, 2); + } } } if (addresses.Find(t => t.DevicePropCode == "Type").value == "2") { - //表示位置到达,此时检查任务,如果是整出则完成任务 - + //表示位置到达,此时检查任务,如果是整出、空出则完成任务 + if (taskEntity.Type == 300 || taskEntity.Type == 600) + { + var result = Bll.CompleteTask(taskEntity.Id.ToString()); + if (result.Success) + { + AddLogToUI("站台" + station + ",完成" + taskEntity.Id.ToString() + "成功", 1); + } + else + { + AddLogToUI("完成任务" + taskEntity.Id.ToString() + "失败:" + result.Msg, 2); + continue; + } + } + else + { + //如果是其他类型的任务则更新状态为到达站台并响应 + var result = Bll.SetTaskStatus(taskEntity.Id, 30); + if (result.Success) + { + AddLogToUI("站台" + station + ",更新任务状态" + taskEntity.Id.ToString() + "成功", 1); + } + else + { + AddLogToUI("站台" + station + ",更新任务状态" + taskEntity.Id.ToString() + "失败:" + result.Msg, 2); + continue; + } + } + //响应一个位置请求 + var temp = WriteWCSStationDataAddress(addresses, "1", "8", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, "", "0"); + if (temp.Success) + { + AddLogToUI("位置到达写入" + station + "WCS区地址成功", 1); + } + else + { + AddLogToUI("位置到达写入" + station + "WCS区地址失败:" + temp.Msg, 2); + } + continue; } if (addresses.Find(t => t.DevicePropCode == "Type").value == "3") { //表示控制指令 //todo:控制指令先不弄 + AddLogToUI("控制指令暂时没有实现", 1); } } @@ -727,9 +769,9 @@ namespace HHWCSHost.View } #endregion - - Interlocked.Exchange(ref inTimer, 0); } + //Interlocked.Exchange(ref inTimer, 0); + //} } #region 功能函数 @@ -753,34 +795,42 @@ namespace HHWCSHost.View foreach (var stocker in stockers) { var propDatas = DeviceAddressEntities.FindAll(t => t.DeviceId == stocker.Id); - if (ReadAddress(propDatas) && ValidateStockerForCompleteTask(stocker)) + var result = ReadAddress(propDatas); + if (result.Success) { - //现获取要写入的数据的转换后类型,如果转换出错就不进行处理 - BllResult writeDataResult = TansforWCSDataToAddressData(DevicePropEntities.Find(t => t.DeviceTypeId == stocker.DeviceTypeId && t.Code == "TaskNo1").Type, "0"); - if (!writeDataResult.Success) - { - AddLogToUI(writeDataResult.Msg, 2); - break; - } - //获取任务号 - var writeData = writeDataResult.Data; - var propData = propDatas.Find(t => t.DevicePropCode == "TaskNo1"); - var taskCompleteResult = Bll.CompleteTask(propData.value); - if (taskCompleteResult.Success) + if (ValidateStockerForCompleteTask(stocker)) { - //任务完成成功:任务执行完成后由PLC向WCS发送任务完成消息,WCS清除任务信息,随后PLC更新堆垛机状态为待机 - //清除任务 - bool writeFlag = PLC.WriteData(new int[] { propData.ServerHandle }, new object[] { writeData }); - if (!writeFlag) + //现获取要写入的数据的转换后类型,如果转换出错就不进行处理 + BllResult writeDataResult = TansforWCSDataToAddressData(DevicePropEntities.Find(t => t.DeviceTypeId == stocker.DeviceTypeId && t.Code == "TaskNo1").Type, "0"); + if (!writeDataResult.Success) { - AddLogToUI("完成任务" + propData.value + "成功,但是清除堆垛机" + stocker.ToString() + "任务失败", 2); + AddLogToUI(writeDataResult.Msg, 2); + break; + } + //获取任务号 + var writeData = writeDataResult.Data; + var propData = propDatas.Find(t => t.DevicePropCode == "TaskNo1"); + var taskCompleteResult = Bll.CompleteTask(propData.value); + if (taskCompleteResult.Success) + { + //任务完成成功:任务执行完成后由PLC向WCS发送任务完成消息,WCS清除任务信息,随后PLC更新堆垛机状态为待机 + //清除任务 + bool writeFlag = PLC.WriteData(new int[] { propData.ServerHandle }, new object[] { writeData }); + if (!writeFlag) + { + AddLogToUI("完成任务" + propData.value + "成功,但是清除堆垛机" + stocker.ToString() + "任务失败", 2); + } + } + else + { + AddLogToUI("任务" + propData.value + " 堆垛机" + stocker.ToString() + "完成任务失败:" + taskCompleteResult.Msg, 2); } - } - else - { - AddLogToUI("任务" + propData.value + " 堆垛机" + stocker.ToString() + "完成任务失败:" + taskCompleteResult.Msg, 2); } } + else + { + AddLogToUI("读取" + stocker + "地址数据失败:" + result.Msg, 2); + } } } @@ -884,35 +934,43 @@ namespace HHWCSHost.View //地址校验交由初始化完成 var props = DeviceAddressEntities.Where(t => t.DeviceId == stocker.Id).ToList(); //堆垛机出库任务校验 - if (ReadAddress(props) && ValidateStockerOut(props)) + var result = ReadAddress(props); + if (result.Success) { - //校验对应堆垛机接出站台是否可以,按巷道查询 - var stationForStockerOutResult = FindDevByType("stationForStockerOut"); - if (stationForStockerOutResult.Success) + if (ValidateStockerOut(props)) { - var stationForStockerOuts = stationForStockerOutResult.Data.FindAll(t => t.Roadway == location.Roadway); - foreach (var stationForStockerOut in stationForStockerOuts) + //校验对应堆垛机接出站台是否可以,按巷道查询 + var stationForStockerOutResult = FindDevByType("stationForStockerOut"); + if (stationForStockerOutResult.Success) { - //校验接出站台是否可用 - if (ValidateStationForStockerOut(stationForStockerOut)) + var stationForStockerOuts = stationForStockerOutResult.Data.FindAll(t => t.Roadway == location.Roadway); + foreach (var stationForStockerOut in stationForStockerOuts) { - if (stationForStockerOut.SelfAddress != -1) + //校验接出站台是否可用 + if (ValidateStationForStockerOut(stationForStockerOut)) { - //可用,下发任务 - BllResult sendResult = SendTaskToStocker(stocker, stationForStockerOut, task); - if (!BllResult.Success) + if (stationForStockerOut.SelfAddress != -1) { - AddLogToUI("堆垛机" + stocker.ToString() + "下发任务失败:" + sendResult.Msg, 2); + //可用,下发任务 + BllResult sendResult = SendTaskToStocker(stocker, stationForStockerOut, task); + if (!BllResult.Success) + { + AddLogToUI("堆垛机" + stocker.ToString() + "下发任务失败:" + sendResult.Msg, 2); + } + } + else + { + AddLogToUI("堆垛机" + stocker.ToString() + "接出站台没有配置自身地址数据", 2); } - } - else - { - AddLogToUI("堆垛机" + stocker.ToString() + "接出站台没有配置自身地址数据", 2); } } } } } + else + { + AddLogToUI("读取" + stocker + "地址数据失败", 2); + } } } @@ -955,6 +1013,11 @@ namespace HHWCSHost.View throw new NotImplementedException(); } + /// <summary> + /// 添加界面日志,1绿色,2红色 + /// </summary> + /// <param name="log"></param> + /// <param name="level"></param> private void AddLogToUI(string log, int level) { this.Dispatcher.Invoke(new Action(() => @@ -1041,6 +1104,51 @@ namespace HHWCSHost.View } /// <summary> + /// 写入WCS站台区地址 + /// </summary> + /// <param name="addresses"></param> + /// <param name="flag"></param> + /// <param name="type"></param> + /// <param name="loadstatus"></param> + /// <param name="stationno"></param> + /// <param name="taskno"></param> + /// <param name="barcode"></param> + /// <param name="backup"></param> + /// <returns></returns> + private BllResult WriteWCSStationDataAddress(List<DeviceAddressEntity> addresses, string flag, string type, string plcno, string loadstatus, string stationno, string taskno, string barcode, string toaddress, string backup) + { + List<DeviceAddressEntity> temp = new List<DeviceAddressEntity>(); + var wcsflag = addresses.Find(t => t.DevicePropCode == "WCSFlag"); + wcsflag.value = flag; + var wcstype = addresses.Find(t => t.DevicePropCode == "WCSType"); + wcstype.value = type; + var wcsplcno = addresses.Find(t => t.DevicePropCode == "WCSPLCNo"); + wcsplcno.value = plcno; + var wcsloadstatus = addresses.Find(t => t.DevicePropCode == "LoadStatus"); + wcsloadstatus.value = loadstatus; + var wcsstationno = addresses.Find(t => t.DevicePropCode == "WCSStationNo"); + wcsstationno.value = stationno; + var wcstaskno = addresses.Find(t => t.DevicePropCode == "WCSTaskNo"); + wcstaskno.value = taskno; + var wcsbarcode = addresses.Find(t => t.DevicePropCode == "WCSBarcode"); + wcsbarcode.value = barcode; + var wcstoaddress = addresses.Find(t => t.DevicePropCode == "WCSToAddress"); + wcstoaddress.value = toaddress; + var wcsbackup = addresses.Find(t => t.DevicePropCode == "WCSBackUp"); + wcsbackup.value = backup; + temp.Add(wcsflag); + temp.Add(wcstype); + temp.Add(wcsplcno); + temp.Add(wcsloadstatus); + temp.Add(wcsstationno); + temp.Add(wcstaskno); + temp.Add(wcsbarcode); + temp.Add(wcstoaddress); + temp.Add(wcsbackup); + return WriteAddress(temp); + } + + /// <summary> /// 堆垛机出库任务校验 /// 堆垛机接收任务(入库、出库、拣选、转库)条件: ///1. 工作模式=2 联机;