/// <summary> /// 下发数据到桁车 /// </summary> /// <param name="truss"></param> /// <param name="plc"></param> /// <param name="taskFlag"></param> /// <param name="productId"></param> /// <param name="position"></param> /// <param name="taskNo"></param> /// <returns></returns> public BllResult SendTaskToTruss(Equipment truss, IPLC plc, TrussTaskFlag taskFlag, string productId, string stationId, string wcsLine, string wcsLayer, string taskNo) { try { List <EquipmentProp> propsToWriter = new List <EquipmentProp>(); var props = truss.EquipmentProps; var WCSProductId = props.Find(t => t.EquipmentTypeTemplateCode == TrussNormalProps.WCSProductId.ToString()); WCSProductId.Value = productId; var WCSStationId = props.Find(t => t.EquipmentTypeTemplateCode == TrussNormalProps.WCSStationId.ToString()); WCSStationId.Value = stationId; var WCSLine = props.Find(t => t.EquipmentTypeTemplateCode == TrussNormalProps.WCSLine.ToString()); WCSLine.Value = wcsLine; var WCSLayer = props.Find(t => t.EquipmentTypeTemplateCode == TrussNormalProps.WCSLayer.ToString()); WCSLayer.Value = wcsLayer; var WCSTaskNo = props.Find(t => t.EquipmentTypeTemplateCode == TrussNormalProps.WCSTaskNo.ToString()); WCSTaskNo.Value = taskNo; var WCSForkAction = props.Find(t => t.EquipmentTypeTemplateCode == TrussNormalProps.WCSForkAction.ToString()); WCSForkAction.Value = TrussForkAction.一号机械手.GetIndexString(); var WCSTaskFlag = props.Find(t => t.EquipmentTypeTemplateCode == TrussNormalProps.WCSTaskFlag.ToString()); WCSTaskFlag.Value = taskFlag.GetIndexString(); propsToWriter.AddRange(new List <EquipmentProp>() { WCSProductId, WCSStationId, WCSLine, WCSLayer, WCSTaskNo, WCSForkAction, WCSTaskFlag }); return(plc.Writes(propsToWriter)); } catch (Exception ex) { return(BllResultFactory.Error($"写入plc失败,下发任务出现异常:{ex.Message}")); } }
/// <summary> /// 重新下发桁车任务 /// 重新下发任务限制: /// 取货:货叉在中心、联机、无货 /// 放货:货叉在中心、联机、有货 /// </summary> /// <param name="srm"></param> /// <param name="plc"></param> /// <param name="row"></param> /// <param name="column"></param> /// <param name="layer"></param> /// <param name="forkStation">对应桁车的出入口,wcs的桁车出入站台;库内取放为0</param> /// <param name="taskForResend"></param> /// <param name="forkTaskFlag"></param> /// <returns></returns> protected BllResult ReSendTask(Equipment truss, IPLC plc, StepTrace stepTrace, TrussTaskFlag taskFlag, string stationId) { var station = truss.StationList.FirstOrDefault(t => t.Id.ToString() == stationId); if (station == null) { Logger.Log($"未查询到ID为{stationId}的站台", LogLevel.Error); return(BllResultFactory.Error()); } int trussStationId = 0; string wcsLine = "0"; string wcsLayer = "0"; using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { if (taskFlag == TrussTaskFlag.机械手取货) { trussStationId = int.Parse(station.TrussTakeStationId.ToString()); } else if (taskFlag == TrussTaskFlag.机械手放货) { trussStationId = int.Parse(station.TrussPutStationId.ToString()); wcsLine = string.IsNullOrEmpty(stepTrace.WCSLine) ? "0" : stepTrace.WCSLine; wcsLayer = string.IsNullOrEmpty(stepTrace.WCSLayer) ? "0" : stepTrace.WCSLayer; } if (trussStationId == 0) { Logger.Log($"站台[{station.Id}][{station.Name}]没有对应的桁架点位数据,请补齐数据", LogLevel.Error); return(BllResultFactory.Error()); } stepTrace.SendAgain = 2; stepTrace.SrmCode = truss.Code; connection.Open(); tran = connection.BeginTransaction(); connection.Update <StepTrace>(stepTrace, tran); connection.Update <Equipment>(truss, tran); BllResult sendResult = SendTaskToTruss(truss, plc, taskFlag, stepTrace.WcsProductType.ToString(), trussStationId.ToString(), wcsLine, wcsLayer, stepTrace.Id.ToString()); if (sendResult.Success) { tran?.Commit(); Logger.Log($"重新下发桁车{truss.Name}任务,任务id:{stepTrace.Id},操作类型:{taskFlag},目的站台:{stationId} {station.Name},桁车点位{trussStationId},成功", LogLevel.Info); return(BllResultFactory.Sucess()); } else { tran?.Rollback(); stepTrace.SendAgain = 1; Logger.Log($"重新下发桁车{truss.Name}任务,任务id:{stepTrace.Id},操作类型:{taskFlag},目的站台:{stationId} {station.Name},桁车点位{trussStationId},失败:{sendResult.Msg};", LogLevel.Error); return(BllResultFactory.Error()); } } catch (Exception ex) { tran?.Rollback(); stepTrace.SendAgain = 1; Logger.Log($"重新下发桁车{truss.Name}任务,任务id:{stepTrace.Id},操作类型:{taskFlag},目的站台:{stationId} {station.Name},桁车点位{trussStationId},失败:{ex.Message},回滚任务{stepTrace.Id}状态。", LogLevel.Exception, ex); return(BllResultFactory.Error()); } } }