| | |
| | | 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 System.Web.UI.WebControls; |
| | | //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 System.Web.UI.WebControls; |
| | | |
| | | namespace iWare_SCADA_BusinessLogical |
| | | { |
| | | /// <summary> |
| | | /// OP35测量完成标记 |
| | | /// </summary> |
| | | public class DataCaptureHandler_OP3502: DataCaptureHandler |
| | | { |
| | | public static readonly DataCaptureHandler_OP3502 Instance = new DataCaptureHandler_OP3502(); |
| | | //namespace iWare_SCADA_BusinessLogical |
| | | //{ |
| | | // /// <summary> |
| | | // /// OP35测量完成标记 |
| | | // /// </summary> |
| | | // public class DataCaptureHandler_OP3502 : DataCaptureHandler |
| | | // { |
| | | // public static readonly DataCaptureHandler_OP3502 Instance = new DataCaptureHandler_OP3502(); |
| | | |
| | | public DataCaptureHandler_OP3502() |
| | | { |
| | | } |
| | | // public DataCaptureHandler_OP3502() |
| | | // { |
| | | // } |
| | | |
| | | 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) |
| | | { |
| | | } |
| | | // public override void RefreshDataList(List<DataCaptureConfig> dataCaptureConfig) |
| | | // { |
| | | // } |
| | | |
| | | 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.WorkPieceID = "123456"; |
| | | wplog.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | wplog.CreatedUserName = DataCapturePointCode; |
| | | wplog.IsDeleted = false; |
| | | wplog.QualityType = QualityType.Online.ToString(); |
| | | // 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.WorkPieceID = "123456"; |
| | | // wplog.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | // wplog.CreatedUserName = DataCapturePointCode; |
| | | // wplog.IsDeleted = false; |
| | | // wplog.QualityType = QualityType.Online.ToString(); |
| | | |
| | | |
| | | wplog.WorkPieceID = WorkPieceID; |
| | | wplog.EquipmentID = _dataCaptureConfig.EquipmentID; |
| | | wplog.UpdatedTime = DateTimeHelper.GetDateTime(); |
| | | wplog.UpdatedUserName = DataCapturePointCode; |
| | | wplog.QualityState = (int)QualityState.NG; |
| | | wplog.QualityStateUpdateUser = WorkingProcedure; |
| | | wplog.QualityStateUpdateMode = QualityStateUpdateMode.Auto.ToString(); |
| | | // wplog.WorkPieceID = WorkPieceID; |
| | | // wplog.EquipmentID = _dataCaptureConfig.EquipmentID; |
| | | // wplog.UpdatedTime = DateTimeHelper.GetDateTime(); |
| | | // wplog.UpdatedUserName = DataCapturePointCode; |
| | | // wplog.QualityState = (int)QualityState.NG; |
| | | // wplog.QualityStateUpdateUser = WorkingProcedure; |
| | | // wplog.QualityStateUpdateMode = QualityStateUpdateMode.Auto.ToString(); |
| | | |
| | | wplog.QualityOP35To1 = "QualityOP35To1"; |
| | | wplog.QualityOP35To2 = "QualityOP35To2"; |
| | | //wplog.QualityOP35To3 = "QualityOP35To3"; |
| | | //wplog.QualityOP35To4 = "QualityOP35To4"; |
| | | //wplog.QualityOP35To5 = "QualityOP35To5"; |
| | | //wplog.QualityOP35To6 = "QualityOP35To6"; |
| | | //wplog.QualityOP35To7 = "QualityOP35To7"; |
| | | // wplog.QualityOP35To1 = "QualityOP35To1"; |
| | | // wplog.QualityOP35To2 = "QualityOP35To2"; |
| | | // //wplog.QualityOP35To3 = "QualityOP35To3"; |
| | | // //wplog.QualityOP35To4 = "QualityOP35To4"; |
| | | // //wplog.QualityOP35To5 = "QualityOP35To5"; |
| | | // //wplog.QualityOP35To6 = "QualityOP35To6"; |
| | | // //wplog.QualityOP35To7 = "QualityOP35To7"; |
| | | |
| | | //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 |
| | | WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | // //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 |
| | | // WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | |
| | | // //*/ |
| | | |
| | | return; |
| | | } |
| | | if (IsCaptureflag) |
| | | { |
| | | var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig); |
| | | if (plcService == null) |
| | | { |
| | | SystemValue.lbl_Alert_OP3502 = $"{RandomHelper.GenerateRandomCode(4)} 没有找到{_dataCaptureConfig.WorkingProcedure}的PLC设备"; |
| | | return; |
| | | } |
| | | if (plcService != null && !plcService.IsConnected) |
| | | { |
| | | plcService.Close(); |
| | | plcService.OpenService(); |
| | | } |
| | | while (true) |
| | | { |
| | | ThreadStatusMonitor threadStatusMonitor = new ThreadStatusMonitor(); |
| | | threadStatusMonitor.Threadcode = DataCapturePointCode; |
| | | threadStatusMonitor.Threadcname = DataCapturePointCname; |
| | | threadStatusMonitor.Threadendtime = DateTime.Now; |
| | | threadStatusMonitor.Threadlastmodifytime = DateTime.Now; |
| | | threadStatusMonitor.Threadstatue = 0; |
| | | threadStatusMonitor.ThreadId = Thread.CurrentThread.ManagedThreadId.ToString(); |
| | | try |
| | | { |
| | | //_dataCaptureConfig |
| | | if (plcService == null || !plcService.IsConnected) |
| | | { |
| | | SystemValue.lbl_Alert_OP3502 = $" {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_OP3502.Equals("FALSE") && value.ToString().ToUpper().Equals("TRUE")) |
| | | {//当上一标记位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.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | wplog.CreatedUserName = DataCapturePointCode; |
| | | wplog.IsDeleted = false; |
| | | wplog.QualityType = QualityType.Online.ToString(); |
| | | // return; |
| | | // } |
| | | // if (IsCaptureflag) |
| | | // { |
| | | // var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig); |
| | | // if (plcService == null) |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3502 = $"{RandomHelper.GenerateRandomCode(4)} 没有找到{_dataCaptureConfig.WorkingProcedure}的PLC设备"; |
| | | // return; |
| | | // } |
| | | // if (plcService != null && !plcService.IsConnected) |
| | | // { |
| | | // plcService.Close(); |
| | | // plcService.OpenService(); |
| | | // } |
| | | // while (true) |
| | | // { |
| | | // ThreadStatusMonitor threadStatusMonitor = new ThreadStatusMonitor(); |
| | | // threadStatusMonitor.Threadcode = DataCapturePointCode; |
| | | // threadStatusMonitor.Threadcname = DataCapturePointCname; |
| | | // threadStatusMonitor.Threadendtime = DateTime.Now; |
| | | // threadStatusMonitor.Threadlastmodifytime = DateTime.Now; |
| | | // threadStatusMonitor.Threadstatue = 0; |
| | | // threadStatusMonitor.ThreadId = Thread.CurrentThread.ManagedThreadId.ToString(); |
| | | // try |
| | | // { |
| | | // //_dataCaptureConfig |
| | | // if (plcService == null || !plcService.IsConnected) |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3502 = $" {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_OP3502.Equals("FALSE") && value.ToString().ToUpper().Equals("TRUE")) |
| | | // {//当上一标记位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.CreatedTime = DateTimeHelper.GetDateTime(); |
| | | // wplog.CreatedUserName = DataCapturePointCode; |
| | | // wplog.IsDeleted = false; |
| | | // wplog.QualityType = QualityType.Online.ToString(); |
| | | |
| | | foreach (var col in colConfig.Where(o => o.DataCapturePointCode == DataCapturePointCode)) |
| | | { |
| | | try |
| | | { |
| | | var valuecol = plcService.ReadValuePoint(col.DbNumber, col.Offset, col.DataCaptureColumnLength.Value, PLCManger.GetTypeForString(col.DataCaptureColumnType)); |
| | | //wplog.GetType().GetProperty(col.DataCaptureColumnTabelName).SetValue(wplog, valuecol);//给动态字段赋值 |
| | | var set = wplog.GetType().GetProperty(col.DataCaptureColumnTabelName); |
| | | if (set == null) |
| | | { |
| | | Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $" {DataCapturePointCode}工序监控测量完成标记 读取工件码动态由于字段名没找到,赋值【{WorkingProcedure ?? "空字符串"}】失败{wplog.Id}"); |
| | | } |
| | | set.SetValue(wplog, valuecol);//给动态字段赋值 |
| | | } |
| | | catch (Exception setex) |
| | | { |
| | | Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $" {DataCapturePointCode}工序监控测量完成标记 读取工件码动态赋值【{WorkingProcedure ?? "空字符串"}】异常{wplog.Id}", setex); |
| | | } |
| | | } |
| | | //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 |
| | | WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | threadStatusMonitor.Threadstatue = 1; |
| | | // foreach (var col in colConfig.Where(o => o.DataCapturePointCode == DataCapturePointCode)) |
| | | // { |
| | | // try |
| | | // { |
| | | // var valuecol = plcService.ReadValuePoint(col.DbNumber, col.Offset, col.DataCaptureColumnLength.Value, PLCManger.GetTypeForString(col.DataCaptureColumnType)); |
| | | // //wplog.GetType().GetProperty(col.DataCaptureColumnTabelName).SetValue(wplog, valuecol);//给动态字段赋值 |
| | | // var set = wplog.GetType().GetProperty(col.DataCaptureColumnTabelName); |
| | | // if (set == null) |
| | | // { |
| | | // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $" {DataCapturePointCode}工序监控测量完成标记 读取工件码动态由于字段名没找到,赋值【{WorkingProcedure ?? "空字符串"}】失败{wplog.Id}"); |
| | | // } |
| | | // set.SetValue(wplog, valuecol);//给动态字段赋值 |
| | | // } |
| | | // catch (Exception setex) |
| | | // { |
| | | // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $" {DataCapturePointCode}工序监控测量完成标记 读取工件码动态赋值【{WorkingProcedure ?? "空字符串"}】异常{wplog.Id}", setex); |
| | | // } |
| | | // } |
| | | // //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 |
| | | // WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); |
| | | // threadStatusMonitor.Threadstatue = 1; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | SystemValue.value_OP3502 = value.ToString(); |
| | | // } |
| | | // SystemValue.value_OP3502 = value.ToString(); |
| | | |
| | | |
| | | } |
| | | SystemValue.lbl_Alert_OP3502 = $"abcdefg:{RandomHelper.GenerateRandomCode(4)}"; |
| | | if (!_dataCaptureConfig.DataCaptureFrequency.HasValue || _dataCaptureConfig.DataCaptureFrequency < 10) |
| | | { |
| | | Thread.Sleep(5000); |
| | | } |
| | | else |
| | | { |
| | | Thread.Sleep(_dataCaptureConfig.DataCaptureFrequency.Value); |
| | | } |
| | | // } |
| | | // SystemValue.lbl_Alert_OP3502 = $"abcdefg:{RandomHelper.GenerateRandomCode(4)}"; |
| | | // if (!_dataCaptureConfig.DataCaptureFrequency.HasValue || _dataCaptureConfig.DataCaptureFrequency < 10) |
| | | // { |
| | | // Thread.Sleep(5000); |
| | | // } |
| | | // else |
| | | // { |
| | | // Thread.Sleep(_dataCaptureConfig.DataCaptureFrequency.Value); |
| | | // } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | SystemValue.lbl_Alert_OP3502 = $" {RandomHelper.GenerateRandomCode(4)} 读取{DataCapturePointCode}工序监控测量标记 出现异常,请查看日志!"; |
| | | Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"读取 {DataCapturePointCode}工序监控测量标记数据时异常:", ex); |
| | | } |
| | | finally |
| | | { |
| | | WorkPieceInfoManager.ThreadMonitor(threadStatusMonitor); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | SystemValue.lbl_Alert_OP3502 = $" {RandomHelper.GenerateRandomCode(4)} {DataCapturePointCode}工序监控测量标记 不做校验,请确认配置信息!"; |
| | | Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"读{DataCapturePointCode}工序监控测量标记 不做校验,请确认是否配置异常"); |
| | | } |
| | | } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3502 = $" {RandomHelper.GenerateRandomCode(4)} 读取{DataCapturePointCode}工序监控测量标记 出现异常,请查看日志!"; |
| | | // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"读取 {DataCapturePointCode}工序监控测量标记数据时异常:", ex); |
| | | // } |
| | | // finally |
| | | // { |
| | | // WorkPieceInfoManager.ThreadMonitor(threadStatusMonitor); |
| | | // } |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // SystemValue.lbl_Alert_OP3502 = $" {RandomHelper.GenerateRandomCode(4)} {DataCapturePointCode}工序监控测量标记 不做校验,请确认配置信息!"; |
| | | // Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"读{DataCapturePointCode}工序监控测量标记 不做校验,请确认是否配置异常"); |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | } |
| | | // } |
| | | //} |