| | |
| | | using WIDESEA_Core.BaseRepository; |
| | | using AutoMapper; |
| | | using Mapster; |
| | | using AngleSharp.Dom; |
| | | using Masuit.Tools.Security; |
| | | using WIDESEA_IStorageTaskServices; |
| | | using System.Threading.Tasks; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using WIDESEA_IBusinessesRepository; |
| | | using WIDESEA_Repository; |
| | | using static MailKit.Telemetry; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | using System.Runtime.InteropServices; |
| | | |
| | | namespace WIDESEA_StorageSocketServices |
| | | { |
| | |
| | | const byte ETX = 3; |
| | | private readonly ILogger<SocketClientService> _logger; |
| | | private readonly LogFactory LogFactory = new LogFactory(); |
| | | //private readonly IDt_TaskService _taskService; |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | private readonly IDt_TaskRepository BaseDal; |
| | | Connection connection = AppSettings.Configuration.GetSection("Connection").Get<Connection>(); |
| | | string url = AppSettings.Configuration["AGVIP"]; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IStockInfoRepository _stockInfoRepository; |
| | | private readonly IDt_Task_HtyRepository _task_HtyRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | | private readonly IDt_TaskService _taskService; |
| | | private readonly IDt_HostLogRepository _hostLogRepository; |
| | | 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) |
| | | public SocketClientService(IDt_TaskService TaskService, IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger, IDt_HostLogRepository hostLogRepository) |
| | | { |
| | | //_taskService = taskService; |
| | | BaseDal = TaskRepository; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _logger = logger; |
| | | _taskService = TaskService; |
| | | _hostLogRepository = hostLogRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Socketè¿æ¥ |
| | | /// </summary> |
| | | /// <param name="IP"></param> |
| | | /// <param name="Port"></param> |
| | | public void ConnectServer(string IP, int Port) |
| | | { |
| | | try |
| | |
| | | // æ£æ¥æ¯å¦å·²è¿æ¥ï¼é¿å
éå¤å建 |
| | | if (socket != null && socket.Connected) |
| | | { |
| | | //Console.WriteLine("Socketå·²è¿æ¥ï¼æ ééå¤å建"); |
| | | ConsoleHelper.WriteErrorLine($"Socketå·²å¤äºè¿æ¥ç¶æ"); |
| | | //ConsoleHelper.WriteErrorLine($"Socketå·²å¤äºè¿æ¥ç¶æ"); |
| | | return; |
| | | } |
| | | |
| | | //å建è´è´£éä¿¡çsocket |
| | | socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
| | | socket = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
| | | IPAddress ip = IPAddress.Parse(IP); |
| | | IPEndPoint point = new IPEndPoint(ip, Convert.ToInt32(Port)); |
| | | |
| | |
| | | _logger.LogInformation("Socketè¿æ¥æå"); |
| | | ConsoleHelper.WriteSuccessLine("Socketè¿æ¥æå"); |
| | | |
| | | DeleteHostLog(910); |
| | | |
| | | _IsOnline = true; |
| | | RequestCommunication(); |
| | | DeviceStateReport("I"); |
| | | AGVStatusRespone status = GetAGVStatus(); |
| | | |
| | | DeviceStateReport(GetAGVStatus(status.RuntimeStatus)); |
| | | |
| | | //å¼å¯ä¸ä¸ªæ°ç线ç¨ä¸åçæ¥æ¶æå¡ç«¯åæ¥çä¿¡æ¯ |
| | | Thread th = new Thread(Receive); |
| | | th.IsBackground = true; |
| | | th.Start(); |
| | | ConsoleHelper.WriteErrorLine($"Socketå¯å¨"); |
| | | return; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _IsOnline = false; |
| | | ConsoleHelper.WriteErrorLine($"Socketè¿æ¥å¤±è´¥{ex.Message}"); |
| | | LogFactory.GetLog("Socketè¿æ¥å¼å¸¸").Error(true, $"Socketè¿æ¥å¤±è´¥{ex.Message}{ex.StackTrace}"); |
| | | HandleDisconnection(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public bool Socketonline() |
| | | { |
| | | return _IsOnline; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 线ç¨è¯»åæ°æ® |
| | | /// </summary> |
| | | void Receive() |
| | | { |
| | | Time = DateTime.Now; |
| | | while (true) |
| | | { |
| | | try |
| | |
| | | var str = Encoding.UTF8.GetString(newArray); |
| | | string receivedChecksum = str.Substring(str.Length - 2); |
| | | |
| | | LogFactory.GetLog("æ¥æ¶Socketæ°æ®").Info(true, $"{JsonConvert.SerializeObject(GetParse(str))}{Environment.NewLine}"); |
| | | if (calculatedChecksum == receivedChecksum) |
| | | { |
| | | var x = Encoding.UTF8.GetString(newArray); |
| | |
| | | } |
| | | else |
| | | { |
| | | LogFactory.GetLog("Socketæ¥æ¶æ°æ®").Error(true, "æ ¡éªå¤±è´¥"); |
| | | CheckSum("3"); |
| | | LogFactory.GetLog("Socketæ¥æ¶æ°æ®").Error(true, $"CheckSumæ ¡éªå¤±è´¥,è§£æ{calculatedChecksum}ã读å{receivedChecksum}æ°æ®{JsonConvert.SerializeObject(GetParse(str))}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogFactory.GetLog("Socketæ¥æ¶æ°æ®").Error(true, "æ ææ¥ææ ¼å¼"); |
| | | LogFactory.GetLog("Socketæ¥æ¶æ°æ®").Error(true, $"æ ææ¥ææ ¼å¼:{JsonConvert.SerializeObject(Y)}{Environment.NewLine}"); |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | _IsOnline = false; |
| | | HandleDisconnection(); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// ä½ä¸JobType |
| | | /// </summary> |
| | | /// <param name="cmdId"></param> |
| | | /// <param name="x"></param> |
| | | private void ProcessCommand(string cmdId, string x) |
| | | { |
| | | switch (cmdId) |
| | |
| | | ReceiveCommandResponse(x); |
| | | break; |
| | | case "906": |
| | | AGVJobStartOrEndResponse(x.Substring(21, 1), x.Substring(22, 1)); |
| | | AGVJobStartOrEndResponse(x.Substring(20, 1), x.Substring(21, 1)); |
| | | break; |
| | | case "902": |
| | | DataReportResponse(x.Substring(21, 1)); |
| | | DataReportResponse(x.Substring(20, 1)); |
| | | break; |
| | | case "935": |
| | | DeviceStationStatusInvite(); |
| | | DeviceStationStatusInvite(x.Substring(15, 5)); |
| | | break; |
| | | case "103": |
| | | HOSTOutBoundTask(x); |
| | |
| | | RecreateGetLocation(x); |
| | | break; |
| | | case "108": |
| | | RecreateGetLocation(x.Substring(21, 1)); |
| | | EmptyOutBoundResponse(x.Substring(20, 1)); |
| | | break; |
| | | case "909": |
| | | DeviceStatusReportRequest(); |
| | | break; |
| | | case "987": |
| | | FireAlarm(x.Substring(21, 6), x.Substring(15, 5)); |
| | | break; |
| | | case "301": |
| | | UpdateLocalTime(x.Substring(30), x.Substring(15, 5)); |
| | | break; |
| | | case "918": |
| | | break; |
| | | default: |
| | | CheckSum("1"); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void HandleDisconnection() |
| | | #region |
| | | //private void HandleDisconnection() |
| | | //{ |
| | | // int attempts = 100; |
| | | // do |
| | | // { |
| | | // string message = "è¿æ¥å·²æå¼..." + '\n'; |
| | | // message += "çå¾
5ç§åéæ°è¿æ¥" + '\n'; |
| | | // Console.WriteLine(message); |
| | | |
| | | // // å
³éå½åè¿æ¥ |
| | | // try |
| | | // { |
| | | // socket?.Close(); |
| | | // } |
| | | // catch { } |
| | | |
| | | // // çå¾
5ç§ |
| | | // Thread.Sleep(5000); |
| | | |
| | | // // å°è¯éæ°è¿æ¥ |
| | | // ConnectServer(connection.IP, connection.Port); |
| | | // attempts--; |
| | | // } while (!socket.Connected && attempts > 0); |
| | | //} |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// éè¿ |
| | | /// </summary> |
| | | public void HandleDisconnection() |
| | | { |
| | | int attempts = 5; |
| | | do |
| | | int maxAttempts = 10; // æå¤§å°è¯æ¬¡æ° |
| | | int currentAttempts = 0; |
| | | |
| | | while (currentAttempts < maxAttempts) |
| | | { |
| | | string message = "è¿æ¥å·²æå¼..." + '\n'; |
| | | string message = "ä¸Hostç³»ç»è¿æ¥å·²æå¼..." + '\n'; |
| | | message += "çå¾
5ç§åéæ°è¿æ¥" + '\n'; |
| | | Console.WriteLine(message); |
| | | |
| | |
| | | |
| | | // å°è¯éæ°è¿æ¥ |
| | | ConnectServer(connection.IP, connection.Port); |
| | | attempts--; |
| | | } while (!socket.Connected && attempts > 0); |
| | | currentAttempts++; |
| | | |
| | | // æ£æ¥æ¯å¦å·²è¿æ¥ |
| | | if (socket?.Connected ?? false) |
| | | { |
| | | break; // è¿æ¥æåï¼éåºå¾ªç¯ |
| | | } |
| | | } |
| | | |
| | | if (currentAttempts >= maxAttempts) |
| | | { |
| | | Console.WriteLine("å·²è¾¾å°æå¤§éè¿æ¬¡æ°ï¼åæ¢éè¿ã"); |
| | | // å¯ä»¥å¨è¿éè¿è¡å
¶ä»å¤çï¼ä¾å¦éç¥ç¨æ·æè®°å½æ¥å¿ |
| | | } |
| | | } |
| | | |
| | | //private void CheckTimeout(object state) |
| | | //{ |
| | | // TimeSpan elapsed = DateTime.Now - _lastActivityTime; |
| | | // if (elapsed.TotalSeconds > 180) // 3åéè¶
æ¶ |
| | | // { |
| | | // Console.WriteLine("è¶
æ¶æªæ¶å°æ°æ®ï¼è§¦å909å½ä»¤å¹¶å°è¯éæ°è¿æ¥..."); |
| | | |
| | | // // 触å909å½ä»¤ |
| | | // _workTaskService.DeviceStatusReportRequest(); |
| | | |
| | | // // å°è¯éæ°è¿æ¥ |
| | | // HandleDisconnection(); |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// ä¸å |
| | | /// </summary> |
| | | /// <param name="buffer"></param> |
| | | public void clientSend(byte[] buffer) |
| | | { |
| | | var Y = Encoding.UTF8.GetString(buffer); |
| | | LogFactory.GetLog("Socketåéæ°æ®").Error(true, Y); |
| | | socket.Send(buffer); |
| | | |
| | | |
| | | int newLength = buffer.Length - 2; |
| | | byte[] newArray = new byte[newLength]; |
| | | |
| | | Array.Copy(buffer, 1, newArray, 0, newLength); |
| | | string calculatedChecksum = GetCheckSumone(newArray); |
| | | |
| | | var str = Encoding.UTF8.GetString(newArray); |
| | | string receivedChecksum = str.Substring(str.Length - 2); |
| | | |
| | | var x = Encoding.UTF8.GetString(newArray); |
| | | |
| | | LogFactory.GetLog("Socketåéæ°æ®").Info(true, $"{JsonConvert.SerializeObject(GetParse(x))}{Environment.NewLine}"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// CheckSumè§£æ |
| | | /// </summary> |
| | | /// <param name="x"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public string GetCheckSumone(byte[] x) |
| | | { |
| | | int sum = 0; |
| | |
| | | /// </summary> |
| | | public const string JobOrderID = "0000000000000000"; |
| | | |
| | | public const string JobOrderIDPDA = "PDA0000000000000"; |
| | | |
| | | public const string JobOrderIDF = "FIRE000000000000"; |
| | | |
| | | /// <summary> |
| | | /// ä¼å
级 é¢ç |
| | | /// </summary> |
| | | public const string priority = "1"; |
| | | |
| | | /// <summary> |
| | | /// éå
¥åº |
| | | /// </summary> |
| | | public const string Restocking = "2100"; |
| | | |
| | | |
| | | public const string EmptyOutBoundconst = "2101"; |
| | | |
| | | /// <summary> |
| | | /// æçä¸ªæ° é¢ç |
| | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public const string DeviceID = "0000000001"; |
| | | public const string DeviceID = "0013130010"; |
| | | /// <summary> |
| | | /// åéä¸éè¦åå¤ |
| | | /// </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() + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + "1" + GetFieldsAsString(inStation); |
| | | string str = SendandReply + "101" + Sequence() + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + OutStationSpare2 + "1" + GetFieldsAsString(inStation); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("DeviceRequestInbound").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "925" + BaseDal.GetSeqNo().Result.ToString(); |
| | | string str = SendandReply + "925" + Sequence(); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("RequestCommunication").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "915" + BaseDal.GetSeqNo().Result.ToString() + Command; |
| | | string str = SendNotReply + "915" + Sequence() + Command; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("JobReady").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "913" + BaseDal.GetSeqNo().Result.ToString() + Status; |
| | | string str = SendNotReply + "913" + Sequence() + Status; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("DeviceStateReport").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "917" + BaseDal.GetSeqNo().Result.ToString() + Status; |
| | | string str = SendandReply + "917" + Sequence() + Status; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("DeviceAutoStatusReport").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "905" + BaseDal.GetSeqNo().Result.ToString() + 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) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("JobStartOrEnd").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "907" + BaseDal.GetSeqNo().Result.ToString() + 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) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("PalletActionReportå·¥åº907").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString() + "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, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | 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" + 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" + 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> |
| | |
| | | /// <param name="TaskType">ä»»å¡ç±»å Iå
¥åºãOåºåºãSç«å°å°ç«å°ãRç§»åº</param> |
| | | /// <param name="PallteCode">æçå·</param> |
| | | /// <returns></returns> |
| | | public void DeviceStationStatusReport(HOSTAGVStatus Agvstatus, List<OutStationStatus> outStations, List<InStationStatus> inStation) |
| | | public void DeviceStationStatusReport(HOSTAGVStatus Agvstatus, List<OutStationStatus> outStations, List<InStationStatus> inStation, string sGetSeqNo) |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "936" + BaseDal.GetSeqNo().Result.ToString() + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + GetListStringInStation(inStation); |
| | | var agvstatus = GetFieldsAsString(Agvstatus); |
| | | var outstation = GetListStringOutStation(outStations); |
| | | var instation = GetListStringInStation(inStation); |
| | | string str = SendNotReply + "936" + sGetSeqNo + agvstatus + outstation + OutStationSpare2 + "2" + instation; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("DeviceStationStatusReport").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "105" + BaseDal.GetSeqNo().Result.ToString() + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | ErrorReport(Restocking, "A", "00"); |
| | | string str = SendandReply + "105" + Sequence() + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 105, |
| | | Count = 0, |
| | | Messgae = str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("RecreateGetLocation").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// CheckSumæ ¡éª å·¥åº981 |
| | | /// </summary> |
| | | /// <param name="message"></param> |
| | | public void CheckSum(string message) |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "981" + Sequence() + message; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("CheckSum").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | | /// /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "985" + BaseDal.GetSeqNo().Result.ToString() + Trouble + Level + Location; |
| | | string str = SendNotReply + "985" + Sequence() + Trouble + Level + Location; |
| | | |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("ErrorReport").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "104" + BaseDal.GetSeqNo().Result.ToString() + Statues; |
| | | string str = SendNotReply + "104" + Sequence() + Statues; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("DeviceReceiveJobResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// /// <summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | string str = SendandReply + "107" + BaseDal.GetSeqNo().Result.ToString() + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode; |
| | | ErrorReport(EmptyOutBoundconst, "A", "00"); |
| | | string str = SendandReply + "107" + Sequence() + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode; |
| | | Dt_HostLog hostLog = new Dt_HostLog() |
| | | { |
| | | CommandID = 107, |
| | | Count = 0, |
| | | Messgae = str, |
| | | }; |
| | | _hostLogRepository.AddData(hostLog); |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | LogFactory.GetLog("EmptyOutBound").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="AgvStatus"></param> |
| | | public void DeviceStatusReportResponse(HOSTAGVStatus AgvStatus, string X, string Y) |
| | | { |
| | | string str = SendNotReply + "910" + BaseDal.GetSeqNo().Result.ToString() + "1" + GetFieldsAsString(AgvStatus) + X + Y; |
| | | try |
| | | { |
| | | string str = SendNotReply + "910" + Sequence() + GetFieldsAsString(AgvStatus) + X + Y; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | var hostlog = SqlSugarHelper.DbWMS.Queryable<Dt_HostLog>().Where(x => x.CommandID == 910).First(); |
| | | if (hostlog != null) |
| | | { |
| | | 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) |
| | | { |
| | | LogFactory.GetLog("DeviceStatusReportResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå¤HOST987å·¥åº å·¥åº988 |
| | | /// </summary> |
| | | /// <param name="AgvStatus"></param> |
| | | /// <param name="X"></param> |
| | | /// <param name="Y"></param> |
| | | public void FireAlarmReportResponse(string SeqNo, string IsOK, string Location) |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "988" + SeqNo + IsOK + Location; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("FireAlarmReportResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// åå¤HOST301å·¥åº å·¥åº302 |
| | | /// </summary> |
| | | /// <param name="AgvStatus"></param> |
| | | /// <param name="X"></param> |
| | | /// <param name="Y"></param> |
| | | public void UpdateLocalTimeResponse(string message, string SeqNo) |
| | | { |
| | | try |
| | | { |
| | | string str = SendNotReply + "302" + SeqNo + message; |
| | | clientSend(MakeStringToByteMsg(str)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("UpdateLocalTimeResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | #endregion |
| | |
| | | /// <param name="message"></param> |
| | | public void ReceiveCommandResponse(string message) |
| | | { |
| | | var parseMessage = GetParse(message); |
| | | switch (parseMessage.body.ret) |
| | | try |
| | | { |
| | | //OK |
| | | case "0": |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation); |
| | | if (location == null) |
| | | { |
| | | return; |
| | | } |
| | | if (location.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | InsertWMSTask(parseMessage); |
| | | Thread.Sleep(500); |
| | | //915 |
| | | JobReady("0"); |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | //todoè´§ä½æè´§éå¤å
¥åº |
| | | return; |
| | | } |
| | | //NG |
| | | case "1": |
| | | break; |
| | | //æ åºä½åé
|
| | | case "2": |
| | | break; |
| | | //ç«å°å°ç«å°ï¼åºåºç«å°æªåå¤å¥½ |
| | | case "3": |
| | | break; |
| | | //éå¸¸æ¸©å·¥ç¨ |
| | | case "4": |
| | | break; |
| | | |
| | | case "9": |
| | | break; |
| | | default: |
| | | break; |
| | | ParseMessage parseMessage = GetParse(message); |
| | | var lcationEnd = parseMessage.body.ToLocation; |
| | | switch (parseMessage.body.ret) |
| | | { |
| | | //OK |
| | | case "0": |
| | | GetLocation(parseMessage); |
| | | break; |
| | | //NG |
| | | case "1": |
| | | AddErrorMessage("2013", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | //æ åºä½åé
|
| | | case "2": |
| | | AddErrorMessage("2014", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | //ç«å°å°ç«å°ï¼åºåºç«å°æªåå¤å¥½ |
| | | case "3": |
| | | AddErrorMessage("2015", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | //éå¸¸æ¸©å·¥ç¨ |
| | | case "4": |
| | | AddErrorMessage("2016", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | case "9": |
| | | AddErrorMessage("2017", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host102åå¤WMS101ReceiveCommandResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | public void AGVJobStartOrEndResponse(string status, string message) |
| | | { |
| | | switch (message) |
| | | try |
| | | { |
| | | //OK |
| | | case "0": |
| | | if (status == "E") |
| | | { |
| | | DeviceStateReport("I"); |
| | | Thread.Sleep(3000); |
| | | JobReady("1"); |
| | | } |
| | | break; |
| | | //NG |
| | | case "1": |
| | | //è°ç¨AGVæåæ¥å£ |
| | | break; |
| | | case "9": |
| | | break; |
| | | default: |
| | | break; |
| | | switch (message) |
| | | { |
| | | //OK |
| | | case "0": |
| | | if (status == "E") |
| | | { |
| | | AGVStatusRespone Agvstatus = GetAGVStatus(); |
| | | |
| | | DeviceStateReport(GetAGVStatus(Agvstatus.RuntimeStatus)); |
| | | Thread.Sleep(3000); |
| | | JobReady("1"); |
| | | } |
| | | break; |
| | | //NG |
| | | case "1": |
| | | //è°ç¨AGVæåæ¥å£ |
| | | AddErrorMessage("2004", "Host", ""); |
| | | break; |
| | | case "9": |
| | | AddErrorMessage("2005", "Host", ""); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host906åå¤WMS905AGVJobStartOrEndResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public void DataReportResponse(string message) |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish || x.TaskState == (int)TaskRelocationStatusEnum.AGV_RelocationFinish || x.TaskState == (int)TaskInStatusEnum.AGV_InFinish); |
| | | if (task != null) |
| | | try |
| | | { |
| | | switch (task.TaskType) |
| | | DeleteHostLog(901); |
| | | #region |
| | | switch (message) |
| | | { |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | //å
¥åº |
| | | task.TaskState = (int)TaskInStatusEnum.AGV_InFinish; |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | CompleteInboundTask(task); |
| | | case "0": |
| | | |
| | | break; |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | //åºåº |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | CompleteOutboundTask(task); |
| | | case "1": |
| | | AddErrorMessage("2001", "Host", ""); |
| | | break; |
| | | case (int)TaskRelocationTypeEnum.Relocation: |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationFinish; |
| | | CompleteRelocationboundTask(task); |
| | | break; |
| | | case (int)TaskStationTypeEnum.StationToStation: |
| | | if (message == "0") |
| | | { |
| | | JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode); |
| | | } |
| | | task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish; |
| | | TaskMoveHty(task); |
| | | case "9": |
| | | AddErrorMessage("2002", "Host", ""); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host902åå¤WMS901DataReportResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | /// <summary> |
| | | /// HOSTä¸ååºåºä»»å¡ å·¥åº103 |
| | |
| | | { |
| | | //OK |
| | | case "0": |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation); |
| | | if (location == null) |
| | | { |
| | | return; |
| | | } |
| | | if (location.LocationStatus == (int)LocationEnum.InStock) |
| | | { |
| | | var task = InsertWMSTask(parseMessage); |
| | | BaseDal.AddData(task); |
| | | InsertAGVTask(task); |
| | | Thread.Sleep(500); |
| | | //915 |
| | | JobReady("0"); |
| | | Thread.Sleep(500); |
| | | //104 |
| | | DeviceReceiveJobResponse("0"); |
| | | } |
| | | else |
| | | { |
| | | //todoè´§ä½æ 货空åºåº |
| | | return; |
| | | } |
| | | |
| | | GetLocation(parseMessage); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | DeviceReceiveJobResponse("1"); |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host103HOSTOutBoundTask").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// HOST设å¤ç¶æè·å å·¥åº935 |
| | | /// </summary> |
| | | /// <param name="message"></param> |
| | | public void DeviceStationStatusInvite() |
| | | public void DeviceStationStatusInvite(string sSeqNo) |
| | | { |
| | | try |
| | | { |
| | | //åå¤936 |
| | | List<Dt_StationManager> Instation = _stationManagerRepository.QueryData(x => x.stationType == 1).ToList(); |
| | | List<Dt_StationManager> Outstation = _stationManagerRepository.QueryData(x => x.stationType == 2).ToList(); |
| | | List<OutStationStatus> outStationStatus = new List<OutStationStatus>(); |
| | | List<InStationStatus> inStationStatus = new List<InStationStatus>(); |
| | | foreach (var item in Instation) |
| | | |
| | | StationStatus stationIn = GetStationStatus("B002"); |
| | | StationStatus stationOut = GetStationStatus("B001"); |
| | | |
| | | if (stationIn == null || stationOut == null) |
| | | { |
| | | inStationStatus.Add(new InStationStatus() |
| | | { |
| | | StationName = item.stationName, |
| | | StationEnable = item.stationStatus, |
| | | IsDistributionTask = item.stationHasTask, |
| | | PallteCode = "0000000000", |
| | | }); |
| | | ErrorReport("2103", "A", "00"); |
| | | } |
| | | foreach (var item in Outstation) |
| | | { |
| | | StationStatus station = GetStationStatus(item.stationName); |
| | | var taskStation = BaseDal.QueryFirst(x => x.SourceAddress == item.stationName || x.TargetAddress == item.stationName); |
| | | outStationStatus.Add(new OutStationStatus() |
| | | { |
| | | StationName = item.HostName, |
| | | StationEnable = station.StationEnable == "1" ? "0" : "1", |
| | | IsDistributionTask = taskStation == null ? "0" : "1", |
| | | Spare1 = "00" |
| | | }); |
| | | //outStationStatus.Add(new OutStationStatus() |
| | | //{ |
| | | // StationName = item.stationName, |
| | | // StationEnable = item.stationStatus, |
| | | // IsDistributionTask = item.stationHasTask, |
| | | // Spare1 = "00" |
| | | //}); |
| | | } |
| | | |
| | | List<OutStationStatus> outStationStatus = GetOutStationStatus(stationOut); |
| | | List<InStationStatus> inStationStatus = GetInStationStatus(stationIn); |
| | | |
| | | #region |
| | | //inStationStatus.Add(new InStationStatus() |
| | | //{ |
| | | // StationName = "02", |
| | | // StationEnable = stationIn.WorkstationO == "1" ? "0" : "1", |
| | | // IsDistributionTask = "0", |
| | | // PallteCode = "0000000000", |
| | | //}); |
| | | //inStationStatus.Add(new InStationStatus() |
| | | //{ |
| | | // StationName = "01", |
| | | // StationEnable = stationIn.WorkstationT == "1" ? "0" : "1", |
| | | // IsDistributionTask = "0", |
| | | // PallteCode = "0000000000", |
| | | //}); |
| | | //var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1"); |
| | | //var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2"); |
| | | //outStationStatus.Add(new OutStationStatus() |
| | | //{ |
| | | // StationName = "04", |
| | | // StationEnable = stationOut.WorkstationO == "1" ? "0" : "1", |
| | | // IsDistributionTask = taskOutStationO == null ? "0" : "1", |
| | | // Spare1 = "00" |
| | | //}); |
| | | //outStationStatus.Add(new OutStationStatus() |
| | | //{ |
| | | // StationName = "03", |
| | | // StationEnable = stationOut.WorkstationT == "1" ? "0" : "1", |
| | | // IsDistributionTask = taskOutStationT == null ? "0" : "1", |
| | | // Spare1 = "00" |
| | | //}); |
| | | #endregion |
| | | AGVStatusRespone status = GetAGVStatus(); |
| | | HOSTAGVStatus AgvStatus = new HOSTAGVStatus() |
| | | { |
| | | RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus), |
| | | AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0", |
| | | Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1", |
| | | }; |
| | | DeviceStationStatusReport(AgvStatus, outStationStatus, inStationStatus); |
| | | if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode") |
| | | { |
| | | AgvStatus.Ready = "1"; |
| | | } |
| | | else |
| | | { |
| | | AgvStatus.Ready = "0"; |
| | | } |
| | | DeviceStationStatusReport(AgvStatus, outStationStatus, inStationStatus, sSeqNo); |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | DeviceReceiveJobResponse("1"); |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host935DeviceStationStatusInvite").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | JobReady("1"); |
| | | } |
| | | |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | DeleteHostLog(105); |
| | | var parseMessage = GetParse(message); |
| | | var lcationEnd = parseMessage.body.ToLocation; |
| | | switch (parseMessage.body.ret) |
| | | { |
| | | //OK |
| | | case "0": |
| | | UpdateTaskLocation(parseMessage); |
| | | GetLocation(parseMessage, true); |
| | | break; |
| | | //NG |
| | | case "1": |
| | | AddErrorMessage("2019", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | //æ åºä½åé
|
| | | case "2": |
| | | AddErrorMessage("2020", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | case "9": |
| | | AddErrorMessage("2021", "Host", StationParse(parseMessage.body.FromLocation)); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | DeviceReceiveJobResponse("1"); |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host106éæ°åé
åºä½RecreateGetLocation").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | JobReady("1"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="message"></param> |
| | | public void EmptyOutBoundResponse(string message) |
| | | { |
| | | if (message != null && message == "0") |
| | | try |
| | | { |
| | | DeviceStateReport("I"); |
| | | Thread.Sleep(500); |
| | | JobReady("1"); |
| | | |
| | | DeleteHostLog(107); |
| | | if (message != null) |
| | | { |
| | | switch (message) |
| | | { |
| | | case "0": |
| | | AGVStatusRespone Agvstatus = GetAGVStatus(); |
| | | DeviceStateReport(GetAGVStatus(Agvstatus.RuntimeStatus)); |
| | | Thread.Sleep(2000); |
| | | JobReady("1"); |
| | | break; |
| | | case "1": |
| | | AddErrorMessage("2023", "Host", ""); |
| | | break; |
| | | case "9": |
| | | AddErrorMessage("2024", "Host", ""); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("Host108空åºåºååºEmptyOutBoundResponse").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Hostä¸åç«è¦ä»»å¡ 987 |
| | | /// </summary> |
| | | public void FireAlarm(string Location, string SeqNo) |
| | | { |
| | | try |
| | | { |
| | | Dt_Task taskNew = new Dt_Task(); |
| | | var stock = SqlSugarHelper.DbWMS.Queryable<DtStockInfo>().Where(x => x.LocationCode == Location).First(); |
| | | |
| | | var location = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.SourceAddress == Location).First(); |
| | | if (location != null) |
| | | { |
| | | FireAlarmReportResponse(SeqNo, "0", Location); |
| | | return; |
| | | } |
| | | var stationOne = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.TargetAddress == "B001::1").ToList(); |
| | | var stationTwo = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.TargetAddress == "B001::2").ToList(); |
| | | |
| | | if (stationOne.Count > 0 && stationTwo.Count > 0) |
| | | { |
| | | if (stationOne.Count > stationTwo.Count) |
| | | { |
| | | taskNew = GetFireAlarm(Location, "B001::2", stock == null ? "F" + DateTime.Now.ToString("HHmmss") + new Random().Next(100, 1000) : stock.PalletCode, SeqNo); |
| | | } |
| | | else |
| | | { |
| | | taskNew = GetFireAlarm(Location, "B001::1", stock == null ? "F" + DateTime.Now.ToString("HHmmss") + new Random().Next(100, 1000) : stock.PalletCode, SeqNo); |
| | | } |
| | | FireAlarmReportResponse(SeqNo, "0", Location); |
| | | } |
| | | else |
| | | { |
| | | StationStatus stationOut = GetStationStatus("B001"); |
| | | |
| | | if (stationOut != null && stationOut.WorkstationO == "0" && stationOne.Count == 0) |
| | | { |
| | | taskNew = GetFireAlarm(Location, "B001::1", stock == null ? "F" + DateTime.Now.ToString("HHmmss") + new Random().Next(100, 1000) : stock.PalletCode, SeqNo); |
| | | } |
| | | else if (stationOut != null && stationOut.WorkstationT == "0" && stationTwo.Count == 0) |
| | | { |
| | | taskNew = GetFireAlarm(Location, "B001::2", stock == null ? "F" + DateTime.Now.ToString("HHmmss") + new Random().Next(100, 1000) : stock.PalletCode, SeqNo); |
| | | } |
| | | else |
| | | { |
| | | taskNew = GetFireAlarm(Location, "B001::2", stock == null ? "F" + DateTime.Now.ToString("HHmmss") + new Random().Next(100, 1000) : stock.PalletCode, SeqNo); |
| | | } |
| | | FireAlarmReportResponse(SeqNo, "0", Location); |
| | | } |
| | | BaseDal.AddData(taskNew); |
| | | InsertAGVTask(taskNew); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("ç«è¦987FireAlarm").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·åæ¶é²ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="SourceAddress">èµ·å§å°å</param> |
| | | /// <param name="TargetAddress">ç»ç¹å°å</param> |
| | | /// <param name="PalletCode">æçå·</param> |
| | | /// <param name="SeqNo">Hoståºåå·</param> |
| | | /// <returns></returns> |
| | | public Dt_Task GetFireAlarm(string SourceAddress, string TargetAddress, string PalletCode, string SeqNo) |
| | | { |
| | | return new Dt_Task() |
| | | { |
| | | SourceAddress = SourceAddress, |
| | | TargetAddress = TargetAddress, |
| | | CurrentAddress = SourceAddress, |
| | | NextAddress = TargetAddress, |
| | | TaskType = (int)TaskFireAlarmTypeEnum.FireAlarmOut, |
| | | TaskState = (int)TaskFireAlarmStatusEnum.FireAlarmNew, |
| | | Remark = TargetAddress, |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | PalletCode = PalletCode == null ? "" : PalletCode, |
| | | Dispatchertime = DateTime.Now, |
| | | Grade = 1, |
| | | SeqNo = Convert.ToInt32(SeqNo), |
| | | CommandID = Convert.ToInt32(987), |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public void DeviceStatusReportRequest() |
| | | { |
| | | AGVStatusRespone status = GetAGVStatus(); |
| | | |
| | | HOSTAGVStatus AgvStatus = new HOSTAGVStatus() |
| | | try |
| | | { |
| | | RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus), |
| | | AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0", |
| | | Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1", |
| | | }; |
| | | string axis = "000000"; |
| | | DeviceStatusReportResponse(AgvStatus, axis, axis); |
| | | DeleteHostLog(910); |
| | | AGVStatusRespone status = GetAGVStatus(); |
| | | |
| | | HOSTAGVStatus AgvStatus = new HOSTAGVStatus() |
| | | { |
| | | RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus), |
| | | AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0", |
| | | |
| | | }; |
| | | if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode") |
| | | { |
| | | AgvStatus.Ready = "1"; |
| | | } |
| | | else |
| | | { |
| | | AgvStatus.Ready = "0"; |
| | | } |
| | | string axis = "000000"; |
| | | |
| | | DeviceStatusReportResponse(AgvStatus, axis, axis); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | 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) |
| | | { |
| | | try |
| | | { |
| | | SYSTEMTIME newTime = new SYSTEMTIME |
| | | { |
| | | 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)), |
| | | Minute = Convert.ToUInt16(Time.Substring(10, 2)), |
| | | Second = Convert.ToUInt16(Time.Substring(12, 2)), |
| | | Milliseconds = 0 |
| | | }; |
| | | if (SetLocalTime(ref newTime)) |
| | | { |
| | | UpdateLocalTimeResponse("0", SeqNo); |
| | | Console.WriteLine("ç³»ç»æ¶é´å·²æåä¿®æ¹ã"); |
| | | } |
| | | else |
| | | { |
| | | UpdateLocalTimeResponse("1", SeqNo); |
| | | Console.WriteLine("ä¿®æ¹ç³»ç»æ¶é´å¤±è´¥ã请确ä¿ä»¥ç®¡çåæéè¿è¡æ¤ç¨åºã"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ErrorReport("2199", "A", "00"); |
| | | LogFactory.GetLog("UpdateLocalTimeæ¶é´åæ¥").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(ex.Message)}{Environment.NewLine}{ex.StackTrace}", ""); |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | |
| | |
| | | { |
| | | byte[] byt = Encoding.UTF8.GetBytes(Message); // ä½¿ç¨ UTF-8 é¿å
ç¼ç é®é¢ |
| | | |
| | | LogFactory.GetLog("è¯·æ±æçä»»å¡").Error(true, BitConverter.ToString(byt)); |
| | | string checksum = GetCheckSum(byt); |
| | | |
| | | string str = Message + checksum; |
| | |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | //public bool IsOnline() |
| | | //{ |
| | | |
| | | //} |
| | | public string GetListStringOutStation(List<OutStationStatus> outStationStatus) |
| | | { |
| | | return string.Join("", outStationStatus.Select(status => $"{status.StationName}{status.StationEnable}{status.IsDistributionTask}{status.Spare1}")); |
| | | } |
| | | public string GetListStringInStation(List<InStationStatus> inStationStatus) |
| | | { |
| | | return string.Join("", inStationStatus.Select(status => $"{status.StationName}{status.StationEnable}{status.IsDistributionTask}{status.Spare1}")); |
| | | return string.Join("", inStationStatus.Select(status => $"{status.StationName}{status.StationEnable}{status.IsDistributionTask}{status.IsHasPallte}{status.Spare1}{status.StationPallteCount}{status.PallteCode}{status.Spare2}")); |
| | | } |
| | | /// <summary> |
| | | /// å°å¯¹è±¡å¼åæ¼æ¥ |
| | |
| | | } |
| | | } |
| | | |
| | | public ParseMessage SubString(string Y) |
| | | public List<OutStationStatus> GetOutStationStatus(StationStatus stationOut) |
| | | { |
| | | |
| | | const string STX = "0x02"; |
| | | const string ETX = "0x03"; |
| | | |
| | | // æ£æ¥æ¯å¦ä»¥ STX å¼å¤´ãETX ç»å°¾ |
| | | if (Y.Substring(0, 4) == STX && Y.Substring(Y.Length - 4) == ETX) |
| | | List<OutStationStatus> outStationStatus = new List<OutStationStatus>(); |
| | | var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1"); |
| | | var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2"); |
| | | outStationStatus.Add(new OutStationStatus() |
| | | { |
| | | string str = Y.Substring(4, Y.Length - 8); |
| | | byte[] message = Encoding.UTF8.GetBytes(str); |
| | | int newLength = message.Length - 2; |
| | | |
| | | if (newLength < 0) |
| | | { |
| | | throw new ArgumentException("æ°ç»é¿åº¦ä¸è¶³ï¼æ æ³å»ææå两ä½ã"); |
| | | } |
| | | |
| | | byte[] newArray = new byte[newLength]; |
| | | Array.Copy(message, 0, newArray, 0, newLength); |
| | | string calculatedChecksum = GetCheckSum(newArray); |
| | | |
| | | string receivedChecksum = str.Substring(str.Length - 2); |
| | | |
| | | if (calculatedChecksum == receivedChecksum) |
| | | { |
| | | var x = Encoding.UTF8.GetString(newArray); |
| | | ParseMessage parseMessage = new ParseMessage() |
| | | { |
| | | bDir = x.Substring(0, 1), |
| | | bObjID = x.Substring(2, 10), |
| | | bReply = x.Substring(11, 1), |
| | | bCmdID = x.Substring(12, 3), |
| | | nSeqNo = x.Substring(15, 5), |
| | | //Body = x.Substring(21), |
| | | }; |
| | | return parseMessage; |
| | | } |
| | | else |
| | | { |
| | | Console.WriteLine("æ ¡éªå¤±è´¥ï¼"); |
| | | return null; |
| | | } |
| | | } |
| | | else |
| | | StationName = "04", |
| | | StationEnable = stationOut.WorkstationO == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationO == null ? "0" : "1", |
| | | Spare1 = "00" |
| | | }); |
| | | outStationStatus.Add(new OutStationStatus() |
| | | { |
| | | Console.WriteLine("æ ææ¥ææ ¼å¼ï¼"); |
| | | return null; |
| | | } |
| | | StationName = "03", |
| | | StationEnable = stationOut.WorkstationT == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationT == null ? "0" : "1", |
| | | Spare1 = "00" |
| | | }); |
| | | return outStationStatus; |
| | | } |
| | | #endregion |
| | | |
| | | #region å®ä¹å¯¹è±¡ |
| | | |
| | | |
| | | public List<InStationStatus> GetInStationStatus(StationStatus stationIn) |
| | | { |
| | | List<InStationStatus> inStationStatus = new List<InStationStatus>(); |
| | | var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B002::1" || x.TargetAddress == "B002::1"); |
| | | var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B002::2" || x.TargetAddress == "B002::2"); |
| | | inStationStatus.Add(new InStationStatus() |
| | | { |
| | | StationName = "02", |
| | | StationEnable = stationIn.WorkstationO == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationO == null ? "0" : "1", |
| | | PallteCode = "0000000000", |
| | | }); |
| | | inStationStatus.Add(new InStationStatus() |
| | | { |
| | | StationName = "01", |
| | | StationEnable = stationIn.WorkstationT == "1" ? "0" : "1", |
| | | IsDistributionTask = taskOutStationT == null ? "0" : "1", |
| | | PallteCode = "0000000000", |
| | | }); |
| | | return inStationStatus; |
| | | } |
| | | #endregion |
| | | |
| | | #region ç§ææ¹æ³ |
| | | private void UpdateTaskLocation(ParseMessage parseMessage) |
| | | /// <summary> |
| | | /// æ·»å WMSä»»å¡ |
| | | /// </summary> |
| | | /// <param name="parseMessage"></param> |
| | | /// <exception cref="Exception"></exception> |
| | | private void InsertWMSTask(ParseMessage parseMessage) |
| | | { |
| | | var task = BaseDal.QueryFirst(x => x.SeqNo == Convert.ToInt32(parseMessage.nSeqNo) && x.PalletCode.Contains(parseMessage.body.TrayIdList)); |
| | | if (task != null) |
| | | { |
| | | task.TargetAddress = parseMessage.body.ToLocation; |
| | | task_call agvtask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(it => it.d_involed5 == task.TaskNum).First(); |
| | | BaseDal.Update(task); |
| | | SqlSugarHelper.DbAGV.Updateable(agvtask).ExecuteCommand(); |
| | | } |
| | | |
| | | } |
| | | |
| | | private Dt_Task InsertWMSTask(ParseMessage parseMessage) |
| | | { |
| | | //var task = BaseDal.QueryFirst(x => x.PalletCode.Contains(parseMessage.body.TrayIdList)); |
| | | int taskType = 0; |
| | | int taskState = 0; |
| | | Dt_Task task = new Dt_Task(); |
| | | if (parseMessage.body.JobType == "I") |
| | | { |
| | | Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.FromLocation.Substring(4, 2)); |
| | | task.SourceAddress = StationParse(parseMessage.body.FromLocation); |
| | | task.TargetAddress = parseMessage.body.ToLocation; |
| | | task.CurrentAddress = StationParse(parseMessage.body.FromLocation); |
| | | task.NextAddress = parseMessage.body.ToLocation; |
| | | taskType = (int)TaskInboundTypeEnum.Inbound; |
| | | taskState = (int)TaskInStatusEnum.InNew; |
| | | task.Remark = parseMessage.body.FromLocation; |
| | | |
| | | } |
| | | else if (parseMessage.body.JobType == "O") |
| | | { |
| | | task.SourceAddress = parseMessage.body.FromLocation; |
| | | task.TargetAddress = StationParse(parseMessage.body.ToLocation); |
| | | task.CurrentAddress = parseMessage.body.FromLocation; |
| | | task.NextAddress = StationParse(parseMessage.body.ToLocation); |
| | | taskType = (int)TaskOutboundTypeEnum.Outbound; |
| | | taskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.Remark = parseMessage.body.ToLocation; |
| | | } |
| | | else if (parseMessage.body.JobType == "C") |
| | | { |
| | | task.SourceAddress = parseMessage.body.FromLocation; |
| | | task.TargetAddress = StationParse(parseMessage.body.ToLocation); |
| | | task.CurrentAddress = parseMessage.body.FromLocation; |
| | | task.NextAddress = StationParse(parseMessage.body.ToLocation); |
| | | taskType = (int)TaskOutboundTypeEnum.OutQuality; |
| | | taskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.Remark = parseMessage.body.ToLocation; |
| | | } |
| | | else if (parseMessage.body.JobType == "S") |
| | | { |
| | | taskType = (int)TaskStationTypeEnum.StationToStation; |
| | | taskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.SourceAddress = StationParse(parseMessage.body.FromLocation); |
| | | task.TargetAddress = StationParse(parseMessage.body.ToLocation); |
| | | task.CurrentAddress = StationParse(parseMessage.body.FromLocation); |
| | | task.NextAddress = StationParse(parseMessage.body.ToLocation); |
| | | task.Remark = parseMessage.body.FromLocation; |
| | | task.HostName = parseMessage.body.ToLocation; |
| | | } |
| | | else if (parseMessage.body.JobType == "R") |
| | | { |
| | | taskType = (int)TaskRelocationTypeEnum.Relocation; |
| | | taskState = (int)TaskRelocationStatusEnum.RelocationNew; |
| | | task.SourceAddress = parseMessage.body.FromLocation; |
| | | task.TargetAddress = parseMessage.body.ToLocation; |
| | | task.CurrentAddress = parseMessage.body.FromLocation; |
| | | task.NextAddress = parseMessage.body.ToLocation; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("æªç¥åºä½"); |
| | | } |
| | | return new Dt_Task() |
| | | { |
| | | TaskNum = BaseDal.GetTaskNo().Result, |
| | | SourceAddress = parseMessage.body.FromLocation, |
| | | TargetAddress = parseMessage.body.ToLocation, |
| | | PalletCode = parseMessage.body.TrayIdList.Substring(0, 10), |
| | | TaskType = taskType, |
| | | TaskState = taskState, |
| | | Dispatchertime = DateTime.Now, |
| | | SeqNo = Convert.ToInt32(parseMessage.nSeqNo), |
| | | CommandID = Convert.ToInt32(parseMessage.bCmdID) |
| | | }; |
| | | |
| | | |
| | | task.TaskNum = BaseDal.GetTaskNo().Result; |
| | | task.PalletCode = parseMessage.body.TrayIdList.Substring(0, 10); |
| | | task.TaskType = taskType; |
| | | task.TaskState = taskState; |
| | | task.Dispatchertime = DateTime.Now; |
| | | task.Grade = 1; |
| | | task.SeqNo = Convert.ToInt32(parseMessage.nSeqNo); |
| | | task.CommandID = Convert.ToInt32(parseMessage.bCmdID); |
| | | BaseDal.AddData(task); |
| | | InsertAGVTask(task); |
| | | } |
| | | |
| | | |
| | | public void GetLocation(ParseMessage parseMessage, bool repeat = false) |
| | | { |
| | | |
| | | switch (parseMessage.body.JobType) |
| | | { |
| | | case "I": |
| | | var locationIn = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First(); |
| | | if (locationIn == null) |
| | | { |
| | | ErrorReport("2102", "A", "00"); |
| | | return; |
| | | } |
| | | if (locationIn.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | var taskIn = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.PalletCode == parseMessage.body.TrayIdList.Substring(0, 10)).First(); |
| | | if (taskIn != null) |
| | | { |
| | | _taskService.UpdateTask(StationParse(parseMessage.body.FromLocation), parseMessage.body.ToLocation, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | } |
| | | else |
| | | { |
| | | InsertWMSTask(parseMessage); |
| | | } |
| | | Thread.Sleep(500); |
| | | JobReady("0"); |
| | | } |
| | | else |
| | | { |
| | | RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | } |
| | | break; |
| | | case "O": |
| | | case "C": |
| | | var locationOut = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.FromLocation).First(); |
| | | if (locationOut == null) |
| | | { |
| | | ErrorReport("2102", "A", "00"); |
| | | return; |
| | | } |
| | | if (locationOut.LocationStatus == (int)LocationEnum.InStock) |
| | | { |
| | | var taskOut = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.PalletCode == parseMessage.body.TrayIdList.Substring(0, 10)).First(); |
| | | if (taskOut != null) |
| | | { |
| | | _taskService.UpdateTask(locationOut.LocationCode, StationParse(parseMessage.body.ToLocation), parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | } |
| | | else |
| | | { |
| | | InsertWMSTask(parseMessage); |
| | | } |
| | | Thread.Sleep(500); |
| | | JobReady("0"); |
| | | Thread.Sleep(500); |
| | | //104 |
| | | DeviceReceiveJobResponse("0"); |
| | | } |
| | | else |
| | | { |
| | | EmptyOutBound(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | _taskService.AddStcokHty(parseMessage.body.TrayIdList.Substring(0, 10), parseMessage.body.FromLocation); |
| | | } |
| | | break; |
| | | case "S": |
| | | var taskS = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.PalletCode == parseMessage.body.TrayIdList.Substring(0, 10)).First(); |
| | | if (taskS != null) |
| | | { |
| | | _taskService.UpdateTask(StationParse(parseMessage.body.FromLocation), StationParse(parseMessage.body.ToLocation), parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | } |
| | | else |
| | | { |
| | | InsertWMSTask(parseMessage); |
| | | } |
| | | Thread.Sleep(500); |
| | | JobReady("0"); |
| | | |
| | | break; |
| | | case "R": |
| | | var locationA = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.FromLocation).First(); |
| | | var locationB = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First(); |
| | | if (locationA == null || locationB == null) |
| | | { |
| | | ErrorReport("2102", "A", "00"); |
| | | return; |
| | | } |
| | | if (locationA.LocationStatus == (int)LocationEnum.InStock && locationB.LocationStatus == (int)LocationEnum.Free) |
| | | { |
| | | var taskR = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.PalletCode == parseMessage.body.TrayIdList.Substring(0, 10)).First(); |
| | | if (taskR != null) |
| | | { |
| | | |
| | | _taskService.UpdateTask(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | } |
| | | else |
| | | { |
| | | InsertWMSTask(parseMessage); |
| | | } |
| | | Thread.Sleep(500); |
| | | JobReady("0"); |
| | | } |
| | | else |
| | | { |
| | | RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10)); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ·»å AGVä»»å¡ |
| | |
| | | { |
| | | string SourceAddress = string.Empty; |
| | | string TargetAddress = string.Empty; |
| | | string AGVType = string.Empty; |
| | | if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) |
| | | { |
| | | SourceAddress = task.SourceAddress; |
| | | AGVType = "2"; |
| | | TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress); |
| | | } |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound) |
| | | { |
| | | SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); |
| | | TargetAddress = task.TargetAddress; |
| | | AGVType = "4"; |
| | | } |
| | | else if (task.TaskType == (int)TaskOutboundTypeEnum.OutQuality) |
| | | { |
| | | SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); |
| | | TargetAddress = task.TargetAddress; |
| | | AGVType = "128"; |
| | | } |
| | | else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation) |
| | | { |
| | | TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress); |
| | | SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); |
| | | AGVType = "16"; |
| | | } |
| | | else if (task.TaskType == (int)TaskStationTypeEnum.StationToStation) |
| | | { |
| | | TargetAddress = task.TargetAddress; |
| | | SourceAddress = task.SourceAddress; |
| | | SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); |
| | | AGVType = "8"; |
| | | } |
| | | else if (task.TaskType == (int)TaskFireAlarmTypeEnum.FireAlarmOut) |
| | | { |
| | | TargetAddress = task.TargetAddress; |
| | | SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); |
| | | AGVType = "1"; |
| | | } |
| | | task_call task_Call = new task_call() |
| | | { |
| | | d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? 1 : 2, |
| | | d_floor = 1, |
| | | d_task_type = AGVType, |
| | | d_floor = "1", |
| | | d_involed1 = SourceAddress, |
| | | d_involed2 = TargetAddress, |
| | | d_involed5 = task.TaskNum, |
| | | d_involed5 = task.TaskNum.ToString(), |
| | | }; |
| | | |
| | | return SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); |
| | | var x = SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); |
| | | LogFactory.GetLog("æå
¥æ°æ®å°AGV").InfoFormat(true, $"请æ±åæ°ï¼{JsonConvert.SerializeObject(x)}", ""); |
| | | return x; |
| | | } |
| | | public ParseMessage GetParse(string x) |
| | | { |
| | | return new ParseMessage() |
| | | |
| | | if (string.IsNullOrEmpty(x)) |
| | | { |
| | | bDir = x.Substring(0, 1), |
| | | bObjID = x.Substring(2, 10), |
| | | bReply = x.Substring(11, 1), |
| | | bCmdID = x.Substring(12, 3), |
| | | nSeqNo = x.Substring(15, 5), |
| | | body = new ReceiveBody |
| | | { |
| | | ret = x.Substring(21, 1), |
| | | JobOrderID = x.Substring(22, 16), |
| | | priority = x.Substring(39, 1), |
| | | FromLocation = x.Substring(40, 6), |
| | | ToLocation = x.Substring(47, 6), |
| | | JobType = x.Substring(54, 1), |
| | | TrayCnt = x.Substring(55, 1), |
| | | TrayIdList = x.Substring(56) |
| | | }, |
| | | throw new ArgumentNullException(nameof(x), "Input string cannot be null or empty"); |
| | | } |
| | | |
| | | // å®ä¹ææéè¦çåæ®µé¿åº¦åä½ç½® |
| | | var fieldDefinitions = new (int Start, int Length, string Name)[] |
| | | { |
| | | (0, 1, "bDir"), |
| | | (1, 10, "bObjID"), |
| | | (11, 1, "bReply"), |
| | | (12, 3, "bCmdID"), |
| | | (15, 5, "nSeqNo"), |
| | | (20, 1, "ret"), |
| | | (21, 16, "JobOrderID"), |
| | | (37, 1, "priority"), |
| | | (38, 6, "FromLocation"), |
| | | (44, 6, "ToLocation"), |
| | | (50, 1, "JobType"), |
| | | (51, 1, "TrayCnt"), |
| | | (52, x.Length - 52, "TrayIdList") // å¯åé¿åº¦å段 |
| | | }; |
| | | |
| | | // è®¡ç®æéæå°é¿åº¦ |
| | | int minLength = fieldDefinitions.Max(f => f.Start + f.Length); |
| | | |
| | | if (x.Length < minLength) |
| | | { |
| | | // 妿å符串é¿åº¦ä¸è¶³ï¼å¯ä»¥éæ©è®°å½è¦åææ¥å¿ |
| | | // è¿éæä»¬ç»§ç»å¤çï¼å°½å¯è½å¤å°è§£æå段 |
| | | } |
| | | |
| | | // è¾
婿¹æ³ï¼å®å
¨çåå符串æªåï¼é¿åº¦ä¸è¶³æ¶è¿å空å符串 |
| | | string SafeSubstringOrDefault(string source, int start, int length, string fieldName) |
| | | { |
| | | if (start < 0 || start >= source.Length) |
| | | { |
| | | return ""; // è¿å空å符串 |
| | | } |
| | | |
| | | if (length < 0) |
| | | { |
| | | return ""; // è¿å空å符串 |
| | | } |
| | | |
| | | if (start + length > source.Length) |
| | | { |
| | | length = source.Length - start; // è°æ´é¿åº¦ä»¥é¿å
è¶ç |
| | | } |
| | | |
| | | return source.Substring(start, length); |
| | | } |
| | | |
| | | // æå»ºç»æå¯¹è±¡ |
| | | var result = new ParseMessage(); |
| | | |
| | | // è®¾ç½®åºæ¬å段 |
| | | result.bDir = SafeSubstringOrDefault(x, fieldDefinitions[0].Start, fieldDefinitions[0].Length, fieldDefinitions[0].Name); |
| | | result.bObjID = SafeSubstringOrDefault(x, fieldDefinitions[1].Start, fieldDefinitions[1].Length, fieldDefinitions[1].Name); |
| | | result.bReply = SafeSubstringOrDefault(x, fieldDefinitions[2].Start, fieldDefinitions[2].Length, fieldDefinitions[2].Name); |
| | | result.bCmdID = SafeSubstringOrDefault(x, fieldDefinitions[3].Start, fieldDefinitions[3].Length, fieldDefinitions[3].Name); |
| | | result.nSeqNo = SafeSubstringOrDefault(x, fieldDefinitions[4].Start, fieldDefinitions[4].Length, fieldDefinitions[4].Name); |
| | | |
| | | // 设置bodyåæ®µ |
| | | result.body = new ReceiveBody |
| | | { |
| | | ret = SafeSubstringOrDefault(x, fieldDefinitions[5].Start, fieldDefinitions[5].Length, fieldDefinitions[5].Name), |
| | | JobOrderID = SafeSubstringOrDefault(x, fieldDefinitions[6].Start, fieldDefinitions[6].Length, fieldDefinitions[6].Name), |
| | | priority = SafeSubstringOrDefault(x, fieldDefinitions[7].Start, fieldDefinitions[7].Length, fieldDefinitions[7].Name), |
| | | FromLocation = SafeSubstringOrDefault(x, fieldDefinitions[8].Start, fieldDefinitions[8].Length, fieldDefinitions[8].Name), |
| | | ToLocation = SafeSubstringOrDefault(x, fieldDefinitions[9].Start, fieldDefinitions[9].Length, fieldDefinitions[9].Name), |
| | | JobType = SafeSubstringOrDefault(x, fieldDefinitions[10].Start, fieldDefinitions[10].Length, fieldDefinitions[10].Name), |
| | | TrayCnt = SafeSubstringOrDefault(x, fieldDefinitions[11].Start, fieldDefinitions[11].Length, fieldDefinitions[11].Name), |
| | | TrayIdList = SafeSubstringOrDefault(x, fieldDefinitions[12].Start, fieldDefinitions[12].Length, fieldDefinitions[12].Name) |
| | | }; |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public AGVStatusRespone GetAGVStatus() |
| | | { |
| | | string urlnew = url + "/ilns/AGV/getAgvState"; |
| | | string urlnew = url + "/ilns/AGV/getState"; |
| | | var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { getStatus = "1" }.ToJson())).Result; |
| | | |
| | | return JsonConvert.DeserializeObject<AGVStatusRespone>(result.ToString()); |
| | |
| | | |
| | | public StationStatus GetStationStatus(string stationName) |
| | | { |
| | | string urlnew = url + "/ilns/strl/getState"; |
| | | var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { strlName = stationName }.ToJson())).Result; |
| | | string urlnew = url + "/ilns/ctrl/getState"; |
| | | var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { ctrlName = stationName }.ToJson())).Result; |
| | | return JsonConvert.DeserializeObject<StationStatus>(result.ToString()); |
| | | } |
| | | public void ReportStationErrorMeaage(string StationName) |
| | | { |
| | | string urlnew = url + "/ilns/setctrlerr"; |
| | | var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { ctrlName = StationName }.ToJson())).Result; |
| | | } |
| | | public void ReportAgvErrorMeaage(string ErrorCode) |
| | | { |
| | | string urlnew = url + "/ilns/rpterr"; |
| | | var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { code = ErrorCode }.ToJson())).Result; |
| | | } |
| | | public void AddErrorMessage(string Code, string ReportName, string Location = "") |
| | | { |
| | | var errorDescription = SqlSugarHelper.DbWMS.Queryable<Dt_ErrorDescription>().Where(x => x.ErrorCode == Code).First(); |
| | | if (errorDescription != null) |
| | | { |
| | | Dt_HostErrorMessage hostErrorMessage = new Dt_HostErrorMessage() |
| | | { |
| | | ErrorCode = Code, |
| | | ErrorMessage = errorDescription.ErrorMessgae, |
| | | AlarmSource = errorDescription.AlarmSource, |
| | | Grade = errorDescription.Grade, |
| | | ReportName = ReportName, |
| | | Creater = "System", |
| | | Location = Location == "" ? "" : Location, |
| | | CreateDate = DateTime.Now, |
| | | }; |
| | | SqlSugarHelper.DbWMS.Insertable(hostErrorMessage).ExecuteCommand(); |
| | | if (Location == "") |
| | | { |
| | | ReportAgvErrorMeaage(Code); |
| | | } |
| | | else |
| | | { |
| | | ReportStationErrorMeaage(Location); |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | //todeä¸åå¨å¼å¸¸Code |
| | | } |
| | | } |
| | | public void DeleteHostLog(int CommandID) |
| | | { |
| | | var hostLog = SqlSugarHelper.DbWMS.Queryable<Dt_HostLog>().Where(x => x.CommandID == CommandID).First(); |
| | | if (hostLog != null) |
| | | { |
| | | SqlSugarHelper.DbWMS.Deleteable(hostLog).ExecuteCommand(); |
| | | } |
| | | } |
| | | |
| | | public string StationParse(string station) |
| | | { |
| | | var Station = SqlSugarHelper.DbWMS.Queryable<Dt_StationManager>().Where(x => x.HostName == station.Substring(4, 2)).First(); |
| | | if (Station != null) |
| | | { |
| | | return Station.stationName; |
| | | } |
| | | else |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | public string CapitalizeFirstLetter(string s) |
| | | { |
| | | if (s == "Pause") |
| | | { |
| | | return "S"; |
| | | } |
| | | else if (s == "PowerOFF") |
| | | { |
| | | return "O"; |
| | | } |
| | | if (string.IsNullOrEmpty(s)) |
| | | { |
| | | return ""; |
| | | } |
| | | |
| | | char firstChar = s[0]; |
| | | return char.ToUpper(firstChar).ToString(); |
| | | } |
| | | |
| | | public string GetAGVStatus(string Status) |
| | | { |
| | | switch (Status) |
| | | { |
| | | case "Run": |
| | | return "R"; |
| | | case "Idle": |
| | | return "I"; |
| | | case "Trouble": |
| | | //æ
é |
| | | return "T"; |
| | | case "Pause": |
| | | return "S"; |
| | | case "Charge": |
| | | return "C"; |
| | | case "PowerOn": |
| | | return "P"; |
| | | case "PowerOFF": |
| | | return "O"; |
| | | default: break; |
| | | } |
| | | return "T"; |
| | | } |
| | | |
| | | public string InsertHyphenEveryTwoChars(string input) |
| | | { |
| | | if (string.IsNullOrEmpty(input)) |
| | |
| | | |
| | | return result.ToString(); |
| | | } |
| | | #region å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | public WebResponseContent CompleteInboundTask(Dt_Task task) |
| | | #endregion |
| | | |
| | | #region ä¿®æ¹æ¬å°è®¡ç®æºæ¶é´ |
| | | // å®ä¹ System ç»æä½ |
| | | [StructLayout(LayoutKind.Sequential)] |
| | | public struct SYSTEMTIME |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | locationInf.LocationStatus = (int)LocationEnum.InStock; |
| | | var stock = new DtStockInfo() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | LocationCode = task.TargetAddress, |
| | | CreateDate = DateTime.Now, |
| | | Creater = "system", |
| | | LocationId = locationInf.Id, |
| | | }; |
| | | _stockInfoRepository.AddData(stock); |
| | | _locationRepository.UpdateData(locationInf); |
| | | TaskMoveHty(task); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | public ushort Year; |
| | | public ushort Month; |
| | | public ushort DayOfWeek; |
| | | public ushort Day; |
| | | public ushort Hour; |
| | | public ushort Minute; |
| | | public ushort Second; |
| | | public ushort Milliseconds; |
| | | } |
| | | |
| | | public WebResponseContent CompleteOutboundTask(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | locationInf.LocationStatus = (int)LocationEnum.Free; |
| | | var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode); |
| | | |
| | | DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>(); |
| | | stockInfo_Hty.ModifyDate = DateTime.Now; |
| | | |
| | | AddStockInfoHty(stockInfo_Hty); |
| | | |
| | | _stockInfoRepository.DeleteData(stock); |
| | | _locationRepository.UpdateData(locationInf); |
| | | |
| | | TaskMoveHty(task); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent CompleteRelocationboundTask(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); |
| | | locationInf.LocationStatus = (int)LocationEnum.InStock; |
| | | location.LocationStatus = (int)LocationEnum.Free; |
| | | |
| | | var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode); |
| | | |
| | | stock.LocationCode = locationInf.LocationCode; |
| | | stock.LocationId = locationInf.Id; |
| | | |
| | | |
| | | _stockInfoRepository.UpdateData(stock); |
| | | _locationRepository.UpdateData(locationInf); |
| | | _locationRepository.UpdateData(location); |
| | | TaskMoveHty(task); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent TaskMoveHty(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | var taskHtyNG = CreateHistoricalTask(task); |
| | | var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0; |
| | | var isTaskDelete = Delete(task.TaskId); |
| | | var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum).First(); |
| | | if (AgvTask != null) |
| | | { |
| | | SqlSugarHelper.DbAGV.Deleteable(AgvTask).ExecuteCommand(); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | #region private å
鍿¹æ³ |
| | | |
| | | /// <summary> |
| | | /// å建åå²ä»»å¡è®°å½ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public Dt_Task_Hty CreateHistoricalTask(Dt_Task task, bool isHand = false) |
| | | { |
| | | task.CurrentAddress = task.NextAddress; |
| | | |
| | | // å建åå²ä»»å¡ |
| | | var taskHty = _mapper.Map<Dt_Task_Hty>(task); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.TaskId = 0; |
| | | taskHty.OperateType = isHand ? (int)OperateTypeEnum.人工å é¤ : App.User.UserName != null ? (int)OperateTypeEnum.äººå·¥å®æ : (int)OperateTypeEnum.èªå¨å®æ; |
| | | taskHty.SourceId = task.TaskId; |
| | | if (isHand) |
| | | { |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | } |
| | | return taskHty; |
| | | } |
| | | /// <summary> |
| | | /// å é¤ä¸ä¸ªä»»å¡ |
| | | /// </summary> |
| | | /// <param name="id">ä»»å¡ID</param> |
| | | /// <returns>æ¯å¦å 餿å</returns> |
| | | public bool Delete(int id) |
| | | { |
| | | return BaseDal.Delete(id); |
| | | } |
| | | private void AddStockInfoHty(DtStockInfo_Hty dtStock) |
| | | { |
| | | var isStockAdd = SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommand(); |
| | | if (!isStockAdd) |
| | | { |
| | | throw new Exception("åºååå²ä¿¡æ¯æ·»å 失败"); |
| | | } |
| | | } |
| | | |
| | | #endregion private å
鍿¹æ³ |
| | | // 导å
¥ SetLocalTime 彿° |
| | | [DllImport("kernel32.dll", SetLastError = true)] |
| | | public static extern bool SetLocalTime(ref SYSTEMTIME st); |
| | | #endregion |
| | | } |
| | | } |