kazelee
3 天以前 1b6bf29ff7daa1987de65940af52f452cabd6881
core/WCSCore.cs
@@ -22,29 +22,20 @@
namespace HH.WCS.Mobox3.DSZSH.core {
    public class WCSCore {
        public static ReturnResult OperateAgvTaskStatus(AgvTaskState model) {
            var result = new ReturnResult();
            const string preLog = "AGV:任务状态回报:";
            try {
                if (model.state > 0) {
                    // AGV 执行任务的逻辑处理
                    if (!AgvTaskProcessOk(model)) {
                        // 执行不OK,说明没有找到任务
                        result.ResultCode = 1;
                        result.ResultMsg = $"根据Model.No未找到对应的任务,{model.task_no}";
                        LogHelper.Info(result.ResultMsg, "API");
                        return result;
                        return NewReturnResult(1, preLog + $"根据任务号'{model.task_no}'未找到对应的任务!");
                    }
                }
                result.ResultCode = 0;
                result.ResultMsg = "success";
                LogHelper.Info(result.ResultMsg, "API");
                return result;
                return NewReturnResult(0, "success"); // 不返回详细成功日志,避免NDC以msg=success作为成功判定(参考国自)
            }
            catch (Exception ex) {
                result.ResultCode = -1;
                result.ResultMsg = $"发生了异常:{ex.Message}";
                LogHelper.Info(result.ResultMsg, "Error");
                return result;
                return NewReturnResult(-1, $"发生了异常:{ex.Message}\n{ex.StackTrace}");
            }
        }
@@ -147,7 +138,7 @@
                var isInbound = false; // 入库类型的任务(包括移库类任务)
                var inboundTasks = new List<string> {
                    ETask.M满托下线入库.Name(), ETask.K空箱入库.Name(), ETask.M满托下线入库.Name(), ETask.K空托入库.Name(),
                    ETask.M满托下线入库.Name(), ETask.M满箱下线入库.Name(), ETask.K空托入库.Name(), ETask.K空箱入库.Name(),
                    ETask.C抽检合格回库.Name(), ETask.C抽检不合格移库.Name(), ETask.Y移库.Name()
                };
                if (inboundTasks.Contains(task.S_TYPE)) {
@@ -204,7 +195,7 @@
        /// <returns></returns>
        public static ReturnResult SafetyInteraction(SafetyInteractionInfo model) {
            var db = new SqlHelper<object>().GetInstance();
            var info = "";
            const string preLog = "AGV:产线安全交互:";
            try {
                ModbusHelper.Relink();
@@ -214,24 +205,18 @@
                    .Where(l => BZQ.Contains(l.S_AREA_CODE) && l.S_AGV_SITE == model.station_name).First();
                if (loc == null) {
                    info = $"AGV 站点{model.station_name}不是合法的产线接驳位站点";
                    LogHelper.Info(info);
                    return NewReturnResult(1, info);
                    return NewReturnResult(1, preLog + $"AGV 站点{model.station_name}不是合法的产线接驳位站点");
                }
                if (!Settings.LocProdIdMap.TryGetValue(loc.S_CODE, out var prodIndex)) {
                    info = $"AGV 站点{model.station_name}不是合法的产线接驳位站点";
                    LogHelper.Info(info);
                    return NewReturnResult(1, info);
                    return NewReturnResult(1, preLog + $"AGV 站点{model.station_name}不是合法的产线接驳位站点");
                }
                var prodLineInfo = Settings.ProductionLines[prodIndex];
                var prodLineDevice = new ProductionLineDevice(prodLineInfo);
                if (!prodLineDevice.LoadDeviceStateOk()) {
                    info = "与产线设备通讯失败";
                    LogHelper.Info(info);
                    return NewReturnResult(2, info);
                    return NewReturnResult(2, preLog + "与产线设备通讯失败");
                }
                //var tn_task = db.Queryable<TN_Task>().First(a => a.S_CODE == model.task_no);
@@ -248,56 +233,40 @@
                //}
                if (prodLineDevice.SystemState != 1) {
                    info = $"当前产线无法与AGV联动:状态{prodLineDevice.SystemState}";
                    LogHelper.Info(info);
                    return NewReturnResult(3, info);
                    return NewReturnResult(3, preLog + $"当前产线无法与AGV联动:状态{prodLineDevice.SystemState}");
                }
                if (model.apply_code == "5") { // 请求取货
                // 请求取货
                if (model.apply_code == "5") {
                    if (prodLineDevice.FullOffline != 1) {
                        info = $"当前输送线满料下线信号不为1,无法取货";
                        LogHelper.Info(info);
                        return NewReturnResult(4, info);
                        return NewReturnResult(4, preLog + $"当前输送线满料下线信号不为1,无法取货");
                    }
                    
                    if (!prodLineDevice.SetAgvPicking(1)) {
                        info = $"向输送线写入允许取货信号失败";
                        LogHelper.Info(info);
                        return NewReturnResult(5, info);
                        return NewReturnResult(5, preLog + $"向输送线写入允许取货信号失败");
                    }
                    
                    info = $"向输送线写入允许取货信号成功";
                    LogHelper.Info(info);
                    return NewReturnResult(0, info);
                    return NewReturnResult(0, preLog + $"向输送线写入允许取货信号成功");
                }
                else if (model.apply_code == "1") { // 请求卸货
                // 请求卸货
                else if (model.apply_code == "1") {
                    if (prodLineDevice.AllowAgvPlacePallet != 1) {
                        info = $"当前输送线允许放托盘信号不为1,无法放货";
                        LogHelper.Info(info);
                        return NewReturnResult(6, info);
                        return NewReturnResult(6, preLog + $"当前输送线允许放托盘信号不为1,无法放货");
                    }
                    if (!prodLineDevice.SetAgvPlacingPallet(1)) {
                        info = $"向输送线写入允许放货信号失败";
                        LogHelper.Info(info);
                        return NewReturnResult(7, info);
                        return NewReturnResult(7, preLog + $"向输送线写入允许放货信号失败");
                    }
                    info = $"向输送线写入允许放货信号成功";
                    LogHelper.Info(info);
                    return NewReturnResult(0, info);
                    return NewReturnResult(0, preLog + $"向输送线写入允许放货信号成功");
                }
                else {
                    info = $"当前AGV请求码不为 5取货 或 1卸货";
                    LogHelper.Info(info);
                    return NewReturnResult(8, info);
                    return NewReturnResult(8, preLog + $"当前AGV请求码不为 5取货 或 1卸货");
                }
            }
            catch (Exception ex) {
                info = $"发生了异常:{ex.Message}";
                LogHelper.InfoEx(ex);
                return NewReturnResult(1, info);
                return NewReturnResult(1, preLog + $"发生了异常:{ex.Message}\n{ex.StackTrace}");
            }
        }
@@ -425,7 +394,7 @@
                model.hwzt = "已出库";
                var jsonInfo = JsonConvert.SerializeObject(model);
                var result = httpH.WebPost(Settings.ErpApiUrl + "PickUpReturn", jsonInfo);
                var result = httpH.WebPost(Settings.ErpApiUrl + Settings.ErpRoute.PickUpReturn, jsonInfo);
                LogHelper.InfoApi($"取货完成反馈ERP接口,结果={result},调用参数:", model);
@@ -464,7 +433,7 @@
        // TCP 非轮询方式 模拟产线下线的尝试
        public static void StartServer() {
            var ListenPort = 6000;
            var ListenPort = Settings.TcpServerPort;
            TcpListener listener = new TcpListener(IPAddress.Any, ListenPort);
            listener.Start();
            Console.WriteLine($"后台服务已启动,监听端口 {ListenPort}...");
@@ -578,8 +547,8 @@
                var cntId = locCntrRel.S_CNTR_CODE;
                var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName);
                LocationHelper.LockStartLoc(ref startLoc); // 起点出库锁
                LocationHelper.LockEndLoc(ref endLoc); // 终点入库锁
                WCSHelper.LockStartLoc(ref startLoc); // 起点出库锁
                WCSHelper.LockEndLoc(ref endLoc); // 终点入库锁
                using (var tran = db.Ado.UseTran()) {
                    if (locCntrRelOld != null) {
@@ -638,11 +607,15 @@
                }
            }
            catch (Exception ex) {
                LogHelper.InfoEx(ex);
                return new Result<bool>(false, ex.Message);
                return NewResult(false, ex.Message);
            }
        }
        private static Result<bool> NewResult(bool res, string msg, bool log = true) {
            if (log) { LogHelper.Info(msg); }
            return new Result<bool>(res, msg);
        }
    }
    public class ProductCompletedMessage {