wankeda
2025-05-26 0864509e1eb593c3dedb66196ec19fe51437922b
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
using Quartz;
using System.Text.RegularExpressions;
using WIDESEAWCS_QuartzJob;
 
namespace WIDESEAWCS_Tasks
{
    internal class CommonRoastZJob : JobBase, IJob, IDisposable
    {
        public CommonRoastZJob()
        {
        }
 
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                // 从上下文中获取 JobParams 并转换为 Roast 类型
                CommonRoastZ roast = (CommonRoastZ)context.JobDetail.JobDataMap.Get("JobParams");
                // 初始化 AGV 变量
                AGV agv = null;
 
                if (roast == null)
                {
                    throw new Exception("未找到烘烤设备参数。");
                }
 
                // 根据设备名称决定是正极还是负极 AGV
                string devicePrefix = roast.DeviceCode.Contains("FJ") ? "负极" : "正极";
                string agvName = $"{devicePrefix}AGV";
 
                // 从存储中查找指定名称的设备
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceName == agvName);
                if (device != null)
                {
                    agv = (AGV)device;
                }
                else
                {
                    throw new Exception("未找到AGV设备参数。");
                }
 
                // 使用正则表达式从设备名称中提取数字
                MatchCollection matches = Regex.Matches(roast.DeviceName, @"\d+");
                if (matches.Count == 0)
                {
                    throw new Exception("No number found in device name.");
                }
                int number = int.Parse(matches[0].Value);
 
 
 
                // 根据number的值选择相应的double集合并调整值
                List<double> doubleValues = GetDoubleValues(roast.DeviceName.Contains("正极"), number);
 
                DeviceInteraction(roast, agv, doubleValues);
 
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return Task.CompletedTask;
        }
 
        public static void DeviceInteraction(CommonRoastZ roast, AGV agv, List<double> doubleValues)
        {
            #region
            ////读烘烤滚筒是否转动
            //bool RHKupFGTZ1 = roast.Communicator.Read<bool>("YC");
            //bool RHKupFGTZ2 = roast.Communicator.Read<bool>("YD");
            //bool RHKupFGTZ3 = roast.Communicator.Read<bool>("YE");
            //bool RHKupFGTZ4 = roast.Communicator.Read<bool>("YF");
            ////写AGV滚筒转动
            //agv.Communicator.Write("DB1002." + doubleValues[0], RHKupFGTZ1);
            //agv.Communicator.Write("DB1002." + doubleValues[1], RHKupFGTZ2);
            //agv.Communicator.Write("DB1002." + doubleValues[2], RHKupFGTZ3);
            //agv.Communicator.Write("DB1002." + doubleValues[3], RHKupFGTZ4);
 
            ////读烘烤入料
            //var RFHKupa = roast.Communicator.Read<short>("D1960");
            //var RFHKupb = roast.Communicator.Read<short>("D15");
            //var RFHKupc = roast.Communicator.Read<short>("D1961");
            //var RFHKupd = roast.Communicator.Read<short>("D1950");
            //var RFHKupe = roast.Communicator.Read<short>("D1951");
 
            ////写AGV入料
            //agv.Communicator.Write("DB1002." + doubleValues[4], byte.Parse(RFHKupa.ToString()));
            //agv.Communicator.Write("DB1002." + doubleValues[5], byte.Parse(RFHKupb.ToString()));
            //agv.Communicator.Write("DB1002." + doubleValues[6], byte.Parse(RFHKupc.ToString()));
            //agv.Communicator.Write("DB1002." + doubleValues[7], byte.Parse(RFHKupd.ToString()));
            //agv.Communicator.Write("DB1002." + doubleValues[8], byte.Parse(RFHKupe.ToString()));
 
            ////读AGV入料
            //var RFAGVa = agv.Communicator.Read<byte>("DB1002." + doubleValues[9]);
            //var RFAGVb = agv.Communicator.Read<byte>("DB1002." + doubleValues[10]);
            //var RFAGVc = agv.Communicator.Read<byte>("DB1002." + doubleValues[11]);
            //var RFAGVd = agv.Communicator.Read<byte>("DB1002." + doubleValues[12]);
            //var RFAGVe = agv.Communicator.Read<byte>("DB1002." + doubleValues[22]);
 
            ////写烘烤入料
            //roast.Communicator.Write("D1940", RFAGVa);
            //roast.Communicator.Write("D1941", RFAGVb);
            //roast.Communicator.Write("D1955", RFAGVc);
            //roast.Communicator.Write("D1956", RFAGVd);
            //roast.Communicator.Write("M691", RFAGVe);
 
            ////读烘烤出料
            //var RFHKdowna = roast.Communicator.Read<short>("D1960");
            //var RFHKdownb = roast.Communicator.Read<short>("D35");
            //var RFHKdownc = roast.Communicator.Read<short>("D1962");
 
            ////写AGV出料
            //agv.Communicator.Write("DB1002." + doubleValues[13], byte.Parse(RFHKdowna.ToString()));
            //agv.Communicator.Write("DB1002." + doubleValues[14], byte.Parse(RFHKdownb.ToString()));
            //agv.Communicator.Write("DB1002." + doubleValues[15], byte.Parse(RFHKdownc.ToString()));
 
            ////读AGV出料
            //var RFAGVdowna = agv.Communicator.Read<byte>("DB1002." + doubleValues[16]);
            //var RFAGVdownb = agv.Communicator.Read<byte>("DB1002." + doubleValues[17]);
            //var RFAGVdownc = agv.Communicator.Read<byte>("DB1002." + doubleValues[18]);
            //var RFAGVdownd = agv.Communicator.Read<byte>("DB1002." + doubleValues[19]);
            //var RFAGVdowne = agv.Communicator.Read<byte>("DB1002." + doubleValues[20]);
            //var RFAGVdownf = agv.Communicator.Read<byte>("DB1002." + doubleValues[21]);
            //var RFAGVdowng = agv.Communicator.Read<bool>("DB1002." + doubleValues[23]);
 
            ////写烘烤出料
            //roast.Communicator.Write("D1940", RFAGVdowna);
            //roast.Communicator.Write("D1941", RFAGVdownb);
            //roast.Communicator.Write("D1957", RFAGVdownc);
            //roast.Communicator.Write("D1952", RFAGVdownd);
            //roast.Communicator.Write("D1953", RFAGVdowne);
            //roast.Communicator.Write("D1958", RFAGVdownf);
            //roast.Communicator.Write("M692", RFAGVdowng);
            #endregion
 
            // 读烘烤滚筒是否转动
            bool[] RHKupFGTZ = new bool[]
            {
                roast.Communicator.Read<bool>("YC"),
                roast.Communicator.Read<bool>("YD"),
                roast.Communicator.Read<bool>("YE"),
                roast.Communicator.Read<bool>("YF")
            };
 
            // 写AGV滚筒转动
            for (int i = 0; i < RHKupFGTZ.Length; i++)
            {
                agv.Communicator.Write($"DB1002.{doubleValues[i]}", RHKupFGTZ[i]);
            }
 
            // 读烘烤入料
            short[] RFHKup = new short[]
            {
                roast.Communicator.Read<short>("D1960"),
                roast.Communicator.Read<short>("D15"),
                roast.Communicator.Read<short>("D1961"),
                roast.Communicator.Read<short>("D1950"),
                roast.Communicator.Read<short>("D1951")
            };
 
            // 写AGV入料
            for (int i = 0; i < RFHKup.Length; i++)
            {
                agv.Communicator.Write($"DB1002.{doubleValues[i + 4]}", (byte)RFHKup[i]);
            }
 
            // 读AGV入料
 
            short RFAGVa = agv.Communicator.Read<byte>($"DB1002.{doubleValues[9]}");
            short RFAGVb = agv.Communicator.Read<byte>($"DB1002.{doubleValues[10]}");
            short RFAGVc = agv.Communicator.Read<byte>($"DB1002.{doubleValues[11]}");
            short RFAGVd = agv.Communicator.Read<byte>($"DB1002.{doubleValues[12]}");
            bool RFAGVe = agv.Communicator.Read<bool>($"DB1002.{doubleValues[22]}");
 
 
            // 写烘烤入料
            //string[] writeAddressesUp = new string[] { "D1940", "D1941", "D1955", "D1956", "M691" };
            //for (int i = 0; i < RFAGVup.Length; i++)
            //{
            //    roast.Communicator.Write(writeAddressesUp[i], RFAGVup[i]);
            //}
            roast.Communicator.Write("D1940", RFAGVa);
            roast.Communicator.Write("D1941", RFAGVb);
            roast.Communicator.Write("D1955", RFAGVc);
            roast.Communicator.Write("D1956", RFAGVd);
            roast.Communicator.Write("M691", RFAGVe);
            // 读烘烤出料
            short[] RFHKdown = new short[]
            {
                roast.Communicator.Read<short>("D1960"),
                roast.Communicator.Read<short>("D35"),
                roast.Communicator.Read<short>("D1962")
            };
 
            // 写AGV出料
            for (int i = 0; i < RFHKdown.Length; i++)
            {
                agv.Communicator.Write($"DB1002.{doubleValues[i + 13]}", (byte)RFHKdown[i]);
            }
 
            // 读AGV出料
            short RFAGVdowna = agv.Communicator.Read<byte>($"DB1002.{doubleValues[16]}");
            short RFAGVdownb = agv.Communicator.Read<byte>($"DB1002.{doubleValues[17]}");
            short RFAGVdownc = agv.Communicator.Read<byte>($"DB1002.{doubleValues[18]}");
            short RFAGVdownd = agv.Communicator.Read<byte>($"DB1002.{doubleValues[19]}");
            short RFAGVdowne = agv.Communicator.Read<byte>($"DB1002.{doubleValues[20]}");
            short RFAGVdownf = agv.Communicator.Read<byte>($"DB1002.{doubleValues[21]}");
            bool RFAGVdowng = agv.Communicator.Read<bool>($"DB1002.{doubleValues[23]}");
 
            // 写烘烤出料
            //string[] writeAddressesDown = new string[] { "D1940", "D1941", "D1957", "D1952", "D1953", "D1958", "M692" };
            roast.Communicator.Write("D1940", RFAGVdowna);
            roast.Communicator.Write("D1941", RFAGVdownb);
            roast.Communicator.Write("D1957", RFAGVdownc);
            roast.Communicator.Write("D1952", RFAGVdownd);
            roast.Communicator.Write("D1953", RFAGVdowne);
            roast.Communicator.Write("D1958", RFAGVdownf);
            roast.Communicator.Write("M692", RFAGVdowng);
        }
 
 
        // 根据设备类型和number的值获取并调整double值集合
        private List<double> GetDoubleValues(bool isPositivePole, int number)
        {
            List<double> doubleValues;
 
            if (isPositivePole)
            {
                doubleValues = number < 3
                    ? new List<double> { 8093.6, 8093.7, 3493.6, 3493.7, 8094.0, 8095.0, 8096.0, 8097.0, 8098.0, 8194.0, 8195.0, 8196.0, 8197.0, 3494.0, 3495.0, 3496.0, 3594.0, 3595.0, 3596.0, 3597.0, 3598.0, 3599.0, 8192.2, 3592.2 }
                    : new List<double> { 1693.6, 1693.7, 293.6, 293.6, 1694.0, 1695.0, 1696.0, 1697.0, 1698.0, 1794.0, 1795.0, 1796.0, 1797.0, 294.0, 295.0, 296.0, 394.0, 395.0, 396.0, 397.0, 398.0, 399.0, 1792.2, 392.2 };
            }
            else // 负极
            {
                doubleValues = number < 3
                    ? new List<double> { 8893.6, 8893.7, 9093.6, 9093.7, 8894.0, 8895.0, 8896.0, 8897.0, 8898.0, 8994.0, 8995.0, 8996.0, 8997.0, 9094.0, 9095.0, 9096.0, 9194.0, 9195.0, 9196.0, 9197.0, 9198.0, 9199.0, 8992.2, 9192.2 }
                    : new List<double> { 4893.6, 4893.7, 5093.6, 5093.6, 4894.0, 4895.0, 4896.0, 4897.0, 4898.0, 4994.0, 4995.0, 4996.0, 4997.0, 5094.0, 5095.0, 5096.0, 5194.0, 5195.0, 5196.0, 5197.0, 5198.0, 5199.0, 4992.2, 5192.2 };
            }
 
            // 调整double集合中的每个元素
            int adjustmentFactor = (number < 3 ? (number - 1) : (number - 3)) * 400;
            return doubleValues.Select(val => val + adjustmentFactor).ToList();
 
        }
    }
}