huanghongfeng
7 天以前 8c8a68df710d568f5f2b358c1e8c4b4799547d0b
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob;
using WIDESEA_Common.Log;
using System.Xml.Linq;
using SixLabors.ImageSharp;
using WIDESEAWCS_QuartzJob.Service;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 
namespace WIDESEAWCS_Tasks.StackerCraneJob
{
    
 
    public class GetDeviceAddress
    {
        /// <summary>
        /// 传入设备,获取当前位置位置
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static int GetEquipmentlocation(string ChildPosiDeviceCode)   
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null) return 0;
            DeviceProDTO? deviceProDTO = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
            int MCGStatus = GetDeviceAddress.RGVGetLine(speStackerCrane, deviceProDTO.DeviceProAddress);
            return MCGStatus;
        }
 
        /// <summary>
        /// 传入设备,返回设备信息
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static GetStackerObject GetChildDeviceCode(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null)
            {
                Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},002");
                return null;
            }
            GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
            return getStackerObject;
        }
 
 
        /// <summary>
        /// 传入设备,返回当前设备信息
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static int GetEquipmentInformation(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null)
            {
                Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},003");
                return 0;
            }
            GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
            if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
                        getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
            {
                return getStackerObject.RGVCurrentlocation;
            }
            else
            {
                return 0;
            }
                
        }
 
        /// <summary>
        /// 传入设备,返回当前设备信息(入库母车,需要加入是否有货判断)
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static int GetEquipmentInMuche(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null)
            {
                Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},004");
                return 0;
            }
            GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
            if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
                        getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
            {
                return getStackerObject.RGVCurrentlocation;
            }
            else
            {
                return 0;
            }
 
        }
 
 
        /// <summary>
        /// 传入设备编号,判断设备状态是否可进入
        /// </summary>
        /// <param name="ChildPosiDeviceCode"></param>
        /// <returns></returns>
        public static bool ReturnCurrentStatus(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null)
            {
                Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},005");
                return false;
            }
            GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
            if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
                        getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
 
        /// <summary>
        /// 查询HCJ站台设备
        /// </summary>
        /// <param name="Commonstacker"></param>
        /// <param name="SCAddress"></param>
        /// <param name="Interactivet"></param>
        /// <returns></returns>
        public static DeviceProDTO? GetDeviceProDTO(CommonConveyorLine Commonstacker, string SCAddress, string Interactivet)
        {
            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet && x.DeviceProParamType == "ReadDeviceCommand");
        }
 
        /// <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 Interactivet)
        {
            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet && x.DeviceProParamType == "RGV_Rgvtaskstutas");
        }
        /// <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);
        }
 
        public static int RGVGetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
        {
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
 
 
        /// <summary>
        /// 日志记录
        /// </summary>
        /// <param name="SCLLinStack">设备名称</param>
        /// <param name="Filename">文件名称</param>
        /// <param name="Logtype">日志类型</param>
        /// <param name="Magessadd">内容</param>
        public void wcsWriteLog(string SCLLinStack,string Filename, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log(SCLLinStack, Filename, Logtype, new { 信息 = Magessadd });
        }
 
        /// <summary>
        /// 传入站台编号,判断是否有货
        /// </summary>
        /// <param name="Platformnumber">站台编号</param>
        public static bool HCJIsstock(string Platformnumber)
        {
            //获取需要区分是否去入库与去不合格载货台任务
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
            CommonConveyorLine Commonstacker = (CommonConveyorLine)device;
            DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, Platformnumber.ToString(), "HCJ_GoodsStatus");
            int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
            if (HCJGStatus == 0)    //为无货
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        /// <summary>
        /// 判断设备是否有货
        /// </summary>
        public static bool Mucheywhaddres(string DeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
            DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceCode && x.DeviceProParamName == "RgvEquipmentStatus" && x.DeviceProParamType == "RgvEquipmentStatus");
            int MCGStatus = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
            if(MCGStatus== (int)RgvEquipmentStatus.NoCargo)
            {
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 判断3个站台
        /// </summary>
        public static bool AQMStatus(List<AGVStation> aGVStatList)
        {
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
                CommonConveyorLine Commonstacker = (CommonConveyorLine)device;
                foreach (var item in aGVStatList)
                {
                    DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, item.Station_code.ToString(), "HCJ_GoodsStatus");
                    int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                    if (HCJGStatus != 0)    //为无货
                    {
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
                throw;
            }
            
        }
 
        public static List<string> StationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115","RGV118" };
        public static List<string> InStationareaList = new List<string>() { "RGV101", "RGV103", "RGV105", "RGV108", "RGV109", "RGV104","RGV107" };
 
        public static bool OutbounMotherChildCartbool(string DeviceChildCode)
        {
            if (StationareaList.Contains(DeviceChildCode))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        public static bool OutbounMotherChildCartbool2(string DeviceChildCode)
        {
            if (DeviceChildCode=="RGV104" || DeviceChildCode == "RGV107")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        /// <summary>
        /// 读取子是否为手动
        /// </summary>
        public static bool OutRGVStatice()
        {
            bool rgvbool=true;
            foreach (string AGVStation in StationareaList)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
                if (device == null)  continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RgvCraneAutoStatus" && x.DeviceProParamType == "RgvCraneAutoStatus");
                int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (RGVState == 1)
                {
                   return false;
                }
            }
            return rgvbool;
        }
 
        public static bool InRGVStatice()
        {
            bool rgvbool = true;
            foreach (string AGVStation in InStationareaList)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
                if (device == null)  continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RgvCraneAutoStatus" && x.DeviceProParamType == "RgvCraneAutoStatus");
                int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (RGVState == 1)
                {
                    return false;
                }
            }
            return rgvbool;
        }
 
        /// <summary>
        /// 出库,读取RGV是否为空闲
        /// </summary>
        /// <returns></returns>
        public static bool OutRGVRGVStepprocess()
        {
            bool rgvbool = true;
            foreach (string AGVStation in StationareaList)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
                if (device == null)  continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RGVStepprocess" && x.DeviceProParamType == "RGVStepprocess");
                int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (RGVState != 0)
                {
                   return false;
                }
            }
            return rgvbool;
        }
 
        public static bool InRGVRGVStepprocess()
        {
            bool rgvbool = true;
            foreach (string AGVStation in InStationareaList)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == AGVStation);
                if (device == null)  continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == AGVStation && x.DeviceProParamName == "RGVStepprocess" && x.DeviceProParamType == "RGVStepprocess");
                int RGVState = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (RGVState != 0)
                {
                   return false;
                }
            }
            return rgvbool;
        }
 
        public static bool WriteSecurityDoorpolice(string DeviceCode,string WriteType,int Writevalue)
        {
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
                if (device == null) return false;
                CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                DeviceProDTO? deviceProDTO = commonConveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceCode && x.DeviceProParamName == WriteType && x.DeviceProParamType == "DeviceCommand");
                return commonConveyorLine.Communicator.Write<short>(deviceProDTO.DeviceProAddress, (short)Writevalue);
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }
 
 
        public static List<string> AQMListdata = new List<string>() { "AQM001", "AQM002"};
        /// <summary>
        /// 判断安全门状态
        /// </summary>
        /// <param name="aqmtype">1为出库安全门3号,2为入库安全门判断</param>
        /// <returns></returns>
        public static bool ReadAqmDecicStice(int aqmtype)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
            CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
            if (aqmtype == 1)
            {
                DeviceProDTO? deviceProDTO = commonConveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == "AQM003" && x.DeviceProParamName == "IndicatorStatus" && x.DeviceProParamType == "ReadDeviceCommand");
                short AQMldeng = commonConveyorLine.Communicator.Read<short>(deviceProDTO.DeviceProDataBlock);
                if (AQMldeng == 2) return false;
            }
            else
            {
                foreach (string aqmname in AQMListdata)
                {
                    DeviceProDTO? deviceProDTO = commonConveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == aqmname && x.DeviceProParamName == "IndicatorStatus" && x.DeviceProParamType == "ReadDeviceCommand");
                    short AQMldeng = commonConveyorLine.Communicator.Read<short>(deviceProDTO.DeviceProDataBlock);
                    if (AQMldeng == 2) return false;
                }
            }
            return true;
        }
 
 
    }
}