//TODO:大小板速度不一致 private void init(DiagramViewModel diagramViewModel) { // if (diagramViewModel == null) { return; } _diagramViewModel = diagramViewModel; _connectors = diagramViewModel.Items.OfType <ConnectorViewModel>().ToList(); _roller = diagramViewModel.Items.OfType <RollerDesignerItemViewModel>().ToList(); foreach (var rollerDesignerItemViewModel in _roller) { var runningRoller = new RunningRollerVo { Roller = rollerDesignerItemViewModel }; /*runningRoller.In += runningRollerOnIn; * runningRoller.Out += runningRollerOnOut; * runningRoller.BeginOut += runningRollerOnBeginOut; */ _runningRollers.Add(runningRoller); } // 路由信息 _routes = _connectors .Where(a => a.SinkConnectorInfo is FullyCreatedConnectorInfo) .Where(a => a.SourceConnectorInfo != null) .Where(a => a.SinkConnectorInfo != null) .Select(a => new string[2] { (a.SourceConnectorInfo.DataItem as RollerDesignerItemViewModel)?.Key, (((FullyCreatedConnectorInfo)a.SinkConnectorInfo).DataItem as RollerDesignerItemViewModel)?.Key }).ToList(); // 开始节点 var sinkDataItemIdArray = _connectors .Where(a => a.SinkConnectorInfo is FullyCreatedConnectorInfo) .Select(a => (((FullyCreatedConnectorInfo)a.SinkConnectorInfo).DataItem as RollerDesignerItemViewModel)?.Key) .ToList(); _beginRollers = diagramViewModel.Items .OfType <RollerDesignerItemViewModel>() .Where(a => false == sinkDataItemIdArray.Contains(a.Key)).ToList(); // 结束节点 var sourceDataItemIdArray = _connectors .Where(a => a.SourceConnectorInfo != null) .Select(a => (a.SourceConnectorInfo.DataItem as RollerDesignerItemViewModel)?.Key) .ToList(); _exitRollers = diagramViewModel.Items .OfType <RollerDesignerItemViewModel>() .Where(a => false == sourceDataItemIdArray.Contains(a.Key)).ToList(); // 加载缓存的板件列表 // loadRunningPanels4Roller(diagramViewModel.Key); }
/// <summary> /// /// </summary> /// <param name="curRollerVo"></param> private void running3(RunningRollerVo curRollerVo) { if (curRollerVo == null) { throw new Exception("参数 curRollerVo == null"); } if (curRollerVo.BandProduct == null) { throw new Exception("参数 curRollerVo.BandProduct == null"); } // var currentRollerViewModel = curRollerVo.Roller; var currentBandingProduct = curRollerVo.BandProduct; // 准备离开 if (currentRollerViewModel?.BeginOutTrigger != null) { curRollerVo.StatusDesc = $"等待{curRollerVo.BandProduct.Id}【准备离开】通讯"; var result = currentRollerViewModel.BeginOutTrigger.GetTargetNode(currentBandingProduct.Product, curRollerVo.RollerKey); if (result == null) { throw new Exception("返回值为空"); } curRollerVo.StatusDesc = $"完成{curRollerVo.BandProduct.Id}【准备离开】通讯"; running2_sub(result, currentBandingProduct); } // 进入下一节滚筒判定 if (currentBandingProduct.IsPause) { return; // 暂停 } if (currentBandingProduct.CurrentRollerKey == currentBandingProduct.NextNode) // 暂停 { return; } // 结束(当前的滚筒为结束) if (isExit(currentBandingProduct.CurrentRollerKey)) { if (currentBandingProduct?.NextNode != null) { throw new Exception( $"板件({currentBandingProduct.Product.ToString()}), 已经到达了出口{currentBandingProduct.CurrentRollerKey},但是下节滚筒为{currentBandingProduct.NextNode}"); } // 离开 if (currentRollerViewModel?.OutTrigger != null) { curRollerVo.StatusDesc = $"等待{curRollerVo.BandProduct.Id}【离开】通讯"; var result = currentRollerViewModel.OutTrigger.GetTargetNode(currentBandingProduct.Product, curRollerVo.RollerKey); if (result == null) { throw new Exception($"{curRollerVo.BandProduct.Id}【离开】通讯返回结果为空"); } curRollerVo.StatusDesc = $"完成{curRollerVo.BandProduct.Id}【离开】通讯"; } // 离开动作 curRollerVo.BandProduct = null; lock (_lockRunningProducts) { if (_runningProducts.Contains(currentBandingProduct) == false) { throw new Exception($"{currentBandingProduct.ToString()} 剔除失败"); } _runningProducts.Remove(currentBandingProduct); } return; } if (currentBandingProduct.NextNode == null) // 再次验证 { throw new Exception($"板件({currentBandingProduct.Product.ToString()})," + $"当前滚筒({currentBandingProduct.CurrentRollerKey}),下节滚筒为空!"); } // 下节滚筒 var nextRolloerVo = _runningRollers.FirstOrDefault(a => a.RollerKey == currentBandingProduct.NextNode); if (nextRolloerVo == null) { throw new Exception($"{curRollerVo.RollerKey} 对应滚筒数据为空!"); } if (nextRolloerVo.HasProduct) // 下一节滚筒有板 { return; } var nextRollerViewModel = nextRolloerVo.Roller; if (currentBandingProduct.IsPause) { return; } lock (nextRollerViewModel) { if (nextRolloerVo.HasProduct) // 下一节滚筒有板 { return; } // 触发“离开”监听 if (currentRollerViewModel?.OutTrigger != null) { curRollerVo.StatusDesc = $"等待{curRollerVo.BandProduct.Id}【离开】通讯"; var result = currentRollerViewModel.OutTrigger.GetTargetNode(currentBandingProduct.Product, curRollerVo.RollerKey); if (result == null) { throw new Exception($"{curRollerVo.BandProduct.Id}【离开】通讯返回结果为空"); } curRollerVo.StatusDesc = $"完成{curRollerVo.BandProduct.Id}【离开】通讯"; running2_sub(result, currentBandingProduct); } Thread.Sleep(500); // 【注意】增加一个延迟,缓解plc轮询数据过快,实际上板件在顶升下降和板件离开某个滚筒都需要一定的时间 // 流动 curRollerVo.BandProduct = null; // 离开动作 nextRolloerVo.BandProduct = currentBandingProduct; // 进入动作 RunningAccessService.SaveLog(nextRolloerVo.RollerKey, currentBandingProduct.Id, DateTime.Now); // 记录历史 // 开始进入下节滚筒,触发“入板”监听 if (nextRollerViewModel.InTrigger != null) { nextRolloerVo.StatusDesc = $"等待{nextRolloerVo.BandProduct?.Id} 【进入】通讯"; var result = nextRollerViewModel.InTrigger.GetTargetNode(currentBandingProduct.Product, nextRolloerVo.RollerKey); if (result == null) { throw new Exception("返回值为空"); } nextRolloerVo.StatusDesc = $"完成{nextRolloerVo.BandProduct?.Id} 【进入】通讯"; running2_sub(result, currentBandingProduct); } } }