From 92417fc26db8af34d2f88602aa5dc846d0a67665 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期三, 10 九月 2025 09:25:46 +0800
Subject: [PATCH] 1
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs | 125 ++++++++++++++++++++++++++++++++---------
1 files changed, 97 insertions(+), 28 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
index 0319ba1..4bf8120 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/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>
@@ -73,7 +73,7 @@
// 妫�鏌ユ槸鍚﹀凡杩炴帴锛岄伩鍏嶉噸澶嶅垱寤�
if (socket != null && socket.Connected)
{
- ConsoleHelper.WriteErrorLine($"Socket宸插浜庤繛鎺ョ姸鎬�");
+ //ConsoleHelper.WriteErrorLine($"Socket宸插浜庤繛鎺ョ姸鎬�");
return;
}
@@ -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鏍¢獙澶辫触,瑙f瀽{calculatedChecksum}銆佽鍙杮receivedChecksum}");
+ LogFactory.GetLog("Socket鎺ユ敹鏁版嵁").Error(true, $"CheckSum鏍¢獙澶辫触,瑙f瀽{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,6 +1919,14 @@
public string CapitalizeFirstLetter(string s)
{
+ if (s == "Pause")
+ {
+ return "S";
+ }
+ else if (s == "PowerOFF")
+ {
+ return "O";
+ }
if (string.IsNullOrEmpty(s))
{
return "";
--
Gitblit v1.9.3