schangxiang@126.com
2024-09-04 35f78d6371d884271e5f9873a5193bf979fc2c1d
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
using iWare_SCADA_BusinessLogical.BLL;
using iWare_SCADA_BusinessLogical.Utils;
using iWare_SCADA_Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace iWare_SCADA_BusinessLogical
{
    /// <summary>
    /// OP20告警标记
    /// </summary>
    public class DataCaptureHandler_OP2006: DataCaptureHandler
    {
        public static readonly DataCaptureHandler_OP2006 Instance = new DataCaptureHandler_OP2006();
 
        public DataCaptureHandler_OP2006()
        {
        }
 
        public override string WorkingProcedure
        {
            get { return _dataCaptureConfig.WorkingProcedure; }
        }
 
        public override string DataCapturePointCode
        {
            get { return _dataCaptureConfig.DataCapturePointCode; }
        }
        public override string DataCapturePointCname
        {
            get { return _dataCaptureConfig.DataCapturePointCname; }
        }
 
 
        public override void RefreshDataList(List<DataCaptureConfig> dataCaptureConfig)
        {
            //try
            //{
            //    foreach (var dataCaptureColumnDict in dataCaptureConfig)
            //    {
            //        switch (dataCaptureColumnDict.DataCapturePointCode)
            //        {
            //            case "OP2001":
            //                //_dataCaptureConfig = dataCaptureColumnDict;
            //                IsCaptureflag = true;
            //                return;
 
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    SystemValue._lbl_Alert_OP2001 = $" {RandomHelper.GenerateRandomCode(4)} OP05工序监控打码标记 出现异常,请查看日志!";
            //    Log4NetHelper.WriteErrorLog(LogType.PLCOP05, "刷新 OP05工序监控打码标记数据时异常:", ex);
            //}
        }
 
        public override void DataCaptureStart()
        {
            if (IsCaptureflag)
            {
                var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig);
                if (plcService == null)
                {
                    SystemValue._lbl_Alert_OP2001 = $"{RandomHelper.GenerateRandomCode(4)} 没有找到{_dataCaptureConfig.WorkingProcedure}的PLC设备";
                    return;
                }
                if (plcService != null && !plcService.IsConnected)
                {
                    plcService.Close();
                    plcService.OpenService();
                }
                while (true)
                {
                    try
                    {
                        //_dataCaptureConfig
                        if (plcService == null || !plcService.IsConnected)
                        {
                            SystemValue._lbl_Alert_OP2001 = $" {RandomHelper.GenerateRandomCode(4)} {_dataCaptureConfig.WorkingProcedure} PLC连接已断开,正在尝试打开!";
                            plcService.Close();
                            plcService.OpenService();
                            Thread.Sleep(100);
                            continue;
                        }
                        else
                        {
                            var value = plcService.ReadValuePoint(_dataCaptureConfig.DbNumber, _dataCaptureConfig.Offset, PLCManger.GetTypeForString(_dataCaptureConfig.DataCaptureColumnType));
                            if (SystemValue.value_OP2001.Equals("0") && value.ToString().Equals("1"))
                            {//当上一标记位0,当前获取标记为1时,
                             //触发操作,  并给静态变量赋值为1
                             //业务代码
                                WorkPieceLog wplog = new WorkPieceLog();
                                wplog.WorkingProcedure = "OP20";
                                wplog.EquipmentID = "OP20";
                                wplog.Remarks = "OP20";
                                foreach (var col in colConfig)
                                {
                                    switch(col.DbNumber+ col.Offset)
                                    {
                                        case "":
                                            var valuecol = plcService.ReadValuePoint(col.DbNumber, col.Offset, PLCManger.GetTypeForString(col.DataCaptureColumnType));
                                            wplog.WorkPieceID = valuecol.ToString();
                                            break;
                                    }
                                }
                                //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表
                                WorkPieceInfoManager.ReadQRcode(wplog, LogType.PLCOP20, plcService, _dataCaptureConfig.IsFeedback);
 
 
                                //判断是否跳序,上一工序质量是否合格
 
                                //反馈给PLC,写入
 
 
                            }
                            SystemValue.value_OP2001 = value.ToString();
 
 
                        }
                        SystemValue._lbl_Alert_OP2001 = $"abcdefg:{RandomHelper.GenerateRandomCode(4)}";
 
                    }
                    catch (Exception ex)
                    {
                        SystemValue._lbl_Alert_OP2001 = $" {RandomHelper.GenerateRandomCode(4)} 读取OP05工序监控打码标记 出现异常,请查看日志!";
                        Log4NetHelper.WriteErrorLog(LogType.PLCOP05, "读取 OP05工序监控打码标记数据时异常:", ex);
                    }
                }
            }
            else
            {
                SystemValue._lbl_Alert_OP2001 = $" {RandomHelper.GenerateRandomCode(4)} OP05工序监控打码标记 不做校验,请确认配置信息!";
                Log4NetHelper.WriteInfoLog(LogType.PLCOP05, "读OP05工序监控打码标记 不做校验,请确认是否配置异常");
            }
        }
 
    }
}