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 { /// /// OP05工序监控打码标记 /// public class DataCaptureHandler_OP05 : DataCaptureHandler { public static readonly DataCaptureHandler_OP05 Instance = new DataCaptureHandler_OP05(); public List _dataCaptureConfig = new List(); public DataCaptureHandler_OP05() { } public override string WorkingProcedure { get { return _dataCaptureConfig.FirstOrDefault().WorkingProcedure; } } public override string DataCapturePointCode { get { return _dataCaptureConfig.FirstOrDefault().DataCapturePointCode; } } public override string DataCapturePointCname { get { return _dataCaptureConfig.FirstOrDefault().DataCapturePointCname; } } public override void RefreshDataList(List dataCaptureConfig) { //try //{ // foreach (var dataCaptureColumnDict in dataCaptureConfig) // { // switch (dataCaptureColumnDict.DataCapturePointCode) // { // case "OP0501": // //_dataCaptureConfig = dataCaptureColumnDict; // IsCaptureflag = true; // return; // } // } //} //catch (Exception ex) //{ // SystemValue._lbl_Alert_OP0501 = $" {RandomHelper.GenerateRandomCode(4)} OP05工序监控打码标记 出现异常,请查看日志!"; // Log4NetHelper.WriteErrorLog(LogType.PLCOP05, "刷新 OP05工序监控打码标记数据时异常:", ex); //} } public override void DataCaptureStart() { if(IsCaptureflag) { var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig.FirstOrDefault()); if (plcService == null) { SystemValue.lbl_Alert_OP0501 = $"{RandomHelper.GenerateRandomCode(4)} 没有找到PLC设备"; return; } if (plcService != null && !plcService.IsConnected) { plcService.Close(); plcService.OpenService(); } while (true) { try { //_dataCaptureConfig if (plcService == null || !plcService.IsConnected) { SystemValue.lbl_Alert_OP0501 = $" {RandomHelper.GenerateRandomCode(4)} {_dataCaptureConfig.FirstOrDefault().WorkingProcedure} PLC连接已断开,正在尝试打开!"; plcService.Close(); plcService.OpenService(); Thread.Sleep(100); continue; } else { //业务代码 plcService.ReadValuePoint("", "", PLCManger.GetTypeForString(_dataCaptureConfig.FirstOrDefault().DataCaptureColumnType)); } SystemValue.lbl_Alert_OP0501 = $"abcdefg:{RandomHelper.GenerateRandomCode(4)}"; } catch (Exception ex) { SystemValue.lbl_Alert_OP0501 = $" {RandomHelper.GenerateRandomCode(4)} 读取OP05工序监控打码标记 出现异常,请查看日志!"; Log4NetHelper.WriteErrorLog(LogType.PLCOP05, "读取 OP05工序监控打码标记数据时异常:", ex); } } } else { SystemValue.lbl_Alert_OP0501 = $" {RandomHelper.GenerateRandomCode(4)} OP05工序监控打码标记 不做校验,请确认配置信息!"; Log4NetHelper.WriteInfoLog(LogType.PLCOP05, "读OP05工序监控打码标记 不做校验,请确认是否配置异常"); } } } }