Esempio n. 1
0
        /// <summary>
        /// 实现到达清除
        /// </summary>
        /// <param name="plc"></param>
        /// <param name="station"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private BllResult ExcuteArriveClear(IPLC plc, Equipment station)
        {
            var result = SendAckToPlcForInOrOut(station, plc, StationMessageFlag.默认, StationLoadStatus.默认, "0", "0");

            if (result.Success)
            {
                return(BllResultFactory.Sucess($"站台{station.Name}响应位置到达完成后,清除WCS地址区成功"));
            }
            else
            {
                return(BllResultFactory.Error($"站台{station.Name}响应位置到达完成后,清除WCS地址区失败"));
            }
        }
Esempio n. 2
0
        public override async Task <BllResult <List <T> > > GetCommonModeByPageConditionAsync <T>(IDbConnection connection, IDbTransaction tran, int pageNumber, int pageSize, string condition, string orderBy)
        {
            try
            {
                var a = await connection.GetListPagedAsync <T>(pageNumber, pageSize, condition, orderBy);

                return(BllResultFactory <List <T> > .Sucess(a.ToList(), "成功"));
            }
            catch (Exception ex)
            {
                return(BllResultFactory <List <T> > .Error($"未查询到数据:{ex.Message}"));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 通用条件验证
 /// 验证堆垛机联机且无故障
 /// </summary>
 /// <param name="srm"></param>
 /// <returns></returns>
 public BllResult Validate(Equipment srm)
 {
     //联机,无故障
     if (srm.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.OperationModel.ToString()).Value == SRMOperationModel.联机.GetIndexString() &&
         srm.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.TotalError.ToString()).Value == "False")
     {
         return(BllResultFactory.Sucess());
     }
     else
     {
         return(BllResultFactory.Error());
     }
 }
Esempio n. 4
0
        public override async Task <BllResult> DeleteCommonModelByIdsAsync <T>(List <int> list, IDbConnection connection, IDbTransaction tran)
        {
            try
            {
                await connection.DeleteListAsync <T>("where id in @ids", new { ids = list }, tran);

                return(BllResultFactory.Sucess("成功"));
            }
            catch (Exception ex)
            {
                return(BllResultFactory.Error($"删除失败:{ex.Message}"));
            }
        }
Esempio n. 5
0
        public override async Task <BllResult> UpdateCommonModelAsync <T>(T model, IDbConnection connection, IDbTransaction tran)
        {
            try
            {
                await connection.UpdateAsync <T>(model, tran);

                return(BllResultFactory.Sucess("成功"));
            }
            catch (Exception ex)
            {
                return(BllResultFactory.Error("发生异常:" + ex.Message));
            }
        }
Esempio n. 6
0
        public override async Task <BllResult <int?> > InsertCommonModelAsync <T>(T model, IDbConnection connection, IDbTransaction tran)
        {
            try
            {
                var a = await connection.InsertAsync <T>(model, transaction : tran);

                return(BllResultFactory <int?> .Sucess(a, "成功"));
            }
            catch (Exception ex)
            {
                return(BllResultFactory <int?> .Error("发生异常:" + ex.Message));
            }
        }
 /// <summary>
 /// 通用条件验证
 /// </summary>
 /// <param name="stocker"></param>
 /// <returns></returns>
 public BllResult Validate(Equipment stocker)
 {
     //联机,无故障
     if (stocker.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == SRMProps.OperationModel.ToString()).Value == SRMOperationModel.联机.GetIndexString() &&
         stocker.EquipmentProps.Where(t => t.EquipmentTypeTemplate.IsMonitor == true).Count(t => t.Value != t.EquipmentTypeTemplate.MonitorCompareValue) == 0)
     {
         return(BllResultFactory.Sucess());
     }
     else
     {
         return(BllResultFactory.Error());
     }
 }
        /// <summary>
        /// 执行清除请求
        /// </summary>
        /// <param name="station"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public BllResult ExcuteRequestClear(Equipment station, IPLC plc)
        {
            var result = SendAddressReplyToPlc(station, plc, StationMessageFlag.默认, StationLoadStatus.默认, "0", "0", "0", "0", "0", "0", "0", "0");

            if (result.Success)
            {
                return(BllResultFactory.Sucess($"站台{station.Name}响应地址请求完成后,清除WCS地址区成功"));
            }
            else
            {
                return(BllResultFactory.Error($"站台{station.Name}响应地址请求完成后,清除WCS地址区失败"));
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 连接方法,使用此方法之前请先构造S7PLCHelpers
        /// </summary>
        /// <returns></returns>
        public BllResult Connect()
        {
            if (S7PLCHelpers.Count() == 0)
            {
                return(BllResultFactory.Error($"未配置PLC参数"));
            }
            int i = 0;

            foreach (var item in S7PLCHelpers)
            {
                S7Client s7Client = new S7Client();
                switch (Enum.Parse(typeof(PLCType), item.PLCType))
                {
                case PLCType.S7_300:
                    i = s7Client.ConnectTo(item.PLCIP, 0, 1);
                    break;

                case PLCType.S7_400:
                    i = s7Client.ConnectTo(item.PLCIP, item.Rack, item.Slot);
                    break;

                case PLCType.S7_1200:
                    i = s7Client.ConnectTo(item.PLCIP, 0, 1);
                    break;

                case PLCType.S7_1500:
                    i = s7Client.ConnectTo(item.PLCIP, 0, 1);
                    break;

                default:
                    return(BllResultFactory.Error($"无法识别{item.PLCType}"));
                }
                if (i != 0)
                {
                    return(BllResultFactory.Error(s7Client.ErrorText(i)));
                }
                if (!_lockIds.Exists(t => t.Key == item.PLCIP))
                {
                    _lockIds.Add(new LockInt()
                    {
                        Key = item.PLCIP
                    });
                }
                if (!_lockEvent.TryGetValue(item.PLCIP, out AutoResetEvent e))
                {
                    _lockEvent.Add(item.PLCIP, new AutoResetEvent(false));
                }
                item.S7Client = s7Client;
            }
            return(BllResultFactory.Sucess());
        }
Esempio n. 10
0
 /// <summary>
 /// 通用条件验证   设备准备OK  无错误  控制模式为wcs
 /// </summary>
 /// <param name="car"></param>
 /// <returns></returns>
 public BllResult Validate(Equipment car)
 {
     //穿梭车准备就绪  ready
     if (car.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "ready").Value == CarReadyStatus.Ready.GetIndexString() &&
         car.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "carError").Value == "0" &&
         car.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == "controlMode").Value == CarControlMode.自动.GetIndexString())
     {
         return(BllResultFactory.Sucess());
     }
     else
     {
         return(BllResultFactory.Error());
     }
 }
Esempio n. 11
0
 public override BllResult <int> ExcuteCommonSqlForInsertOrUpdate(string sql)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             return(BllResultFactory <int> .Sucess(connection.Execute(sql), "成功"));
         }
         catch (Exception ex)
         {
             return(BllResultFactory <int> .Error("出现异常:" + ex.Message));
         }
     }
 }
Esempio n. 12
0
 public override BllResult <int?> InsertCommonModel <T>(T model)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             return(BllResultFactory <int?> .Sucess(connection.Insert <T>(model), "成功"));
         }
         catch (Exception ex)
         {
             return(BllResultFactory <int?> .Error("发生异常:" + ex.Message));
         }
     }
 }
Esempio n. 13
0
 public override async Task <BllResult <int> > ExcuteCommonSqlForInsertOrUpdateAsync(string sql, object param)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             return(BllResultFactory <int> .Sucess(await connection.ExecuteAsync(sql, param), "成功)"));
         }
         catch (Exception ex)
         {
             return(BllResultFactory <int> .Error("出现异常:" + ex.Message));
         }
     }
 }
Esempio n. 14
0
        public BllResult Reads(List <EquipmentProp> equipmentProps)
        {
            if (equipmentProps == null || equipmentProps.Count == 0)
            {
                return(BllResultFactory.Error(null, "无地址传入"));
            }
            if (this == null || this.GetConnectStatus().Success == false)
            {
                return(BllResultFactory.Error(null, "地址读取失败,请检查通讯连接"));
            }

            int[] handles = equipmentProps.Select(t => t.ServerHandle).ToArray();
            return(this.ReadData(handles, equipmentProps));
        }
Esempio n. 15
0
 /// <summary>
 /// 断开连接,安全做法是先停止控制循环,然后调用
 /// </summary>
 /// <returns></returns>
 public BllResult DisConnect()
 {
     if (S7PLCHelpers.Count() == 0)
     {
         return(BllResultFactory.Error($"未配置PLC参数"));
     }
     foreach (var item in S7PLCHelpers)
     {
         item.S7Client?.Disconnect();
     }
     //重置所有锁
     _lockIds.ForEach(t => t.I = 0);
     return(BllResultFactory.Sucess());
 }
Esempio n. 16
0
 public override BllResult UpdateCommonModel <T>(T model)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             connection.Update <T>(model);
             return(BllResultFactory.Sucess("成功"));
         }
         catch (Exception ex)
         {
             return(BllResultFactory.Error("发生异常:" + ex.Message));
         }
     }
 }
        /// <summary>
        /// 更新库位的状态 带仓库维度进行处理
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="transaction"></param>
        /// <param name="locationCode"></param>
        /// <param name="warehouseCode"></param>
        /// <param name="newStatus"></param>
        /// <returns></returns>
        public BllResult UpdateLocationStatus(IDbConnection connection, IDbTransaction transaction, string locationCode, string warehouseCode, LocationLockStatus newStatus)
        {
            string sql    = "update location set isLock = @status where code = @code and warehouseCode=@warehouseCode;";
            int    status = (int)newStatus;
            var    result = AppSession.Dal.ExcuteCommonSqlForInsertOrUpdate(sql, new { status = status, code = locationCode, warehouseCode = warehouseCode }, connection, transaction);

            if (!result.Success)
            {
                return(BllResultFactory.Error("失败"));
            }
            else
            {
                return(BllResultFactory.Sucess("成功"));
            }
        }
Esempio n. 18
0
 public BllResult GetConnectStatus()
 {
     if (S7PLCHelpers.Count() == 0)
     {
         return(BllResultFactory.Error($"未配置PLC参数"));
     }
     foreach (var item in S7PLCHelpers)
     {
         if (item.S7Client?.Connected != true)
         {
             return(BllResultFactory.Error($"存在IP为{item.PLCIP}的PLC未连接"));
         }
     }
     return(BllResultFactory.Sucess());
 }
Esempio n. 19
0
 public override BllResult <List <T> > GetCommonModeByPageCondition <T>(int pageNumber, int pageSize, string condition, string orderBy, object param = null)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             var a = connection.GetListPaged <T>(pageNumber, pageSize, condition, orderBy, param).ToList();
             return(BllResultFactory <List <T> > .Sucess(a, "成功"));
         }
         catch (Exception ex)
         {
             return(BllResultFactory <List <T> > .Error($"未查询到数据:{ex.Message}"));
         }
     }
 }
Esempio n. 20
0
 public override BllResult <int> GetCommonModelCount <T>(string sql, object param)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             int a = connection.RecordCount <T>(sql, param);
             return(BllResultFactory <int> .Sucess(a, ""));
         }
         catch (Exception ex)
         {
             return(BllResultFactory <int> .Error($"未查询到数据:{ex.Message}"));
         }
     }
 }
Esempio n. 21
0
 /// <summary>
 /// 处理设备上料完成
 /// </summary>
 /// <param name="robot"></param>
 /// <param name="allEquipments"></param>
 /// <param name="stepTraceList"></param>
 /// <param name="plc"></param>
 /// <returns></returns>
 public override BllResult ExcuteArrive(Equipment robot, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc)
 {
     try
     {
         var Step_Trace_Id = robot.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == PcRobotStation.Step_Trace_Id.ToString());
         var count         = stepTraceList.Count(t => t.Status == StepTraceStatus.响应桁车放货完成.GetIndexInt() && t.StationId == robot.StationId);
         if (count > 1)
         {
             Logger.Log($"处理设备[{robot.Name}]对应的站台[{robot.StationId}]上料完成的时候,出现数据错误,站台有多个对应的任务", LogLevel.Error);
             return(BllResultFactory.Error());
         }
         var stepTrace = stepTraceList.FirstOrDefault(t => t.Status == StepTraceStatus.响应桁车放货完成.GetIndexInt() && t.StationId == robot.StationId);
         if (stepTrace != null)
         {
             //记录旧数据
             var updateTime = stepTrace.UpdateTime;
             var updateBy   = stepTrace.UpdateBy;
             //更新数据
             stepTrace.Status     = StepTraceStatus.设备开始生产.GetIndexInt();
             stepTrace.UpdateTime = DateTime.Now;
             stepTrace.UpdateBy   = App.User.UserCode;
             var updateResult = AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace);
             if (updateResult.Success)
             {
                 var plcResult = SendStepTraceToPlc(stepTrace.Id.ToString(), stepTrace.WcsProductType.ToString(), "1", true, robot, plc);
                 if (plcResult.Success)
                 {
                     Logger.Log($"写入设备【{robot.Name}】任务[{stepTrace.Id}]的信息成功", LogLevel.Success);
                 }
                 else
                 {
                     stepTrace.Status     = StepTraceStatus.响应桁车放货完成.GetIndexInt();
                     stepTrace.UpdateTime = updateTime;
                     stepTrace.UpdateBy   = updateBy;
                     AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace);
                     Logger.Log($"写入设备【{robot.Name}】任务[{stepTrace.Id}]的信息失败,写入PLC失败:原因:{plcResult.Msg}", LogLevel.Error);
                 }
                 return(plcResult);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Log($"处理设备【{robot.Name}】上料完成时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
         return(BllResultFactory.Error());
     }
     return(BllResultFactory.Sucess());
 }
Esempio n. 22
0
        /// <summary>
        /// 清理WCS交换区
        /// </summary>
        /// <param name="stocker"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public BllResult ClearWCSData(Equipment stocker, IPLC plc)
        {
            //表示堆垛机已经收到WCS发送给他的任务完成信号,此时WCS可以清除自己的交换区地址
            BllResult sendResult = SendTaskToStocker(stocker, plc, SRMForkAction.无, SRMForkTaskFlag.无任务, "0", "0", "0", "0", "0");

            if (sendResult.Success)
            {
                Logger.Log($"任务完成后,清除堆垛机{stocker.Name}交换区地址成功", LogLevel.Info);
                return(BllResultFactory.Sucess());
            }
            else
            {
                Logger.Log($"任务完成后,清除堆垛机{stocker.Name}交换区地址失败", LogLevel.Error);
                return(BllResultFactory.Error());
            }
        }
Esempio n. 23
0
 public BllResult SetUserDisable(List <int?> list, int enable)
 {
     using (IDbConnection connection = AppSession.Dal.GetConnection())
     {
         try
         {
             var a = connection.Execute("update [wcsuser] set disable = @enalbe where id in @ids;", new { enalbe = enable, ids = list });
             return(BllResultFactory.Sucess("成功"));
         }
         catch (Exception ex)
         {
             AppSession.LogService.WriteDBExceptionLog(ex);
             return(BllResultFactory.Error("发生异常"));
         }
     }
 }
Esempio n. 24
0
 public BllResult <List <Role> > GetAllRole()
 {
     try
     {
         using (IDbConnection connection = AppSession.Dal.GetConnection())
         {
             var a = connection.GetList <Role>().ToList();
             return(BllResultFactory <List <Role> > .Sucess(a, "成功"));
         }
     }
     catch (Exception ex)
     {
         AppSession.LogService.WriteDBExceptionLog(ex);
         return(BllResultFactory <List <Role> > .Error(null, "发生异常"));
     }
 }
Esempio n. 25
0
 public BllResult <Role> GetRoleById(int id)
 {
     try
     {
         using (IDbConnection connection = AppSession.Dal.GetConnection())
         {
             var a = connection.Get <Role>(id);
             return(BllResultFactory <Role> .Sucess(a, "成功"));
         }
     }
     catch (Exception ex)
     {
         AppSession.LogService.WriteDBExceptionLog(ex);
         return(BllResultFactory <Role> .Error(null, "发生异常"));
     }
 }
Esempio n. 26
0
 public BllResult <List <Config> > GetAllConfig()
 {
     using (IDbConnection connection = AppSession.Dal.GetConnection())
     {
         try
         {
             var a = connection.GetList <Config>().ToList();
             return(BllResultFactory <List <Config> > .Sucess(a, "成功"));
         }
         catch (Exception ex)
         {
             AppSession.LogService.WriteDBExceptionLog(ex);
             return(BllResultFactory <List <Config> > .Error($"发生异常:{ex.Message}"));
         }
     }
 }
Esempio n. 27
0
 public BllResult <List <User> > GetUserByCondition(string sql)
 {
     using (IDbConnection connection = AppSession.Dal.GetConnection())
     {
         try
         {
             var result = connection.GetList <User>(sql).ToList();
             return(BllResultFactory <List <User> > .Sucess(result, "成功"));
         }
         catch (Exception ex)
         {
             AppSession.LogService.WriteDBExceptionLog(ex);
             return(BllResultFactory <List <User> > .Error(null, "发生异常"));
         }
     }
 }
Esempio n. 28
0
        //public override BllResult ExcuteRequest(List<Equipment> machineTools, List<Equipment> allEquipments, IPLC plc)
        //{
        //    try
        //    {
        //        //找出 桁车 未完成的任务
        //        var stepTraceList = AppSession.Dal.GetCommonModelByCondition<StepTrace>($"where status < {StepTraceStatus.任务完成.GetIndexInt()}");
        //        foreach (var machineTool in machineTools)
        //        {
        //            Excute(machineTool, allEquipments, stepTraceList.Data, plc);
        //        }
        //        return BllResultFactory.Sucess();
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Log($"机床处理过程中出现异常:{ex.Message}", LogLevel.Exception);
        //        return BllResultFactory.Error();
        //    }
        //}
        //private BllResult Excute(Equipment machineTool, List<Equipment> allEquipments, List<StepTrace> stepTraceList, IPLC plc)
        //{
        //    var Request_Load = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineToolToECSProps.Request_Load.ToString());
        //    var Task_OK = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineToolToECSProps.Task_OK.ToString());
        //    var WCS_Allow_Load = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == EcsToMachineToolPorps.WCS_Allow_Load.ToString());
        //    var Request_Product = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineToolToECSProps.Request_Wroking.ToString());
        //    var WCS_Allow_Product = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == EcsToMachineToolPorps.WCS_Wroking.ToString());
        //    var Request_Blank = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineToolToECSProps.Request_Blank.ToString());
        //    //var WCS_Request_Blank = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == EcsToMachineToolPorps.WCS_Request_Blank.ToString());


        //    #region   清除ECS写入的信号

        //    if (Task_OK.Value == "False" && WCS_Allow_Load.Value == "True")
        //    {
        //        WCS_Allow_Load.Value = "False";
        //        BllResult plcResult = plc.Write(WCS_Allow_Load);
        //        if (plcResult.Success)
        //        {
        //            Logger.Log($"清除设备【{machineTool.Name}】允许请求上料信号成功", LogLevel.Success);
        //        }
        //        else
        //        {
        //            Logger.Log($"清除设备【{machineTool.Name}】允许请求上料信号失败,写入PLC失败:{plcResult.Msg}", LogLevel.Success);
        //        }
        //    }

        //    if (Request_Product.Value == "False" && WCS_Allow_Product.Value == "True")
        //    {
        //        WCS_Allow_Product.Value = "False";
        //        BllResult plcResult = plc.Write(WCS_Allow_Product);
        //        if (plcResult.Success)
        //        {
        //            Logger.Log($"清除设备【{machineTool.Name}】允许请求生产信号成功", LogLevel.Success);
        //        }
        //        else
        //        {
        //            Logger.Log($"清除设备【{machineTool.Name}】允许请求上料信号失败,写入PLC失败:{plcResult.Msg}", LogLevel.Success);
        //        }
        //    }

        //    #endregion

        //    #region 处理上料完成确认
        //    try
        //    {
        //        if (Task_OK.Value == "True")
        //        {
        //            //var TYPE = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == EcsToMachineToolPorps.WCS_TYPE.ToString());
        //            var count = stepTraceList.Count(t => t.Status == StepTraceStatus.响应放货完成.GetIndexInt() && t.StationId == machineTool.StationId);
        //            //if (count == 0)
        //            //{
        //            //    Logger.Log($"处理设备[{machineTool.Name}]对应的站台[{machineTool.StationId}]上料完成的时候,出现数据错误,站台没有对应的任务", LogLevel.Error);
        //            //    return BllResultFactory.Error();
        //            //}
        //            if (count > 1)
        //            {
        //                Logger.Log($"处理设备[{machineTool.Name}]对应的站台[{machineTool.StationId}]上料完成的时候,出现数据错误,站台有多个对应的任务", LogLevel.Error);
        //                return BllResultFactory.Error();
        //            }
        //            var stepTrace = stepTraceList.FirstOrDefault(t => t.Status == StepTraceStatus.响应放货完成.GetIndexInt() && t.StationId == machineTool.StationId);
        //            if (stepTrace != null)
        //            {
        //                //记录旧数据
        //                var updateTime = stepTrace.UpdateTime;
        //                var updateBy = stepTrace.UpdateBy;
        //                //更新数据
        //                stepTrace.Status = StepTraceStatus.设备开始生产.GetIndexInt();
        //                stepTrace.UpdateTime = DateTime.Now;
        //                stepTrace.UpdateBy = App.User.UserCode;
        //                var updateResult = AppSession.Dal.UpdateCommonModel<StepTrace>(stepTrace);
        //                if (updateResult.Success)
        //                {
        //                    //TYPE.Value = stepTrace.ProductId.ToString();
        //                    var WCS_Step_Trace_Id = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == EcsToMachineToolPorps.WCS_Step_Trace_Id.ToString());
        //                    WCS_Allow_Load.Value = "True";
        //                    WCS_Step_Trace_Id.Value = stepTrace.Id.ToString();
        //                    var propsToWriter = new List<EquipmentProp> { WCS_Allow_Load, WCS_Step_Trace_Id };
        //                    BllResult plcResult = plc.Writes(propsToWriter);
        //                    if (plcResult.Success)
        //                    {
        //                        Logger.Log($"处理设备【{machineTool.Name}】上料请求,对应的任务{stepTrace.Id}成功", LogLevel.Success);
        //                        return BllResultFactory.Sucess();
        //                    }
        //                    else
        //                    {
        //                        stepTrace.Status = StepTraceStatus.响应放货完成.GetIndexInt();
        //                        stepTrace.UpdateTime = updateTime;
        //                        stepTrace.UpdateBy = updateBy;
        //                        AppSession.Dal.UpdateCommonModel<StepTrace>(stepTrace);
        //                        Logger.Log($"处理设备【{machineTool.Name}】上料请求,对应的任务{stepTrace.Id}失败,写入PLC失败:{plcResult.Msg}", LogLevel.Error);
        //                        return BllResultFactory.Error();
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Log($"处理设备【{machineTool.Name}】上料请求时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
        //        return BllResultFactory.Error();
        //    }
        //    #endregion

        //    #region 给加机下达生产指令
        //    try
        //    {
        //        if (Request_Product.Value == "True" && WCS_Allow_Product.Value == "False")
        //        {
        //           //同一个机床的设备code只有最有一位不一样
        //            var startsCode = machineTool.Code.Substring(0, machineTool.Code.Length - 1);
        //            //获取同一个机床的2个站台
        //            var stationIds = allEquipments.Where(t => t.Code.StartsWith(startsCode)).Select(t => t.StationId).ToList();
        //            var readyCount = stepTraceList.Count(t => t.Status == StepTraceStatus.设备开始生产.GetIndexInt() && stationIds.Contains(t.StationId));
        //            var waitCount = stepTraceList.Count(t => stationIds.Contains(t.NextStationId));
        //            //如果机架里面有2个工件,或是没有下一个要来机加的工件(至少有1个工件,才会请求生产),就生产
        //            if (readyCount >= 2 || waitCount == 0)
        //            {
        //                WCS_Allow_Product.Value = "True";
        //                BllResult plcResult = plc.Write(WCS_Allow_Product);
        //                if (plcResult.Success)
        //                {
        //                    Logger.Log($"处理设备【{machineTool.Name}】 请求生产 成功", LogLevel.Success);
        //                    return BllResultFactory.Sucess();
        //                }
        //                else
        //                {
        //                    Logger.Log($"处理设备【{machineTool.Name}】 请求生产 失败,写入PLC失败:{plcResult.Msg}", LogLevel.Error);
        //                    return BllResultFactory.Error();
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Log($"处理设备【{machineTool.Name}】机加工时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
        //        return BllResultFactory.Error();
        //    }
        //    #endregion

        //    #region 处理下料请求
        //    try
        //    {
        //        if (Request_Blank.Value == "True")
        //        {

        //            //var TYPE = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == EcsToMachineToolPorps.WCS_TYPE.ToString());
        //            //var count = stepTraceList.Count(t => t.Status == StepTraceStatus.设备开始生产.GetIndexInt() && t.StationId == machineTool.StationId);
        //            //if (count == 0)
        //            //{
        //            //    Logger.Log($"处理设备[{machineTool.Name}]对应的站台[{machineTool.StationId}]下料请求的时候,出现数据错误,站台没有对应的任务", LogLevel.Error);
        //            //    return BllResultFactory.Error();
        //            //}
        //            //if (count > 1)
        //            //{
        //            //    Logger.Log($"处理设备[{machineTool.Name}]对应的站台[{machineTool.StationId}]下料请求的时候,出现数据错误,站台有多个对应的任务", LogLevel.Error);
        //            //    return BllResultFactory.Error();
        //            //}
        //            //var stepTrace = stepTraceList.FirstOrDefault(t => t.StationId == machineTool.StationId);
        //            var Step_Trace_Id = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineToolToECSProps.Step_Trace_ID.ToString());
        //            var stepTrace = stepTraceList.FirstOrDefault(t => t.Id == Convert.ToInt32(Step_Trace_Id.Value));
        //            if (stepTrace != null)
        //            {
        //                if (stepTrace.Status == StepTraceStatus.设备开始生产.GetIndexInt())
        //                {
        //                    //修改工序跟踪
        //                    stepTrace.Status = StepTraceStatus.设备请求下料.GetIndexInt();
        //                    stepTrace.UpdateTime = DateTime.Now;
        //                    stepTrace.UpdateBy = App.User.UserCode;
        //                    var updateResult = AppSession.Dal.UpdateCommonModel<StepTrace>(stepTrace);
        //                    if (updateResult.Success)
        //                    {
        //                        var WCS_Step_Trace_Id = machineTool.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == EcsToMachineToolPorps.WCS_Step_Trace_Id.ToString());
        //                        WCS_Step_Trace_Id.Value = "0";
        //                        BllResult plcResult = plc.Write(WCS_Step_Trace_Id);
        //                        if (plcResult.Success)
        //                        {
        //                            Logger.Log($"处理设备【{machineTool.Name}】下料请求对应的任务{stepTrace.Id}成功", LogLevel.Success);
        //                            return BllResultFactory.Sucess();
        //                        }
        //                        else
        //                        {
        //                            stepTrace.Status = StepTraceStatus.设备开始生产.GetIndexInt();
        //                            stepTrace.UpdateTime = DateTime.Now;
        //                            stepTrace.UpdateBy = App.User.UserCode;
        //                            AppSession.Dal.UpdateCommonModel<StepTrace>(stepTrace);
        //                        }
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                Logger.Log($"处理设备【{machineTool.Name}】下料请求失败,找不到未完成的工序任务id[{Step_Trace_Id.Value}]", LogLevel.Error);
        //                //Logger.Log($"处理设备【{machineTool.Name}】下料请求失败,找不到未完成的机加任务", LogLevel.Error);
        //                return BllResultFactory.Error();
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Log($"处理设备【{machineTool.Name}】下料请求时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
        //        return BllResultFactory.Error();
        //    }
        //    #endregion

        //    return BllResultFactory.Sucess();
        //}

        #endregion

        /// <summary>
        /// 执行上料完成
        /// 注意:allEquipments引用所有设备,此为共享应用
        /// </summary>
        /// <param name="machineTool"></param>
        /// <param name="allEquipments"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public override BllResult ExcuteArrive(Equipment machineTool, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc)
        {
            try
            {
                var count = stepTraceList.Count(t => t.Status == StepTraceStatus.响应放货完成.GetIndexInt() && t.StationId == machineTool.StationId);
                if (count > 1)
                {
                    Logger.Log($"处理设备[{machineTool.Name}]对应的站台[{machineTool.StationId}]上料完成的时候,出现数据错误,站台有多个对应的任务", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                var stepTrace = stepTraceList.FirstOrDefault(t => t.Status == StepTraceStatus.响应放货完成.GetIndexInt() && t.StationId == machineTool.StationId);
                if (stepTrace != null)
                {
                    //记录旧数据
                    var updateTime = stepTrace.UpdateTime;
                    var updateBy   = stepTrace.UpdateBy;
                    //更新数据
                    stepTrace.Status     = StepTraceStatus.设备开始生产.GetIndexInt();
                    stepTrace.UpdateTime = DateTime.Now;
                    stepTrace.UpdateBy   = App.User.UserCode;
                    var updateResult = AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace);
                    if (updateResult.Success)
                    {
                        BllResult plcResult = SendStepTraceToPlc(plc, machineTool, true, stepTrace.Id.ToString());
                        if (plcResult.Success)
                        {
                            Logger.Log($"处理设备【{machineTool.Name}】上料完成成功,对应的任务[{stepTrace.Id}]信息写入设备", LogLevel.Success);
                        }
                        else
                        {
                            stepTrace.Status     = StepTraceStatus.响应放货完成.GetIndexInt();
                            stepTrace.UpdateTime = updateTime;
                            stepTrace.UpdateBy   = updateBy;
                            AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace);
                            Logger.Log($"处理设备【{machineTool.Name}】上料完成失败,对应的任务[{stepTrace.Id}]信息没写入设备,写入PLC失败:{plcResult.Msg}", LogLevel.Error);
                        }
                        return(plcResult);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"处理设备【{machineTool.Name}】上料完成时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
                return(BllResultFactory.Error());
            }
            return(BllResultFactory.Sucess());
        }
Esempio n. 29
0
 /// <summary>
 /// 高速堆垛机的下发给PLC的调用函数
 /// 由于只有一个叉,动作类型暂时保留固定写单叉动作。
 /// </summary>
 /// <param name="stocker">堆垛机编码</param>
 /// <param name="plc">对应写入PLC的OPC连接</param>
 /// <param name="taskMode">任务模型</param>
 /// <param name="forkTaskFlag">取货任务的任务类型</param>
 /// <param name="forkRow">取货的行(2,1,3,4)</param>
 /// <param name="forkColumn">取货的列</param>
 /// <param name="forkLayer">取货的层</param>
 /// <param name="forkStation">取货的站台</param>
 /// <param name="forkTaskFlag2">放货的任务类型</param>
 /// <param name="forkRow2">放货的行(2,1,3,4)</param>
 /// <param name="forkColumn2">放货的列</param>
 /// <param name="forkLayer2">放货的层</param>
 /// <param name="forkStation2">放货的站台</param>
 /// <param name="taskNo">任务号</param>
 /// <param name="taskAccount">任务过账 </param>
 /// <returns></returns>
 public BllResult SendTaskToStocker(Equipment stocker, IPLC plc, SuperSRMTaskMode taskMode,
                                    SRMForkTaskFlag forkTaskFlag, string forkRow, string forkColumn, string forkLayer, string forkStation,
                                    SRMForkTaskFlag forkTaskFlag2, string forkRow2, string forkColumn2, string forkLayer2, string forkStation2,
                                    string taskNo, TaskAccount taskAccount)
 {
     try
     {
         List <EquipmentProp> propsToWriter = new List <EquipmentProp>();
         var props  = stocker.EquipmentProps;
         var action = props.Find(t => t.EquipmentTypeTemplateCode == "WCSForkTaskMode");
         action.Value = taskMode.GetIndexString();
         var taskFlag = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1TaskFlag");
         taskFlag.Value = forkTaskFlag.GetIndexString();
         var row = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Row");
         row.Value = forkRow;
         var column = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Column");
         column.Value = forkColumn;
         var layer = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Layer");
         layer.Value = forkLayer;
         var station = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Station");
         station.Value = forkStation;
         var taskFlag2 = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1TaskFlag2");
         taskFlag2.Value = forkTaskFlag2.GetIndexString();
         var row2 = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Row2");
         row2.Value = forkRow2;
         var column2 = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Column2");
         column2.Value = forkColumn2;
         var layer2 = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Layer2");
         layer2.Value = forkLayer2;
         var station2 = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Station2");
         station2.Value = forkStation2;
         var task = props.Find(t => t.EquipmentTypeTemplateCode == "WCSFork1Task");
         task.Value = taskNo;
         var account = props.Find(t => t.EquipmentTypeTemplateCode == "WCSTaskAccount");
         account.Value = taskAccount.GetIndexString();
         propsToWriter.AddRange(new List <EquipmentProp>()
         {
             action, taskFlag, row, column, layer, station, taskFlag2, row2, column2, layer2, station2, task, account
         });
         return(plc.Writes(propsToWriter));
     }
     catch (Exception ex)
     {
         Logger.Log($"PLC写入信息错误:" + ex.Message, LogLevel.Exception);
         return(BllResultFactory.Error($"下发任务出现异常:{ex.Message}"));
     }
 }
Esempio n. 30
0
        protected override BllResult ExcuteRequest(Equipment bevelCcache, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc)
        {
            try
            {
                var RequestTaskId = bevelCcache.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == PipeLineProps.RequestTaskId.ToString());
                var convertResult = int.TryParse(RequestTaskId.Value, out int stepTraceId);
                if (!convertResult)
                {
                    Logger.Log($"处理工位[{bevelCcache.StationId}]设备[{bevelCcache.Name}]地址请求失败,工序任务的id[{RequestTaskId.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                var stepTrace = stepTraceList.FirstOrDefault(t => t.Id == stepTraceId);
                if (stepTrace == null)
                {
                    Logger.Log($"处理工位[{bevelCcache.StationId}]设备[{bevelCcache.Name}]的地址请求失败,找不到未完成的工序任务id[{RequestTaskId.Value}]", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                var bevel = allEquipments.FirstOrDefault(t => t.SelfAddress == bevelCcache.GoAddress.ToString());

                //找到下个设备
                if (bevel == null)
                {
                    Logger.Log($"处理工位位[{bevelCcache.StationCode}]的设备[{bevelCcache.Name}] 地址请求失败,原因:坡口缓存位没有设置对应的下个设备", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                //如果已经有了去下个设备的任务,那么就不能去,需要等待
                if (stepTraceList.Exists(t => t.NextStationId == bevel.StationId))
                {
                    return(BllResultFactory.Error());
                }

                var ArriveMessage = bevel.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.ArriveMessage.ToString());
                var WCSACKMessage = bevel.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.WCSACKMessage.ToString());

                if (ArriveMessage.Value == MachineMessageFlag.PLC自动请求上料.GetIndexString() && WCSACKMessage.Value == MachineMessageFlag.默认.GetIndexString())
                {
                    return(ExcuteRequest(bevelCcache, bevel, stepTrace, plc));
                }
                return(BllResultFactory.Sucess());
            }
            catch (Exception ex)
            {
                Logger.Log($"处理工位[{bevelCcache.StationId}]设备[{bevelCcache.Name}]地址请求时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
                return(BllResultFactory.Error());
            }
        }