xiaojiao
4 天以前 5ce21dbcd0849adc3afcf28fffc8933ce717c380
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
{
    /// <summary>
    /// 任务获取 后底板1 的任务
    /// </summary>
    /// 
    [DisallowConcurrentExecution]
    public class TaskAcquisition_Back1_Job : JobBase, IJob
    {
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskService _taskService;
        private readonly ISys_ConfigService _sys_ConfigService;
        private readonly 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 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
            {
                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("123", 16);
            Console.WriteLine("16进制转回十进制:" + decimalResult);
 
            // 写入
            bool flag = modbusTcp.Write("30", decimalResult.ToString());
 
            modbusTcp.Disconnect();
            Console.WriteLine("进入了TaskAcquisition_Back1_Job");
            return Task.CompletedTask;
        }
    }
}