| | |
| | | using Quartz; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using Quartz; |
| | | using SixLabors.ImageSharp; |
| | | using SqlSugar.Extensions; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_ISystemServices; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_Tasks.TaskAcquisition; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | |
| | | private readonly ITaskService _taskService; |
| | | private readonly ISys_ConfigService _sys_ConfigService; |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | public TaskAcquisition_Back1_Job(ITaskRepository taskRepository, ITaskService taskService, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository) |
| | | private readonly IDt_MaterialInfoRepository _IDt_MaterialInfoRepository; |
| | | public TaskAcquisition_Back1_Job(ITaskRepository taskRepository, ITaskService taskService, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository, IDt_MaterialInfoRepository IDt_MaterialInfoRepository) |
| | | { |
| | | _taskRepository = taskRepository; |
| | | _taskService = taskService; |
| | | _sys_ConfigService = configService; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _IDt_MaterialInfoRepository = IDt_MaterialInfoRepository; |
| | | } |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | string ip = "127.0.0.1"; |
| | | int port = 502; |
| | | string name = "ååºæ¿1"; |
| | | ModbusTcp modbusTcp = new ModbusTcp(ip, port, name); |
| | | string Region = "ååºæ¿1"; |
| | | ModbusTcp modbusTcp = new ModbusTcp(ip, port, Region); |
| | | Baseconversion baseconversion = new Baseconversion(); |
| | | modbusTcp.Connect(); |
| | | //var a = modbusTcp.Read("40002", 20); |
| | | //string barcode = Encoding.UTF8.GetString(a).Replace("\0", "").Replace("\\0", ""); |
| | | |
| | | // 读åæå®çå°å读å°10è¿å¶çasciiç 转æ16è¿å¶ |
| | | byte[] rawBytes = modbusTcp.Read("10", 20); |
| | | string originalDecimalStr = Encoding.ASCII.GetString(rawBytes).TrimEnd('\0'); |
| | | Console.WriteLine($"读åå°çåå§åè¿å¶å符串ï¼{originalDecimalStr}"); |
| | | // ä¸é¢è¿ä¸æ®µå°±æ¯ä½ è¦çï¼è½¬ 16 è¿å¶ |
| | | ulong number = ulong.Parse(originalDecimalStr); // è½¬ææ°å |
| | | string hexStr = number.ToString("X"); // 转大å16è¿å¶ |
| | | Console.WriteLine("è½¬æ¢æ16è¿å¶ï¼" + hexStr); |
| | | 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 |
| | | { |
| | | for (int i = 10; i < 90; i += 20) |
| | | { |
| | | byte[] SignalNumber = modbusTcp.Read(Signal[i].ToString(), 1); // ä¿¡å· 1ï¼å«æ 2ï¼æåºç©ºæ¡ |
| | | |
| | | if (SignalNumber[1] == 1) |
| | | { |
| | | byte[] PartNumber = modbusTcp.Read(i.ToString(), 20); // 读åé¶ä»¶å· |
| | | |
| | | if (PartNumber[1] == 0) continue; |
| | | |
| | | string Ku1_Value = baseconversion.TenthTurn16(PartNumber); |
| | | if (Ku1_Value != "" && Ku1_Value != 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); |
| | | } |
| | | |
| | | // å¦ææ²¡ç»å®åä¸çæä»»å¡ å¦ææ¥æ¾å°å¯¹åºçé¶ä»¶å·ç»å®äº åçæä¸æ¡ä»»å¡æ°æ® |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | |
| | | // 16è¿å¶è½¬æ10è¿å¶ |
| | | // 2. 16è¿å¶ â 转ååè¿å¶ï¼ä½ è¦çåè½ï¼ |
| | | ulong decimalResult = Convert.ToUInt64(hexStr, 16); |
| | | ulong decimalResult = Convert.ToUInt64("123", 16); |
| | | Console.WriteLine("16è¿å¶è½¬ååè¿å¶ï¼" + decimalResult); |
| | | |
| | | // åå
¥ |
| | | bool flag = modbusTcp.Write("30", decimalResult.ToString()); |
| | | |
| | | modbusTcp.Disconnect(); |