| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.StationEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_DTO.PDA; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_ISystemServices; |
| | |
| | | } |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | string ip = "127.0.0.1"; |
| | | int port = 502; |
| | | string Region = "ååºæ¿1"; |
| | | ModbusTcp modbusTcp = new ModbusTcp(ip, port, Region); |
| | | Baseconversion baseconversion = new Baseconversion(); |
| | | modbusTcp.Connect(); |
| | | |
| | | Dictionary<int, int> Signal = new Dictionary<int, int>() { [10] = 2, [30] = 3, [50] = 4, [70] = 5 }; |
| | | Dictionary<int, int> FeedingPoint = new Dictionary<int, int>() { [10] = 2001, [30] = 2002, [50] = 2003, [70] = 2004 }; // 嫿çç¹ä½ ç»ç¹ä½ç½® |
| | | |
| | | try |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (flag && value != null) |
| | | { |
| | | for (int i = 10; i < 90; i += 20) |
| | | OtherDevice device = (OtherDevice)value; |
| | | if (!device.IsConnected) |
| | | { |
| | | byte[] SignalNumber = modbusTcp.Read(Signal[i].ToString(), 1); // ä¿¡å· 1ï¼å«æ 2ï¼æåºç©ºæ¡ |
| | | return Task.CompletedTask; |
| | | } |
| | | //string ip = "127.0.0.1"; |
| | | //int port = 502; |
| | | //string Region = "ååºæ¿1"; |
| | | //ModbusTcp modbusTcp = new ModbusTcp(ip, port, Region); |
| | | //modbusTcp.Connect(); |
| | | Baseconversion baseconversion = new Baseconversion(); |
| | | Dictionary<int, int> Signal = new Dictionary<int, int>() { [10] = 2, [30] = 3, [50] = 4, [70] = 5 }; |
| | | Dictionary<int, int> FeedingPoint = new Dictionary<int, int>() { [10] = 2001, [30] = 2002, [50] = 2003, [70] = 2004 }; // 嫿çç¹ä½ ç»ç¹ä½ç½® |
| | | |
| | | if (SignalNumber[1] == 1) |
| | | try |
| | | { |
| | | for (int i = 10; i < 90; i += 20) |
| | | { |
| | | byte[] PartNumber = modbusTcp.Read(i.ToString(), 20); // 读åé¶ä»¶å· |
| | | byte[] SignalNumber = device.Communicator.Read(Signal[i].ToString(), 1); // ä¿¡å· 1ï¼å«æ 2ï¼æåºç©ºæ¡ |
| | | |
| | | if (PartNumber[1] == 0) continue; |
| | | |
| | | string Ku1_Value = baseconversion.TenthTurn16(PartNumber); |
| | | if (Ku1_Value != "" && Ku1_Value != null) |
| | | Dt_StationManager dt_StationManager = _stationManagerRepository.QueryFirst( |
| | | x => x.StationLocation == FeedingPoint[i].ToString() |
| | | && x.StationStatus != ((int)StationEnum.Disable).ToString()); |
| | | if (dt_StationManager == null) |
| | | { |
| | | // çåè½æµè¯å®ï¼è¿éè¦åæ¥å¿è®°å½ |
| | | |
| | | Console.WriteLine(Ku1_Value); |
| | | // æ¾å¯¹åºçé¶ä»¶å·æ¯å¦å·²ç»ç»å®(ç»ç) |
| | | Dt_MaterialInfo dt_MaterialInfo = _IDt_MaterialInfoRepository.QueryFirst(x => x.MaterialName == Ku1_Value); |
| | | |
| | | if (dt_MaterialInfo != null && dt_MaterialInfo.IsBind && dt_MaterialInfo.EndPosition == null) |
| | | { |
| | | Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.PalletCode == dt_MaterialInfo.ContainerCode); |
| | | if (dt_Task != null) continue; //è¯ææå½åä»»å¡ |
| | | |
| | | dt_Task = new Dt_Task(); |
| | | dt_Task.PalletCode = dt_MaterialInfo.ContainerCode; |
| | | dt_Task.SourceAddress = dt_MaterialInfo.Position; // å½åä½ç½® |
| | | dt_Task.TargetAddress = FeedingPoint[i].ToString(); // ç»ç¹ä½ç½® |
| | | dt_Task.Grade = 2; |
| | | dt_Task.TaskState = TaskAGVCarryStatusEnum.AGV_CarryNew.ObjToInt(); |
| | | dt_Task.TaskType = TaskAGVCarryTypeEnum.Carry.ObjToInt(); |
| | | dt_Task.Roadway = (Signal[i] - 1).ToString(); // åº1 嫿é£å°±æ¯1å··é |
| | | dt_Task.CurrentAddress = dt_MaterialInfo.Position; // å½åä½ç½® |
| | | dt_Task.NextAddress = FeedingPoint[i].ToString(); // ç»ç¹ä½ç½® |
| | | |
| | | dt_MaterialInfo.EndPosition = FeedingPoint[i].ToString(); // ç»ç¹ä½ç½® |
| | | |
| | | _taskRepository.AddData(dt_Task); |
| | | _IDt_MaterialInfoRepository.UpdateData(dt_MaterialInfo); |
| | | } |
| | | |
| | | // å¦ææ²¡ç»å®åä¸çæä»»å¡ å¦ææ¥æ¾å°å¯¹åºçé¶ä»¶å·ç»å®äº åçæä¸æ¡ä»»å¡æ°æ® |
| | | // è¿éåºè¯¥è¦å æ¥å¿ è®°å½æ¾ä¸å°ç«å°çä¿¡æ¯ |
| | | Console.WriteLine($"{DateTime.Now} å½åç«å°ã{FeedingPoint[i].ToString()} æªé
ç½®æå·²ç¦ç¨ã"); |
| | | continue; |
| | | } |
| | | |
| | | if (SignalNumber[1] == 1) |
| | | { |
| | | byte[] PartNumber = device.Communicator.Read(i.ToString(), 20); // 读åé¶ä»¶å· |
| | | |
| | | string Ku1_Value = baseconversion.TenthTurn16(PartNumber); |
| | | if (Ku1_Value != "" && Ku1_Value != null) |
| | | { |
| | | // çåè½æµè¯å®ï¼è¿éè¦åæ¥å¿è®°å½ |
| | | |
| | | Console.WriteLine(Ku1_Value); |
| | | // æ¾å¯¹åºçé¶ä»¶å·æ¯å¦å·²ç»ç»å®(ç»ç) // è¿éè¦æ¹è¦å åºå å æ¯å¦å·²çæä»»å¡ è¿è¦æ ¹æ®æ¶é´æåº å
ç»å®çå
åè¿å» |
| | | Dt_MaterialInfo? dt_MaterialInfo = _IDt_MaterialInfoRepository.QueryData(x => x.MaterialName == Ku1_Value |
| | | && x.Region == ((int)StationEnum.Rearbaseplate1).ToString() |
| | | && (x.EndPosition == null || x.EndPosition == "")).OrderBy(x => x.CreateDate).FirstOrDefault(); |
| | | |
| | | if (dt_MaterialInfo != null) |
| | | { |
| | | Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.PalletCode == dt_MaterialInfo.ContainerCode); |
| | | if (dt_Task != null) continue; //è¯ææå½åä»»å¡ |
| | | |
| | | dt_Task = new Dt_Task(); |
| | | dt_Task.PalletCode = dt_MaterialInfo.ContainerCode; |
| | | dt_Task.SourceAddress = dt_MaterialInfo.Position; // å½åä½ç½® |
| | | dt_Task.TargetAddress = FeedingPoint[i].ToString(); // ç»ç¹ä½ç½® |
| | | dt_Task.Grade = 2; |
| | | dt_Task.TaskState = TaskAGVCarryStatusEnum.AGV_CarryNew.ObjToInt(); |
| | | dt_Task.TaskType = TaskAGVCarryTypeEnum.Carry.ObjToInt(); |
| | | dt_Task.Roadway = (Signal[i] - 1).ToString(); // åº1 嫿é£å°±æ¯1å··é |
| | | dt_Task.CurrentAddress = dt_MaterialInfo.Position; // å½åä½ç½® |
| | | dt_Task.NextAddress = FeedingPoint[i].ToString(); // ç»ç¹ä½ç½® |
| | | |
| | | dt_MaterialInfo.EndPosition = FeedingPoint[i].ToString(); // ç»ç¹ä½ç½® |
| | | |
| | | dt_StationManager.StationStatus = ((int)StationEnum.Thereisatask).ToString(); |
| | | dt_StationManager.StationRemark = dt_MaterialInfo.ContainerCode; |
| | | _stationManagerRepository.UpdateData(dt_StationManager); |
| | | |
| | | |
| | | _taskRepository.AddData(dt_Task); |
| | | _IDt_MaterialInfoRepository.UpdateData(dt_MaterialInfo); |
| | | } |
| | | |
| | | // å¦ææ²¡ç»å®åä¸çæä»»å¡ å¦ææ¥æ¾å°å¯¹åºçé¶ä»¶å·ç»å®äº åçæä¸æ¡ä»»å¡æ°æ® |
| | | } |
| | | } |
| | | |
| | | if (SignalNumber[1] == 2) // 表示æåºç©ºæ¡ |
| | | { |
| | | Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.SourceAddress == FeedingPoint[i].ToString() && x.TaskType == (int)TaskAGVCarryTypeEnum.CarryEmpty); |
| | | if (dt_Task != null) continue; |
| | | |
| | | Dt_StationManager RecyclingpointStation = _stationManagerRepository.QueryFirst(x => |
| | | x.StationStatus == ((int)StationEnum.Enable).ToString() |
| | | && x.StationArea == ((int)StationEnum.Rearbaseplate1).ToString() |
| | | && x.Remark == "åæ¶ç¹"); |
| | | |
| | | if (RecyclingpointStation == null) |
| | | { |
| | | // è®°å½é误æ¥å¿ |
| | | continue; |
| | | } |
| | | dt_Task = new Dt_Task(); |
| | | dt_Task.PalletCode = dt_StationManager.StationRemark; |
| | | dt_Task.SourceAddress = FeedingPoint[i].ToString(); |
| | | dt_Task.TargetAddress = RecyclingpointStation.StationLocation; |
| | | dt_Task.Grade = 2; |
| | | dt_Task.TaskState = TaskAGVCarryStatusEnum.AGV_CarryNew.ObjToInt(); |
| | | dt_Task.TaskType = TaskAGVCarryTypeEnum.CarryEmpty.ObjToInt(); |
| | | dt_Task.Roadway = (Signal[i] - 1).ToString(); // åº1 嫿é£å°±æ¯1å··é |
| | | dt_Task.CurrentAddress = FeedingPoint[i].ToString(); // å½åä½ç½® |
| | | dt_Task.NextAddress = RecyclingpointStation.StationLocation;// ç»ç¹ä½ç½® |
| | | |
| | | RecyclingpointStation.StationStatus = ((int)StationEnum.Thereisatask).ToString(); |
| | | |
| | | _stationManagerRepository.UpdateData(RecyclingpointStation); |
| | | _taskRepository.AddData(dt_Task); |
| | | } |
| | | |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | if (SignalNumber[1] == 2) // 表示æåºç©ºæ¡ |
| | | { |
| | | Dictionary<int, int> Endpointposition = new Dictionary<int, int>() { [10] = 3001, [20] = 3002, [30] = 3003, [40] = 3004 }; // 嫿çç¹ä½ ç»ç¹ä½ç½® |
| | | Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.SourceAddress == FeedingPoint[i].ToString() && x.TaskType == (int)TaskAGVCarryTypeEnum.CarryEmpty); |
| | | if (dt_Task != null) continue; |
| | | |
| | | dt_Task = new Dt_Task(); |
| | | dt_Task.PalletCode = "空æ¡å"; |
| | | dt_Task.SourceAddress = FeedingPoint[i].ToString(); |
| | | dt_Task.TargetAddress = Endpointposition[i].ToString(); |
| | | dt_Task.Grade = 2; |
| | | dt_Task.TaskState = TaskAGVCarryStatusEnum.AGV_CarryNew.ObjToInt(); |
| | | dt_Task.TaskType = TaskAGVCarryTypeEnum.CarryEmpty.ObjToInt(); |
| | | dt_Task.Roadway = (Signal[i] - 1).ToString(); // åº1 嫿é£å°±æ¯1å··é |
| | | dt_Task.CurrentAddress = FeedingPoint[i].ToString(); // å½åä½ç½® |
| | | dt_Task.NextAddress = Endpointposition[i].ToString(); // ç»ç¹ä½ç½® |
| | | _taskRepository.AddData(dt_Task); |
| | | } |
| | | |
| | | throw; |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | |
| | | // 16è¿å¶è½¬æ10è¿å¶ |
| | | // 2. 16è¿å¶ â 转ååè¿å¶ï¼ä½ è¦çåè½ï¼ |
| | | ulong decimalResult = Convert.ToUInt64("123", 16); |
| | | Console.WriteLine("16è¿å¶è½¬ååè¿å¶ï¼" + decimalResult); |
| | | //ulong decimalResult = Convert.ToUInt64("123", 16); |
| | | //Console.WriteLine("16è¿å¶è½¬ååè¿å¶ï¼" + decimalResult); |
| | | |
| | | // åå
¥ |
| | | bool flag = modbusTcp.Write("30", decimalResult.ToString()); |
| | | //// åå
¥ |
| | | //bool flag2 = modbusTcp.Write("30", decimalResult.ToString()); |
| | | |
| | | modbusTcp.Disconnect(); |
| | | Console.WriteLine("è¿å
¥äºTaskAcquisition_Back1_Job"); |
| | | //modbusTcp.Disconnect(); |
| | | //Console.WriteLine("è¿å
¥äºTaskAcquisition_Back1_Job"); |
| | | return Task.CompletedTask; |
| | | } |
| | | } |