分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-01-31 50fd5cc9cfad08714c4daa6d481c5293ff2ae6b1
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
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.EFDbContext;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    public class Gantry
    {
        static VOLContext Context = new VOLContext();
        Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
        Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
        Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
        /// <summary>
        /// 查询车轮数据
        /// </summary>
        public void QueryWheeldata(PLCClient client)
        {
            try
            {
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> names = new List<string>() { "1单元辊道下料查询车轮", "2单元辊道下料查询车轮", "3单元辊道下料查询车轮", "辊道上料查询车轮" };
                foreach (string name in names)
                {
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                    var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
                    if ((Int16)on == 1)
                    {
                        var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
                        var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
                        if (geometry == null)
                        {
                            //DBExtension.Write(details.Where(x => x.plcdetail_name == "W_i_status").First(), client, (Int16)2);
                            client.WriteByOrder("W_i_status", (Int16)2, name);//1-找到数据,2-未找到工件类型数据
                            client.WriteByOrder("W_i_skip_op", "1", name);//屏蔽工艺(屏蔽视觉检测/屏蔽涂油);
                                                                          //0-使用,1-跳过
                            client.WriteByOrder("R_oi_on", (Int16)0, name);
                        }
                        else
                        {
                            client.WriteByOrder("W_i_status", (Int16)1, name);
                            client.WriteByOrder("W_i_parameter_a", (float)geometry.a, name);
                            client.WriteByOrder("W_i_parameter_b", (float)geometry.b, name);
                            client.WriteByOrder("W_i_parameter_c", (float)geometry.c, name);
                            client.WriteByOrder("W_i_parameter_d", (float)geometry.d, name);
                            client.WriteByOrder("W_i_parameter_e", (float)geometry.e, name);
                            client.WriteByOrder("W_i_parameter_f", (float)geometry.f, name);
                            client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
                            client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
                            //屏蔽工艺(屏蔽视觉检测/屏蔽涂油)
                            client.WriteByOrder("W_i_skip_op", "0", name);//字符串写入-2
                            client.WriteByOrder("R_oi_on", (Int16)0, name);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <summary>
        /// 查询订单,是否需要加工
        /// </summary>
        public void QueryOrder(PLCClient client)
        {
            try
            {
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> names = new List<string>() { "1单元辊道下料查询订单", "2单元辊道下料查询订单", "3单元辊道下料查询订单", "辊道上料查询订单" };
                foreach (string name in names)
                {
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                    var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
                    if ((Int16)on == 1)
                    {
                        var wp_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_id").First(), client);
                        //需添加查询车轮SN号订单逻辑
 
                        var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
                        var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
                        if (geometry == null)
                        {
                            client.WriteByOrder("W_i_status", (Int16)2, name);//1-好,允许加工,2-不在列表中,3-不加工车轮类型
                            client.WriteByOrder("R_oi_on", (Int16)0, name);
                        }
                        else
                        {
                            client.WriteByOrder("W_i_status", (Int16)1, name);
                            //client.WriteByOrder("W_i_job_id", "", name);
                            //client.WriteByOrder("W_i_drawing_id", "", name);
                            //client.WriteByOrder("W_i_heat_id", "", name);
                            //client.WriteByOrder("W_i_sourceheat", "", name);
                            //client.WriteByOrder("W_i_batch_id", "", name);
                            client.WriteByOrder("R_oi_on", (Int16)0, name);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <summary>
        /// 下料位交互
        /// </summary>
        public void Layofflevel(PLCClient client)
        {
            try
            {
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> names = new List<string>() { "1单元下料区", "2单元下料区", "3单元下料区", "上料区" };
                foreach (string name in names)
                {
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
 
                    var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                    if (!Request) continue;
                    var PartStatus = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
                    var Wheel_Type = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//车轮类型
                    var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();//车轮SN号
 
 
                    client.WriteByOrder("W_AreaNr", (Int16)1, name);//区域货位号
                    client.WriteByOrder("W_IndexNr", (Int16)1, name);//托盘上的第几个车轮
                    client.WriteByOrder("W_Storage_Type", true, name);//托盘类型1-横放;2-竖放
                    client.WriteByOrder("W_Enabl_Load", true, name);//是否允许
 
                    var finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//放料完成
                    if (finished)
                    {
 
                        client.WriteByOrder("W_Storage_update", true, name);//货位状态更新
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <summary>
        /// 防呆措施
        /// </summary>
        static bool Gantry_Out_of_Area1;//桁架是否在区域内
        static bool Gantry_Out_of_Area2;//桁架是否在区域内
        static bool Gantry_Out_of_Area3;//桁架是否在区域内
        static bool Gantry_Out_of_Area4;//桁架是否在区域内
        public void Stupidproofmeasure(PLCClient client)
        {
            try
            {
                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                List<string> names = new List<string>() { "1单元防呆", "2单元防呆", "3单元防呆", "上料区防呆" };
                foreach (string name in names)
                {
                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                    var Release_In = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Release_In").First(), client);//允许进入
                    if (!Release_In) { }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}