| | |
| | | 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; |
| | | //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> |
| | | /// OP30 告警监控 |
| | | /// </summary> |
| | | public class DataCaptureHandler_OP3007: DataCaptureHandler |
| | | { |
| | | public static readonly DataCaptureHandler_OP3007 Instance = new DataCaptureHandler_OP3007(); |
| | | //namespace iWare_SCADA_BusinessLogical |
| | | //{ |
| | | // /// <summary> |
| | | // /// OP30 告警监控 |
| | | // /// </summary> |
| | | // public class DataCaptureHandler_OP3007 : DataCaptureHandler |
| | | // { |
| | | // public static readonly DataCaptureHandler_OP3007 Instance = new DataCaptureHandler_OP3007(); |
| | | |
| | | public DataCaptureHandler_OP3007() |
| | | { |
| | | } |
| | | // public DataCaptureHandler_OP3007() |
| | | // { |
| | | // } |
| | | |
| | | public override string WorkingProcedure |
| | | { |
| | | get { return _dataCaptureConfig.WorkingProcedure; } |
| | | } |
| | | // 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 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 "OP3007": |
| | | // //_dataCaptureConfig = dataCaptureColumnDict; |
| | | // IsCaptureflag = true; |
| | | // return; |
| | | // public override void RefreshDataList(List<DataCaptureConfig> dataCaptureConfig) |
| | | // { |
| | | // //try |
| | | // //{ |
| | | // // foreach (var dataCaptureColumnDict in dataCaptureConfig) |
| | | // // { |
| | | // // switch (dataCaptureColumnDict.DataCapturePointCode) |
| | | // // { |
| | | // // case "OP3007": |
| | | // // //_dataCaptureConfig = dataCaptureColumnDict; |
| | | // // IsCaptureflag = true; |
| | | // // return; |
| | | |
| | | // } |
| | | // } |
| | | //} |
| | | //catch (Exception ex) |
| | | //{ |
| | | // SystemValue._lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} OP30工序监控打码标记 出现异常,请查看日志!"; |
| | | // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "刷新 OP30工序监控打码标记数据时异常:", ex); |
| | | //} |
| | | } |
| | | // // } |
| | | // // } |
| | | // //} |
| | | // //catch (Exception ex) |
| | | // //{ |
| | | // // SystemValue._lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} OP30工序监控打码标记 出现异常,请查看日志!"; |
| | | // // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "刷新 OP30工序监控打码标记数据时异常:", ex); |
| | | // //} |
| | | // } |
| | | |
| | | public override void DataCaptureStart() |
| | | { |
| | | if (SystemValue.isStartedModel) |
| | | { |
| | | var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig); |
| | | WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); |
| | | wplog.Id = Yitter.IdGenerator.YitIdHelper.NextId(); |
| | | wplog.WorkingProcedure = WorkingProcedure; |
| | | wplog.EquipmentID = WorkingProcedure; |
| | | wplog.Remarks = WorkingProcedure; |
| | | wplog.MonitoringPoint = DataCapturePointCode; |
| | | wplog.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | wplog.CreatedUserName = DataCapturePointCode; |
| | | wplog.IsDeleted = false; |
| | | // public override void DataCaptureStart() |
| | | // { |
| | | // if (SystemValue.isStartedImitateModel) |
| | | // { |
| | | // /* |
| | | // var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig); |
| | | // WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); |
| | | // wplog.Id = Yitter.IdGenerator.YitIdHelper.NextId(); |
| | | // wplog.WorkingProcedure = WorkingProcedure; |
| | | // wplog.EquipmentID = WorkingProcedure; |
| | | // wplog.Remarks = WorkingProcedure; |
| | | // wplog.MonitoringPoint = DataCapturePointCode; |
| | | // wplog.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | // wplog.CreatedUserName = DataCapturePointCode; |
| | | // wplog.IsDeleted = false; |
| | | |
| | | |
| | | wplog.WorkPieceID = WorkPieceID; |
| | | wplog.EquipmentID = _dataCaptureConfig.EquipmentID; |
| | | wplog.UpdatedTime = DateTimeHelper.GetDateTime(); |
| | | wplog.UpdatedUserName = DataCapturePointCode; |
| | | // wplog.WorkPieceID = WorkPieceID; |
| | | // wplog.EquipmentID = _dataCaptureConfig.EquipmentID; |
| | | // wplog.UpdatedTime = DateTimeHelper.GetDateTime(); |
| | | // wplog.UpdatedUserName = DataCapturePointCode; |
| | | |
| | | wplog.AlertTime = DateTime.Now; |
| | | Random ran = new Random(); |
| | | //wplog.FailureType = "1101"+ ran.Next(0,100); |
| | | wplog.AlertMsg = "测试告警 1101"; |
| | | // wplog.AlertTime = DateTime.Now; |
| | | // Random ran = new Random(); |
| | | // //wplog.FailureType = "1101"+ ran.Next(0,100); |
| | | // wplog.AlertMsg = "测试告警 1101"; |
| | | |
| | | wplog.EquipmentCurrentState = ((int)EnumEquipmentCurrentStateDisplay.故障).ToString(); |
| | | //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 |
| | | WorkPieceInfoManager.AlertMonitor(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | // wplog.EquipmentCurrentState = ((int)EnumEquipmentCurrentStateDisplay.故障).ToString(); |
| | | // //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 |
| | | // WorkPieceInfoManager.AlertMonitor(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | |
| | | return; |
| | | } |
| | | if (IsCaptureflag) |
| | | { |
| | | var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig); |
| | | if (plcService == null) |
| | | { |
| | | SystemValue.lbl_Alert_OP3007 = $"{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_OP3007 = $" {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_OP3007.Equals("0") && value.ToString().Equals("1")) |
| | | {//当上一标记位0,当前获取标记为1时, |
| | | //触发操作, 并给静态变量赋值为1 |
| | | //业务代码 |
| | | WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); |
| | | wplog.Id = Yitter.IdGenerator.YitIdHelper.NextId(); |
| | | wplog.WorkingProcedure = WorkingProcedure; |
| | | wplog.EquipmentID = WorkingProcedure; |
| | | wplog.Remarks = WorkingProcedure; |
| | | wplog.MonitoringPoint = DataCapturePointCode; |
| | | wplog.WorkPieceID = "123456"; |
| | | wplog.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | wplog.CreatedUserName = DataCapturePointCode; |
| | | wplog.IsDeleted = false; |
| | | 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.AlertMonitor(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | // //*/ |
| | | // return; |
| | | // } |
| | | // if (IsCaptureflag) |
| | | // { |
| | | // var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig); |
| | | // if (plcService == null) |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3007 = $"{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_OP3007 = $" {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_OP3007.Equals("0") && value.ToString().Equals("1")) |
| | | // {//当上一标记位0,当前获取标记为1时, |
| | | // //触发操作, 并给静态变量赋值为1 |
| | | // //业务代码 |
| | | // WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); |
| | | // wplog.Id = Yitter.IdGenerator.YitIdHelper.NextId(); |
| | | // wplog.WorkingProcedure = WorkingProcedure; |
| | | // wplog.EquipmentID = WorkingProcedure; |
| | | // wplog.Remarks = WorkingProcedure; |
| | | // wplog.MonitoringPoint = DataCapturePointCode; |
| | | // wplog.WorkPieceID = "123456"; |
| | | // wplog.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | // wplog.CreatedUserName = DataCapturePointCode; |
| | | // wplog.IsDeleted = false; |
| | | // 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.AlertMonitor(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | |
| | | |
| | | //判断是否跳序,上一工序质量是否合格 |
| | | // //判断是否跳序,上一工序质量是否合格 |
| | | |
| | | |
| | | |
| | | //反馈给PLC,写入 |
| | | // //反馈给PLC,写入 |
| | | |
| | | |
| | | } |
| | | //SystemValue.value_OP3007 = value.ToString(); |
| | | // } |
| | | // //SystemValue.value_OP3007 = value.ToString(); |
| | | |
| | | |
| | | } |
| | | SystemValue.lbl_Alert_OP3007 = $"abcdefg:{RandomHelper.GenerateRandomCode(4)}"; |
| | | // } |
| | | // SystemValue.lbl_Alert_OP3007 = $"abcdefg:{RandomHelper.GenerateRandomCode(4)}"; |
| | | |
| | | if (!_dataCaptureConfig.DataCaptureFrequency.HasValue || _dataCaptureConfig.DataCaptureFrequency < 10) |
| | | { |
| | | Thread.Sleep(5000); |
| | | } |
| | | else |
| | | { |
| | | Thread.Sleep(_dataCaptureConfig.DataCaptureFrequency.Value); |
| | | } |
| | | // if (!_dataCaptureConfig.DataCaptureFrequency.HasValue || _dataCaptureConfig.DataCaptureFrequency < 10) |
| | | // { |
| | | // Thread.Sleep(5000); |
| | | // } |
| | | // else |
| | | // { |
| | | // Thread.Sleep(_dataCaptureConfig.DataCaptureFrequency.Value); |
| | | // } |
| | | |
| | | } |
| | | catch (System.Data.Entity.Validation.DbEntityValidationException ex) |
| | | { |
| | | SystemValue.lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} 读取{WorkingProcedure}工序监控打码标记 出现异常,请查看日志!"; |
| | | Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "读取 {WorkingProcedure}工序监控打码标记数据时异常:", ex); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | SystemValue.lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} 读取{WorkingProcedure}工序监控打码标记 出现异常,请查看日志!"; |
| | | Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "读取 {WorkingProcedure}工序监控打码标记数据时异常:", ex); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | SystemValue.lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} {WorkingProcedure}工序监控打码标记 不做校验,请确认配置信息!"; |
| | | Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "读{WorkingProcedure}工序监控打码标记 不做校验,请确认是否配置异常"); |
| | | } |
| | | } |
| | | // } |
| | | // catch (System.Data.Entity.Validation.DbEntityValidationException ex) |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} 读取{WorkingProcedure}工序监控打码标记 出现异常,请查看日志!"; |
| | | // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "读取 {WorkingProcedure}工序监控打码标记数据时异常:", ex); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} 读取{WorkingProcedure}工序监控打码标记 出现异常,请查看日志!"; |
| | | // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "读取 {WorkingProcedure}工序监控打码标记数据时异常:", ex); |
| | | // } |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3007 = $" {RandomHelper.GenerateRandomCode(4)} {WorkingProcedure}工序监控打码标记 不做校验,请确认配置信息!"; |
| | | // Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), "读{WorkingProcedure}工序监控打码标记 不做校验,请确认是否配置异常"); |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | } |
| | | // } |
| | | //} |