dengjunjie
2025-03-19 8abc9481eafeb715b39a4f4f8d6f628a642e6b53
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
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_DTO.AGVInfo;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob.ConveyorLineExtend;
using WIDESEAWCS_Tasks.ProductionLineJob;
 
namespace WIDESEAWCS_Tasks
{
    public partial class AGVsignal
    {
        /// <summary>
        /// AGV与输送线交互
        /// </summary>
        /// <param name="conveyor"></param>
        /// <returns></returns>
        public static WebResponseContent AGVRequestin(ConveyorLineDTO conveyor)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (conveyor == null) throw new Exception("请求数据为空");
                if (string.IsNullOrEmpty(conveyor.Station)) throw new Exception("站点编号为空");
                switch (conveyor.Station)
                {
                    case "1001":
                    case "1008":
                        content = AGVRequestinConveyorLine(conveyor);
                        break;
                    case "MDX01":
                        content = AGVRequestinProductionLine(conveyor);
                        break;
                    default: throw new Exception($"未定义站台号[Station:{conveyor.Station}]");
                }
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
 
        /// <summary>
        /// AGV和输送线交互
        /// </summary>
        /// <returns></returns>
        public static WebResponseContent AGVRequestinConveyorLine(ConveyorLineDTO conveyor)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceName == "输送线") as CommonConveyorLine;
                if (conveyorLine == null) throw new Exception("未找到输送线设备信息");
                if (!conveyorLine.IsConnected) throw new Exception($"输送线设备通讯异常");
                //conveyorLine.SetValue(ConveyorLine_AGV.WriteRGPutComplete, true, "1001");//人工放货完成
                switch (conveyor.Type)
                {
                    case 1:
                        {
                            if (conveyor.Station == "1001")
                            {
                                content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestPut, true, conveyor.Station);
                                if (content.Status) content.Status = conveyorLine.GetValue<ConveyorLine_AGV, bool>(ConveyorLine_AGV.ConveyorLinePermitPut, conveyor.Station);
                            }
                            else
                            {
                                content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestTake, true, conveyor.Station);
                                if (content.Status) content.Status = conveyorLine.GetValue<ConveyorLine_AGV, bool>(ConveyorLine_AGV.ConveyorLinePermitTake, conveyor.Station);
                            }
                        }
                        break;
                    case 2:
                        {
                            if (conveyor.Station == "1001")
                            {
                                content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVPutComplete, true, conveyor.Station);
                                if (content.Status)
                                {
                                    Thread.Sleep(1000);
                                    conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestPut, false, conveyor.Station);
                                    conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVPutComplete, false, conveyor.Station);
                                }
                            }
                            else
                            {
                                content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVTakeComplete, true, conveyor.Station);
                                if (content.Status)
                                {
                                    Thread.Sleep(1000);
                                    conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestTake, false, conveyor.Station);
                                    conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVTakeComplete, false, conveyor.Station);
                                }
                            }
                        }
                        break;
                    case 3:
 
                        break;
                    case 4:
 
                        break;
                    default: throw new Exception($"类型有误[Type:{conveyor.Type}]");
                }
                content = content.Status ? content.OK() : content.Error();
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// AGV和产线交互
        /// </summary>
        /// <returns></returns>
        public static WebResponseContent AGVRequestinProductionLine(ConveyorLineDTO conveyor)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                OtherDevice? ProductionLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == conveyor.Station) as OtherDevice;
                if (ProductionLine == null) throw new Exception("未找到产线设备信息");
                if (!ProductionLine.IsConnected) throw new Exception($"产线设备通讯异常");
                content.Status = ProductionLine.SetValue(ProductionLineDBName.WagvState, conveyor.Type);
                if (!content.Status) throw new Exception("写入AGV信号失败");
                var agvState = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.agvState);
                if (agvState == 3) throw new Exception("产线设备异常");
                switch (conveyor.Type)
                {
                    case 1:
                        if (agvState != conveyor.Type) throw new Exception("产线不允许进入作业");
                        break;
                    case 2:
                        if (agvState != conveyor.Type) throw new Exception("产线不允许离开");
                        break;
                    case 3:
                        content.Status = ProductionLine.SetValue(ProductionLineDBName.Wrequest, 2);
                        if (content.Status) content.Status = ProductionLine.SetValue(ProductionLineDBName.WagvState, 0);
                        break;
                }
                content = content.Status ? content.OK() : content.Error("写入失败");
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}