分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-01-26 13137e3acdb759d1541f754fba81c616f418e2a1
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
using FreeSql;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.ItemDB;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.IServices;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.Services;
using WIDESEA_WCS.WCSClient;
using static System.Collections.Specialized.BitVector32;
 
namespace WIDESEA_WCS
{
    /// <summary>
    /// 一二单元调度
    /// </summary>
    [DisallowConcurrentExecution]
    public class One_two_unitJob : IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
                if (client == null)
                {
                    return Task.CompletedTask;
                }
 
                //自动重连
                if (!client.IsConnected)
                {
                    client.Connect();
                    return Task.CompletedTask;
                }
 
                DoAction(client);
            }
            catch { }
            return Task.CompletedTask;
        }
        static List<GDXDB> gDXDBs = new List<GDXDB>();
        private void DoAction(PLCClient client)
        {
            try
            {
                #region 读写方法、日志、执行时间
                //client.Write("DB400.DBX0", "123456");
                //client.WriteByOrder("R_wheel_SN", "123456", "4.1");
                //client.WriteByOrder("R_wheel_SN", "666666", "4.2");
 
                //var res = client.Read<string>("DB400.DBX0", 20);
                //var res1 = client.ReadByOrder<string>("R_wheel_SN", "4.1");
                //var res2 = client.ReadByOrder<string>("R_wheel_SN", "4.2");
 
                //日志写入
                //WriteDBLog.Info("一二单元调度", "4.1:" + res1 + ";4.2:" + res2, "PCS");
 
                //执行完成时间
                //Console.WriteLine(DateTime.Now);
                #endregion 
 
                #region     添加PLC地址信息
                //VOLContext Context = new VOLContext();
                //Idt_plcinfodetailRepository dt_PlcinfodetailService = new dt_plcinfodetailRepository(Context);
                //List<dt_plcinfodetail> plcinfodetails = new List<dt_plcinfodetail>();
                //for (int i = 106; i <= 110; i++)
                //{
                //    dt_plcinfodetail dt_Plcinfodetail = new dt_plcinfodetail()
                //    {
                //        plcdetail_id = Guid.NewGuid(),
                //        plcdetail_iotype = "One_two_unit",
                //        plcdetail_db = "DB400",
                //        plcdetail_value = "DBX" + ((i - 1) * 30),
                //        plcdetail_valtype = "string",
                //        plcdetail_len = 20,
                //        plcdetail_name = "R_wheel_SN",
                //        plcdetail_number = "7." + (i - 80),
                //        plcdetail_remark = "读取车轮SN号"
                //    };
                //    plcinfodetails.Add(dt_Plcinfodetail);
                //    dt_plcinfodetail dt_Plcinfodetail1 = new dt_plcinfodetail()
                //    {
                //        plcdetail_id = Guid.NewGuid(),
                //        plcdetail_iotype = "One_two_unit",
                //        plcdetail_db = "DB400",
                //        plcdetail_value = "DBX" + ((i - 1) * 30 + 20),
                //        plcdetail_valtype = "int",
                //        plcdetail_name = "R_wheel_type",
                //        plcdetail_number = "7." + (i - 80),
                //        plcdetail_remark = "读取车轮类型"
                //    };
                //    plcinfodetails.Add(dt_Plcinfodetail1);
                //    dt_plcinfodetail dt_Plcinfodetail2 = new dt_plcinfodetail()
                //    {
                //        plcdetail_id = Guid.NewGuid(),
                //        plcdetail_iotype = "One_two_unit",
                //        plcdetail_db = "DB400",
                //        plcdetail_value = "DBX" + ((i - 1) * 30 + 22),
                //        plcdetail_valtype = "byte",
                //        plcdetail_name = "R_part_status",
                //        plcdetail_number = "7." + (i - 80),
                //        plcdetail_remark = "读取车轮零件状态"
                //    };
                //    plcinfodetails.Add(dt_Plcinfodetail2);
                //    dt_plcinfodetail dt_Plcinfodetail3 = new dt_plcinfodetail()
                //    {
                //        plcdetail_id = Guid.NewGuid(),
                //        plcdetail_iotype = "One_two_unit",
                //        plcdetail_db = "DB400",
                //        plcdetail_value = "DBX" + ((i - 1) * 30 + 23),
                //        plcdetail_valtype = "byte",
                //        plcdetail_name = "R_part_process",
                //        plcdetail_number = "7." + (i - 80),
                //        plcdetail_remark = "读取车轮零件工艺"
                //    };
                //    plcinfodetails.Add(dt_Plcinfodetail3);
                //    dt_plcinfodetail dt_Plcinfodetail4 = new dt_plcinfodetail()
                //    {
                //        plcdetail_id = Guid.NewGuid(),
                //        plcdetail_iotype = "One_two_unit",
                //        plcdetail_db = "DB400",
                //        plcdetail_value = "DBX" + ((i - 1) * 30 + 24),
                //        plcdetail_valtype = "byte",
                //        plcdetail_name = "R_machine_nr",
                //        plcdetail_number = "7." + (i - 80),
                //        plcdetail_remark = "读取辊道machine_nr"
                //    };
                //    plcinfodetails.Add(dt_Plcinfodetail4);
                //    dt_plcinfodetail dt_Plcinfodetail5 = new dt_plcinfodetail()
                //    {
                //        plcdetail_id = Guid.NewGuid(),
                //        plcdetail_iotype = "One_two_unit",
                //        plcdetail_db = "DB400",
                //        plcdetail_value = "DBX" + ((i - 1) * 30 + 25),
                //        plcdetail_valtype = "byte",
                //        plcdetail_name = "R_direction",
                //        plcdetail_number = "7." + (i - 80),
                //        plcdetail_remark = "读取辊道direction"
                //    };
                //    plcinfodetails.Add(dt_Plcinfodetail5);
                //}
                //dt_PlcinfodetailService.AddRange(plcinfodetails, true);
                #endregion
 
                VOLContext Context = new VOLContext();
                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
 
                PropertyInfo[] propertyInfos = typeof(GDXDB).GetProperties();//获取所有属性
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                var numbers = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep).GroupBy(x => x.plcdetail_number).ToList();
                foreach (var number in numbers)
                {
                    GDXDB dBItem = gDXDBs.Where(x => x.R_Name == number.Key).FirstOrDefault();
                    if (dBItem == null)
                    {
                        dBItem = new();
                        dBItem.OnReadSignal += HandleReadSignal;
                        gDXDBs.Add(dBItem);
                        //object obj = dBItem.R_part_status;
                        //dBItem.R_part_status = client.Read<byte>(number.Key);
                    }
                    List<dt_plcinfodetail> details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == number.Key).ToList();
                    for (int i = 0; i < propertyInfos.Length; i++)
                    {
                        if (i == 0)
                        {
                            dBItem.R_Name = number.Key;
                        }
                        else
                        {
                            object readData = DBExtension.Read(details.Where(x => x.plcdetail_name == propertyInfos[i].Name).FirstOrDefault(), client);
                            if (readData != null) { }
                            object obj = propertyInfos[i].GetValue(dBItem);
                            if (obj != readData)
                                propertyInfos[i].SetValue(dBItem, readData);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 
        public void HandleReadSignal(GDXDB DBItem)
        {
            VOLContext Context = new VOLContext();
            Idt_ActualProductionRepository repository = new dt_ActualProductionRepository(Context);
            var info = repository.FindFirst(x => x.SN == DBItem.R_wheel_SN);//查询车轮的详细信息
            if (info != null)
            {
                //告诉桁架
 
            }
        }
    }
}