1
huanghongfeng
2025-10-22 0cbe01e1241f9af562d86dc79b5f0949ada81dba
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NetTaste;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using System.Net;
using WIDESEAWCS_ISystemServices;
 
namespace WIDESEAWCS_TaskInfoService
{
    public class RgvOperationService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvOperationService
    {
        private readonly IAgvStationService _gvStationService;
        public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService) : base(BaseDal)
        {
            _gvStationService = agvStationService;
        }
 
 
        public WebResponseContent WriteInitialization(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
 
            string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
            //获取实例
            DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand");        //任务类型
            //第一步写入任务
            RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3);
 
            //复位报警
            DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //复位报警信息
            RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
 
            //写入自动
            DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        //任务id
            RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)1);
 
            //写入清除任务
            RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)4);
 
            //反馈确认任务
            DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete");        //任务id
            RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)1);
 
            return webResponse.OK();
        }
 
        public WebResponseContent WriteRGVmokuai(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            string DeviceName = saveModel.DelKeys[0].ToString();    //工作类型
            string DBType = saveModel.DelKeys[1].ToString();    //设备名称
            short WriteRGVvalue = short.Parse(saveModel.DelKeys[2].ToString());    //写入值
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            switch (DBType)
            {
                case "1":  // 工作模式(0手动、1自动)
                           //获取实例
                    DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        //任务类型
                      //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, WriteRGVvalue);
                    break;
                case "2":   //复位操作(0不复位、1复位)
                    DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //任务类型
                                                                                                                                                //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, WriteRGVvalue);
                    break;
                case "3":   //任务确认完成(0不确定,1确定)
                    DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete");        //任务类型
                                                                                                                                                //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, WriteRGVvalue);
                    break;
                case "4":   //任务类型(4清除)
                    DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand");        //任务类型
                                                                                                                                                //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, WriteRGVvalue);
                    break;
            }
            return webResponse.OK();
        }
 
        /// <summary>
        /// 手动移动RGV
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent ManualmovementRGV(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
 
            string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
            short Nextaddres = short.Parse(saveModel.DelKeys[1].ToString());
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
            //获取实例
            DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand");        //任务类型
            //第一步写入任务
            RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3);
 
            //目标位置
            DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVTasklocationt", "DeviceCommand");        //复位报警信息
            RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)Nextaddres);
 
            //写入自动
            DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Rgvtaskidt", "DeviceCommand");        //任务id
            //任务id
            RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)30001);
 
            //任务id
            DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Lanjiantaskidt", "DeviceCommand");        //任务id
            RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)30001);
 
 
            return webResponse.OK();
        }
 
        /// <summary>
        /// 写入复位(入库端)
        /// </summary>
        public WebResponseContent WriteInReset(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
 
            List<AGVStation> rgvdata = _gvStationService.GetInStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //复位报警信息
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
            }
            return webResponse.OK();
        }
 
        /// <summary>
        /// 写入复位(出库端)
        /// </summary>
        public WebResponseContent WriteOutReset(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //复位报警信息
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
            }
            return webResponse.OK();
        }
 
 
 
        /// <summary>
        /// 查询RGV设备
        /// </summary>
        /// <param name="Commonstacker"></param>
        /// <param name="SCAddress"></param>
        /// <param name="Interactivet"></param>
        /// <returns></returns>
        public static DeviceProDTO? GetRGVDeviceProDTO(SpeStackerCrane Commonstacker, string SCAddress, string DeviceProParamName, string DeviceProParamType)
        {
            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
        }
        /// <summary>
        /// 读取设备信息
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public static int GetLine(CommonConveyorLine Commonstacker, string DeviceProDataBlock)
        {
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
 
        /// <summary>
        /// 写入设备信息
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public static bool RgvSetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock, short rgvvalues)
        {
            return Commonstacker.Communicator.Write<short>(DeviceProDataBlock, rgvvalues);
        }
 
 
 
    }
}