| | |
| | | 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; |
| | | private static int _currentNumber = 0; |
| | | private static readonly object _lock = new object(); |
| | | |
| | | |
| | | 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; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// TCPSocketè¿æ¥ |
| | | /// Socketè¿æ¥ |
| | | /// </summary> |
| | | /// <param name="IP"></param> |
| | | /// <param name="Port"></param> |
| | |
| | | { |
| | | _IsOnline = false; |
| | | ConsoleHelper.WriteErrorLine($"Socketè¿æ¥å¤±è´¥{ex.Message}"); |
| | | LogFactory.GetLog("Socketè¿æ¥å¼å¸¸").Error(true, $"Socketè¿æ¥å¤±è´¥{ex.Message}{ex.StackTrace}"); |
| | | HandleDisconnection(); |
| | | } |
| | | } |
| | |
| | | else |
| | | { |
| | | CheckSum("3"); |
| | | LogFactory.GetLog("Socketæ¥æ¶æ°æ®").Error(true, $"CheckSumæ ¡éªå¤±è´¥,è§£æ{calculatedChecksum}ã读å{receivedChecksum}"); |
| | | LogFactory.GetLog("Socketæ¥æ¶æ°æ®").Error(true, $"CheckSumæ ¡éªå¤±è´¥,è§£æ{calculatedChecksum}ã读å{receivedChecksum}æ°æ®{JsonConvert.SerializeObject(GetParse(str))}"); |
| | | } |
| | | } |
| | | else |
| | |
| | | |
| | | public const string JobOrderIDPDA = "PDA0000000000000"; |
| | | |
| | | public const string JobOrderIDF = "FIRE000000000000"; |
| | | public const string JobOrderIDF = "FIRE000000000000"; |
| | | |
| | | /// <summary> |
| | | /// ä¼å
级 é¢ç |
| | |
| | | #endregion |
| | | |
| | | #region WMSä¸åHOSTæ¹æ³ |
| | | public static string Sequence() |
| | | { |
| | | // 使ç¨éç¡®ä¿çº¿ç¨å®å
¨ |
| | | lock (_lock) |
| | | { |
| | | _currentNumber++; |
| | | |
| | | // 妿è¶
è¿99999ï¼å¯ä»¥éç½®ææåºå¼å¸¸ï¼è¿ééæ©éç½® |
| | | if (_currentNumber > 99999) |
| | | { |
| | | _currentNumber = 1; |
| | | } |
| | | |
| | | return _currentNumber.ToString("D5"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设å¤è¯·æ±å
¥åº å·¥åº101 |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "101" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + OutStationSpare2 + "1" + GetFieldsAsString(inStation); |
| | | string str = SendandReply + "101" + Sequence() + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + OutStationSpare2 + "1" + GetFieldsAsString(inStation); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "925" + BaseDal.GetSeqNo().Result.ToString("D5"); |
| | | string str = SendandReply + "925" + Sequence(); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "915" + BaseDal.GetSeqNo().Result.ToString("D5") + Command; |
| | | string str = SendNotReply + "915" + Sequence() + Command; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("JobReady").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "913" + BaseDal.GetSeqNo().Result.ToString("D5") + Status; |
| | | string str = SendNotReply + "913" + Sequence() + Status; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("DeviceStateReport").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "917" + BaseDal.GetSeqNo().Result.ToString("D5") + Status; |
| | | string str = SendandReply + "917" + Sequence() + Status; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "905" + BaseDal.GetSeqNo().Result.ToString("D5") + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | string str = SendandReply + "905" + Sequence() + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("JobStartOrEnd").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "907" + BaseDal.GetSeqNo().Result.ToString("D5") + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | string str = SendNotReply + "907" + Sequence() + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("PalletActionReportå·¥åº907").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString("D5") + "0" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | string str = SendandReply + "901" + Sequence() + "0" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 901, |
| | | Count=0, |
| | | Messgae=str, |
| | | Count = 0, |
| | | Messgae = str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | |
| | | { |
| | | LogFactory.GetLog("PalletActionReportå·¥åº901").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | public void PalletActionReportPDA(string FormLocation, string ToLocation, string TaskType, string PallteCode) |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString("D5") + "0" + JobOrderIDPDA + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | string str = SendandReply + "901" + Sequence() + "0" + JobOrderIDPDA + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("PalletActionReportPDAå·¥åº901").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | public void PalletActionReportFrie(string FormLocation, string ToLocation, string TaskType, string PallteCode) |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString("D5") + "0" + JobOrderIDF + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | string str = SendandReply + "901" + Sequence() + "0" + JobOrderIDF + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("PalletActionReportPDAå·¥åº901").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | LogFactory.GetLog("DeviceStationStatusReport").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// /// <summary> |
| | |
| | | try |
| | | { |
| | | ErrorReport(Restocking, "A", "00"); |
| | | string str = SendandReply + "105" + BaseDal.GetSeqNo().Result.ToString("D5") + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | string str = SendandReply + "105" + Sequence() + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 105, |
| | |
| | | { |
| | | LogFactory.GetLog("RecreateGetLocation").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "981" + BaseDal.GetSeqNo().Result.ToString("D5") + message; |
| | | string str = SendNotReply + "981" + Sequence() + message; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "985" + BaseDal.GetSeqNo().Result.ToString("D5") + Trouble + Level + Location; |
| | | string str = SendNotReply + "985" + Sequence() + Trouble + Level + Location; |
| | | |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "104" + BaseDal.GetSeqNo().Result.ToString("D5") + Statues; |
| | | string str = SendNotReply + "104" + Sequence() + Statues; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("DeviceReceiveJobResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// /// <summary> |
| | |
| | | try |
| | | { |
| | | ErrorReport(EmptyOutBoundconst, "A", "00"); |
| | | string str = SendandReply + "107" + BaseDal.GetSeqNo().Result.ToString("D5") + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode; |
| | | string str = SendandReply + "107" + Sequence() + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 107, |
| | |
| | | { |
| | | LogFactory.GetLog("EmptyOutBound").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "910" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(AgvStatus) + X + Y; |
| | | string str = SendNotReply + "910" + Sequence() + GetFieldsAsString(AgvStatus) + X + Y; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | var hostlog = SqlSugarHelper.DbWMS.Queryable<Dt_HostLog>().Where(x => x.CommandID == 910).First(); |
| | | if (hostlog != null) |
| | | { |
| | | CommandID = 910, |
| | | Count = 0, |
| | | Messgae = str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | hostlog.ModifyDate=DateTime.Now; |
| | | SqlSugarHelper.DbWMS.Updateable(hostlog).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 910, |
| | | Count = 0, |
| | | Messgae = str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | /// <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 |
| | | { |
| | |
| | | { |
| | | LogFactory.GetLog("FireAlarmReportResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | /// <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 |
| | | { |
| | |
| | | { |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host102åå¤WMS101ReceiveCommandResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host906åå¤WMS905AGVJobStartOrEndResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host902åå¤WMS901DataReportResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | } |
| | | /// <summary> |
| | |
| | | StationStatus stationIn = GetStationStatus("B002"); |
| | | StationStatus stationOut = GetStationStatus("B001"); |
| | | |
| | | if(stationIn == null || stationOut == null) |
| | | if (stationIn == null || stationOut == null) |
| | | { |
| | | ErrorReport("2103", "A", "00"); |
| | | } |
| | |
| | | { |
| | | //OK |
| | | case "0": |
| | | GetLocation(parseMessage,true); |
| | | GetLocation(parseMessage, true); |
| | | break; |
| | | //NG |
| | | case "1": |
| | |
| | | CommandID = Convert.ToInt32(987), |
| | | }; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// HOSTè·å设å¤ç¶æ å·¥åº909 |
| | | /// </summary> |
| | |
| | | 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)), |
| | |
| | | { |
| | | 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); |
| | |
| | | } |
| | | |
| | | |
| | | public void GetLocation(ParseMessage parseMessage,bool repeat=false) |
| | | public void GetLocation(ParseMessage parseMessage, bool repeat = false) |
| | | { |
| | | |
| | | switch (parseMessage.body.JobType) |
| | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ·»å AGVä»»å¡ |
| | |
| | | } |
| | | public ParseMessage GetParse(string x) |
| | | { |
| | | |
| | | |
| | | if (string.IsNullOrEmpty(x)) |
| | | { |
| | | throw new ArgumentNullException(nameof(x), "Input string cannot be null or empty"); |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | public AGVStatusRespone GetAGVStatus() |
| | | { |
| | | string urlnew = url + "/ilns/AGV/getState"; |
| | |
| | | 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; |
| | | } |
| | |
| | | |
| | | public string CapitalizeFirstLetter(string s) |
| | | { |
| | | if(s == "Pause") |
| | | if (s == "Pause") |
| | | { |
| | | return "S"; |
| | | } |
| | | else if(s== "PowerOFF") |
| | | else if (s == "PowerOFF") |
| | | { |
| | | return "O"; |
| | | } |