33
schangxiang@126.com
2024-12-08 7285fd041c9ed732ae2039c4cc54f3eb382d9112
SDA/iWareSda/Devices/4-Station/StationModel/StationEntity.cs
@@ -9,7 +9,7 @@
using iWareCommon.Utils;
using iWareCommon.Common.Globle;
using iWareCommon;
using iWareSda.Devices._3_Station.StationModel;
using Newtonsoft.Json;
using iWareSda.Model;
@@ -179,9 +179,38 @@
            }
        }
        /// <summary>
        /// 写PLC bool
        /// </summary>
        /// <param name="dbAddress"></param>
        /// <param name="value"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool WriteBoolPlcData(string dbAddress, bool value, out string msg)
        {
            try
            {
                msg = "";
                MessageModel b2 = null;
                b2 = this.plcService.WriteValuePoint(dbAddress, value, value);
                if (!b2.result)
                {
                    msg = string.Format($"写入PLC地址{dbAddress},值{value}失败");
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                Log4NetHelper.WriteErrorLog(Station_CacheEntity.curLogType, $"地址{dbAddress}失败:" + ex.Message, ex);
                return false;
            }
        }
        /// <summary>
        /// 写入齐套结果
        /// 写入齐套结果、解析结果
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="value">true:表示 齐套。false:不齐套</param>
@@ -196,21 +225,25 @@
                var view_stationObj = this.View.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                int i_result = 0;
                if (value)
                MessageModel b2 = null;
                if (stationCode == StationLocationEnum.BZ01.ToString() || stationCode == StationLocationEnum.BZ30.ToString())
                {
                    i_result = 998;
                }
                else
                {
                    i_result = 999;
                }
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_KittingInfo, i_result, view_stationObj.W_KittingInfo);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_DataFinish);
                    return false;
                    int i_result = 0;
                    if (value)
                    {
                        i_result = 998;
                    }
                    else
                    {
                        i_result = 999;
                    }
                    b2 = this.plcService.WriteValuePoint(stationObj.W_KittingInfo, i_result, view_stationObj.W_KittingInfo);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                          stationObj.W_DataFinish);
                        return false;
                    }
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_DataFinish, true, view_stationObj.W_DataFinish);
@@ -262,7 +295,15 @@
            }
        }
        public bool OutboundFinishConfirm(string stationCode, bool value, out string msg)
        /// <summary>
        ///
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="value"></param>
        /// <param name="msg"></param>
        /// <param name="isClearData">是否需要清理数据</param>
        /// <returns></returns>
        public bool OutboundFinishConfirm(string stationCode, bool value, out string msg, bool isClearData)
        {
            try
            {
@@ -278,28 +319,32 @@
                    return false;
                }
                if (value && isClearData)
                {
                    b2 = this.plcService.WriteValuePoint(stationObj.W_ReqOut, false, view_stationObj.W_ReqOut);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station W_ReqOut 地址{0} 写  " + false + "失败,返回结果:" + b2.resMsg,
                            stationObj.W_ReqOut);
                        return false;
                    }
                    b2 = this.plcService.WriteValuePoint(stationObj.W_Destination_Out, 0, view_stationObj.W_Destination_Out);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station W_Destination_Out 地址{0} 写  " + 0 + "失败,返回结果:" + b2.resMsg,
                            stationObj.W_Destination_Out);
                        return false;
                    }
                    b2 = this.plcService.WriteValuePoint(stationObj.W_Outbound_TaskID, 0, view_stationObj.W_Outbound_TaskID);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station W_Outbound_TaskID 地址{0} 写  " + 0 + "失败,返回结果:" + b2.resMsg,
                            stationObj.W_Outbound_TaskID);
                        return false;
                    }
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_ReqOut, false, view_stationObj.W_ReqOut);
                if (!b2.result)
                {
                    msg = string.Format("向Station W_ReqOut 地址{0} 写  " + false + "失败,返回结果:" + b2.resMsg,
                        stationObj.W_ReqOut);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_Destination_Out, 0, view_stationObj.W_Destination_Out);
                if (!b2.result)
                {
                    msg = string.Format("向Station W_Destination_Out 地址{0} 写  " + 0 + "失败,返回结果:" + b2.resMsg,
                        stationObj.W_Destination_Out);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_Outbound_TaskID, 0, view_stationObj.W_Outbound_TaskID);
                if (!b2.result)
                {
                    msg = string.Format("向Station W_Outbound_TaskID 地址{0} 写  " + 0 + "失败,返回结果:" + b2.resMsg,
                        stationObj.W_Outbound_TaskID);
                    return false;
                }
                return true;
@@ -434,7 +479,7 @@
        /// <param name=""></param>
        /// <param name=""></param>
        /// <returns></returns>
        public bool WritePalletizingTaskInfo(string stationCode, int taskID, bool isLast, short length, short width, short height, short rotate, short toplace, short placeX, short placeY, out string msg)
        public bool WritePalletizingTaskInfo(string stationCode, int taskID, short length, short width, short height, short rotate, short toplace, short placeX, short placeY, short placeZ, short lastnum, out string msg)
        {
            try
            {
@@ -448,14 +493,6 @@
                {
                    msg = string.Format("向Station地址{0} 写 码垛任务号 " + taskID + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Inbound_TaskID);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_EndMark, isLast, view_stationObj.W_EndMark);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 是否末板 " + isLast + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Destination_In);
                    return false;
                }
@@ -508,6 +545,113 @@
                     stationObj.W_Height);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_PalletizingPlaceZ, placeZ, view_stationObj.W_PalletizingPlaceZ);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 Z坐标 " + placeZ + "失败,返回结果:" + b2.resMsg,
                     stationObj.W_Height);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_PalletizingBucketType, lastnum, view_stationObj.W_PalletizingBucketType);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 首末板 " + lastnum + "失败,返回结果:" + b2.resMsg,
                     stationObj.W_Height);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_DataFinish, true, view_stationObj.W_DataFinish);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 读码解析完成 " + true + "失败,返回结果:" + b2.resMsg,
                       stationObj.W_DataFinish);
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var logcontext = string.Format("WriteInStoreTaskInfo出现异常:" + JsonConvert.SerializeObject(ex),
                        "");
                Log4NetHelper.WriteErrorLog(Station_CacheEntity.curLogType, logcontext, ex);
                return false;
            }
        }
        /// <summary>
        /// 合包下发任务
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="taskID"></param>
        /// <param name="length"></param>
        /// <param name="width"></param>
        /// <param name="cartonhigh"></param>
        /// <param name="cartonwidth"></param>
        /// <param name="placex"></param>
        /// <param name="placey"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool WriteSurroundTaskInfo(string stationCode, short taskID, short length, short width, short cartonhigh, short cartonwidth, short placex, short placey, out string msg)
        {
            try
            {
                msg = "";
                var stationObj = this.DBBlockForWrite.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                var view_stationObj = this.View.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_SurroundTaskNo, taskID, view_stationObj.W_SurroundTaskNo);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 合包任务号 " + taskID + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Inbound_TaskID);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_PackageLength, length, view_stationObj.W_PackageLength);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 合包长 " + length + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Destination_In);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_PackageWidth, width, view_stationObj.W_PackageWidth);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 合包宽 " + width + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Destination_In);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_CartonHeight, cartonhigh, view_stationObj.W_CartonHeight);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 纸箱长 " + cartonhigh + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Length);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_CartonWidth, cartonwidth, view_stationObj.W_CartonWidth);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 纸箱宽 " + width + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Width);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_X_Offset, placex, view_stationObj.W_X_Offset);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 放料x " + placex + "失败,返回结果:" + b2.resMsg,
                     stationObj.W_Height);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_Y_Offset, placey, view_stationObj.W_Y_Offset);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 放料y " + placey + "失败,返回结果:" + b2.resMsg,
                     stationObj.W_Height);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_DataFinish, true, view_stationObj.W_DataFinish);
                if (!b2.result)
@@ -530,6 +674,7 @@
            }
        }
        /// <summary>
        /// 写入站点任务完成确认
        /// </summary>
@@ -548,7 +693,41 @@
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_PalletizingTaskFinish, value, view_stationObj.W_PalletizingTaskFinish);
                if (!b2.result)
                {
                    msg = string.Format("向Station"+stationCode+" 写入任务完成确认 地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                    msg = string.Format("向Station" + stationCode + " 写入任务完成确认 地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                        stationObj.W_OutboundFinishConfirm);
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var logcontext = string.Format("向Statio 出库任务完成确认 出现异常:" + JsonConvert.SerializeObject(ex),
                        "");
                Log4NetHelper.WriteErrorLog(Station_CacheEntity.curLogType, logcontext, ex);
                return false;
            }
        }
        /// <summary>
        /// 写入站点任务完成确认
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="value"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool WriteStation_ACK(string stationCode, bool value, out string msg)
        {
            try
            {
                msg = "";
                var stationObj = this.DBBlockForWrite.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                var view_stationObj = this.View.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_DataFinish, value, view_stationObj.W_DataFinish);
                if (!b2.result)
                {
                    msg = string.Format("向Station" + stationCode + " 写入任务完成确认 地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                        stationObj.W_OutboundFinishConfirm);
                    return false;
                }
@@ -565,7 +744,14 @@
            }
        }
        public bool WriteOutStoreTaskInfo(string stationCode, string sourcePlaceNo, out string msg, int outbound_TaskID)
        /// <summary>
        /// 写入 补板工位允许进板
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="value"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool WriteStation_AllowIn(string stationCode, bool value, out string msg)
        {
            try
            {
@@ -573,27 +759,11 @@
                var stationObj = this.DBBlockForWrite.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                var view_stationObj = this.View.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_Outbound_TaskID, outbound_TaskID, view_stationObj.W_Outbound_TaskID);
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_AllowIn, value, view_stationObj.W_AllowIn);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 出库任务号 " + outbound_TaskID + "失败,返回结果:" + b2.resMsg,
                       stationObj.W_Outbound_TaskID);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_Destination_Out, Convert.ToInt32(sourcePlaceNo), view_stationObj.W_Destination_Out);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 库位号 " + sourcePlaceNo + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_Destination_Out);
                    return false;
                }
                b2 = this.plcService.WriteValuePoint(stationObj.W_ReqOut, true, view_stationObj.W_ReqOut);
                if (!b2.result)
                {
                    msg = string.Format("向Station地址{0} 写 请求出库 " + true + "失败,返回结果:" + b2.resMsg,
                      stationObj.W_ReqOut);
                    msg = string.Format("向Station" + stationCode + " 写入 补板工位允许进板 地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                        stationObj.W_OutboundFinishConfirm);
                    return false;
                }
@@ -602,6 +772,131 @@
            catch (Exception ex)
            {
                msg = ex.Message;
                var logcontext = string.Format("向Statio 补板工位允许进板 出现异常:" + JsonConvert.SerializeObject(ex),
                        "");
                Log4NetHelper.WriteErrorLog(Station_CacheEntity.curLogType, logcontext, ex);
                return false;
            }
        }
        /// <summary>
        /// 写入 人工放行
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="value"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool WriteStation_PersonAllow(string stationCode, bool value, out string msg)
        {
            try
            {
                msg = "";
                //var stationObj = this.DBBlockForWrite.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                //var view_stationObj = this.View.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                //MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_PersonAllow, value, view_stationObj.W_PersonAllow);
                var stationObj = this.DBBlockForRead.R_StationForReadCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                var view_stationObj = this.View.R_StationForReadCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.R_ReqParseData, value, view_stationObj.R_ReqParseData);
                if (!b2.result)
                {
                    msg = string.Format("向Station" + stationCode + " 写入 人工放行 地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                        stationObj.R_ReqParseData);
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var logcontext = string.Format("向Statio 人工放行 出现异常:" + JsonConvert.SerializeObject(ex),
                        "");
                Log4NetHelper.WriteErrorLog(Station_CacheEntity.curLogType, logcontext, ex);
                return false;
            }
        }
        public bool WriteSurround_FinishACK(string stationCode, bool value, out string msg)
        {
            try
            {
                msg = "";
                var stationObj = this.DBBlockForWrite.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                var view_stationObj = this.View.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_SurroundTaskFinish, value, view_stationObj.W_SurroundTaskFinish);
                if (!b2.result)
                {
                    msg = string.Format("向Station" + stationCode + " 写入任务完成确认 地址{0} 写  " + value + "失败,返回结果:" + b2.resMsg,
                        stationObj.W_OutboundFinishConfirm);
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var logcontext = string.Format("向Statio 出库任务完成确认 出现异常:" + JsonConvert.SerializeObject(ex),
                        "");
                Log4NetHelper.WriteErrorLog(Station_CacheEntity.curLogType, logcontext, ex);
                return false;
            }
        }
        public bool WriteOutStoreTaskInfo(bool isResetData, string stationCode, string sourcePlaceNo, out string msg, int outbound_TaskID)
        {
            try
            {
                msg = "";
                var stationObj = this.DBBlockForWrite.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                var view_stationObj = this.View.W_StationForWriteCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
                if (isResetData == false)
                {
                    MessageModel b2 = this.plcService.WriteValuePoint(stationObj.W_Outbound_TaskID, outbound_TaskID, view_stationObj.W_Outbound_TaskID);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station地址{0} 写 出库任务号 " + outbound_TaskID + "失败,返回结果:" + b2.resMsg,
                           stationObj.W_Outbound_TaskID);
                        return false;
                    }
                    b2 = this.plcService.WriteValuePoint(stationObj.W_Destination_Out, Convert.ToInt32(sourcePlaceNo), view_stationObj.W_Destination_Out);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station地址{0} 写 库位号 " + sourcePlaceNo + "失败,返回结果:" + b2.resMsg,
                          stationObj.W_Destination_Out);
                        return false;
                    }
                    b2 = this.plcService.WriteValuePoint(stationObj.W_ReqOut, true, view_stationObj.W_ReqOut);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station地址{0} 写 请求出库 " + true + "失败,返回结果:" + b2.resMsg,
                          stationObj.W_ReqOut);
                        return false;
                    }
                    return true;
                }
                else
                {
                    MessageModel b2 = null;
                    b2 = this.plcService.WriteValuePoint(stationObj.W_ReqOut, false, view_stationObj.W_ReqOut);
                    if (!b2.result)
                    {
                        msg = string.Format("向Station地址{0} 写 请求出库 " + false + "失败,返回结果:" + b2.resMsg,
                          stationObj.W_ReqOut);
                        return false;
                    }
                    return true;
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                var logcontext = string.Format("WriteOutStoreTaskInfo 出现异常:" + JsonConvert.SerializeObject(ex),
                        "");
                Log4NetHelper.WriteErrorLog(Station_CacheEntity.curLogType, logcontext, ex);