1
huangxiaoqiang
2025-07-02 9b139ce92aa09f466c01111dd66af9347a34d865
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs
@@ -48,11 +48,11 @@
        string url = AppSettings.Configuration["AGVIP"];
        private readonly IDt_TaskService _taskService;
        private readonly IDt_HostLogRepository _hostLogRepository;
        private bool _IsOnline=false;
        private bool _IsOnline = false;
        public DateTime Time { get; set; } = DateTime.Now;
        public SocketClientService(IDt_TaskService TaskService, IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger,IDt_HostLogRepository hostLogRepository)
        public SocketClientService(IDt_TaskService TaskService, IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger, IDt_HostLogRepository hostLogRepository)
        {
            BaseDal = TaskRepository;
            _stationManagerRepository = stationManagerRepository;
@@ -62,7 +62,7 @@
        }
        /// <summary>
        /// TCPSocket连接
        /// Socket连接
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="Port"></param>
@@ -106,6 +106,7 @@
            {
                _IsOnline = false;
                ConsoleHelper.WriteErrorLine($"Socket连接失败{ex.Message}");
                LogFactory.GetLog("Socket连接异常").Error(true, $"Socket连接失败{ex.Message}{ex.StackTrace}");
                HandleDisconnection();
            }
        }
@@ -169,7 +170,7 @@
                        else
                        {
                            CheckSum("3");
                            LogFactory.GetLog("Socket接收数据").Error(true, $"CheckSum校验失败,解析{calculatedChecksum}、读取{receivedChecksum}");
                            LogFactory.GetLog("Socket接收数据").Error(true, $"CheckSum校验失败,解析{calculatedChecksum}、读取{receivedChecksum}数据{JsonConvert.SerializeObject(GetParse(str))}");
                        }
                    }
                    else
@@ -361,7 +362,7 @@
        public const string JobOrderIDPDA = "PDA0000000000000";
        public const string JobOrderIDF   = "FIRE000000000000";
        public const string JobOrderIDF = "FIRE000000000000";
        /// <summary>
        /// ä¼˜å…ˆçº§  é¢„ç•™
@@ -454,6 +455,10 @@
            {
                LogFactory.GetLog("DeviceRequestInbound").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
        /// <summary>
@@ -471,6 +476,10 @@
            catch (Exception ex)
            {
                LogFactory.GetLog("RequestCommunication").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -490,7 +499,10 @@
            {
                LogFactory.GetLog("JobReady").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
        /// <summary>
@@ -508,6 +520,10 @@
            catch (Exception ex)
            {
                LogFactory.GetLog("DeviceStateReport").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -527,6 +543,10 @@
            catch (Exception ex)
            {
                LogFactory.GetLog("DeviceAutoStatusReport").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -548,6 +568,10 @@
            catch (Exception ex)
            {
                LogFactory.GetLog("JobStartOrEnd").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -572,6 +596,10 @@
            {
                LogFactory.GetLog("PalletActionReport工序907").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -591,8 +619,8 @@
                Dt_HostLog hostLog = new Dt_HostLog()
                {
                    CommandID = 901,
                    Count=0,
                    Messgae=str,
                    Count = 0,
                    Messgae = str,
                };
                _hostLogRepository.AddData(hostLog);
                clientSend(MakeStringToByteMsg(str));
@@ -600,6 +628,10 @@
            catch (Exception ex)
            {
                LogFactory.GetLog("PalletActionReport工序901").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -615,6 +647,10 @@
            {
                LogFactory.GetLog("PalletActionReportPDA工序901").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -628,6 +664,10 @@
            catch (Exception ex)
            {
                LogFactory.GetLog("PalletActionReportPDA工序901").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -683,6 +723,10 @@
            {
                LogFactory.GetLog("RecreateGetLocation").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -701,6 +745,10 @@
            {
                LogFactory.GetLog("CheckSum").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
        /// /// <summary>
@@ -714,11 +762,16 @@
            try
            {
                string str = SendNotReply + "985" + BaseDal.GetSeqNo().Result.ToString("D5") + Trouble + Level + Location;
                clientSend(MakeStringToByteMsg(str));
            }
            catch (Exception ex)
            {
                LogFactory.GetLog("ErrorReport").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -767,6 +820,10 @@
            {
                LogFactory.GetLog("EmptyOutBound").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
@@ -792,6 +849,10 @@
            {
                LogFactory.GetLog("DeviceStatusReportResponse").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            finally
            {
                BaseDal.Db.Close();
            }
        }
        /// <summary>
@@ -800,7 +861,7 @@
        /// <param name="AgvStatus"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        public void FireAlarmReportResponse(string SeqNo,string IsOK,string Location)
        public void FireAlarmReportResponse(string SeqNo, string IsOK, string Location)
        {
            try
            {
@@ -811,7 +872,7 @@
            {
                LogFactory.GetLog("FireAlarmReportResponse").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
        }
@@ -821,7 +882,7 @@
        /// <param name="AgvStatus"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        public void UpdateLocalTimeResponse(string message,string SeqNo)
        public void UpdateLocalTimeResponse(string message, string SeqNo)
        {
            try
            {
@@ -882,7 +943,7 @@
            {
                ErrorReport("2199", "A", "00");
                LogFactory.GetLog("Host102回复WMS101ReceiveCommandResponse").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            }
        }
        /// <summary>
@@ -922,9 +983,9 @@
                ErrorReport("2199", "A", "00");
                LogFactory.GetLog("Host906回复WMS905AGVJobStartOrEndResponse").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
        }
        /// <summary>
@@ -956,7 +1017,7 @@
                ErrorReport("2199", "A", "00");
                LogFactory.GetLog("Host902回复WMS901DataReportResponse").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
            #endregion
        }
        /// <summary>
@@ -998,7 +1059,7 @@
                StationStatus stationIn = GetStationStatus("B002");
                StationStatus stationOut = GetStationStatus("B001");
                if(stationIn == null || stationOut == null)
                if (stationIn == null || stationOut == null)
                {
                    ErrorReport("2103", "A", "00");
                }
@@ -1078,7 +1139,7 @@
                {
                    //OK
                    case "0":
                        GetLocation(parseMessage,true);
                        GetLocation(parseMessage, true);
                        break;
                    //NG
                    case "1":
@@ -1227,7 +1288,7 @@
                CommandID = Convert.ToInt32(987),
            };
        }
        /// <summary>
        /// HOST获取设备状态  å·¥åº909
        /// </summary>
@@ -1261,20 +1322,20 @@
                ErrorReport("2199", "A", "00");
                LogFactory.GetLog("Host心跳").InfoFormat(true, $"请求参数:{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", "");
            }
        }
        /// <summary>
        /// WMS同步Host时间  å·¥åº301
        /// </summary>
        public void UpdateLocalTime(string Time,string SeqNo)
        public void UpdateLocalTime(string Time, string SeqNo)
        {
            try
            {
                SYSTEMTIME newTime = new SYSTEMTIME
                {
                    Year = Convert.ToUInt16(Time.Substring(0,4)),
                    Year = Convert.ToUInt16(Time.Substring(0, 4)),
                    Month = Convert.ToUInt16(Time.Substring(4, 2)),
                    Day = Convert.ToUInt16(Time.Substring(6, 2)),
                    Hour = Convert.ToUInt16(Time.Substring(8, 2)),
@@ -1495,7 +1556,7 @@
            {
                taskType = (int)TaskStationTypeEnum.StationToStation;
                taskState = (int)TaskOutStatusEnum.OutNew;
                task.SourceAddress = StationParse(parseMessage.body.FromLocation)  ;
                task.SourceAddress = StationParse(parseMessage.body.FromLocation);
                task.TargetAddress = StationParse(parseMessage.body.ToLocation);
                task.CurrentAddress = StationParse(parseMessage.body.FromLocation);
                task.NextAddress = StationParse(parseMessage.body.ToLocation);
@@ -1530,7 +1591,7 @@
        }
        public void GetLocation(ParseMessage parseMessage,bool repeat=false)
        public void GetLocation(ParseMessage parseMessage, bool repeat = false)
        {
            switch (parseMessage.body.JobType)
@@ -1636,7 +1697,7 @@
                    break;
                default:
                    break;
            }
            }
        }
        /// <summary>
        /// æ·»åŠ AGV任务
@@ -1698,7 +1759,7 @@
        }
        public ParseMessage GetParse(string x)
        {
            if (string.IsNullOrEmpty(x))
            {
                throw new ArgumentNullException(nameof(x), "Input string cannot be null or empty");
@@ -1777,7 +1838,7 @@
            return result;
        }
        public AGVStatusRespone GetAGVStatus()
        {
            string urlnew = url + "/ilns/AGV/getState";
@@ -1846,7 +1907,7 @@
        public string StationParse(string station)
        {
            var Station = SqlSugarHelper.DbWMS.Queryable<Dt_StationManager>().Where(x => x.HostName == station.Substring(4, 2)).First();
            if(Station != null)
            if (Station != null)
            {
                return Station.stationName;
            }
@@ -1858,11 +1919,11 @@
        public string CapitalizeFirstLetter(string s)
        {
            if(s == "Pause")
            if (s == "Pause")
            {
                return "S";
            }
            else if(s== "PowerOFF")
            else if (s == "PowerOFF")
            {
                return "O";
            }