12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using Aitex.Core.RT.Log;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Venus_Core;
- namespace Aitex.Core.RT.Tolerance
- {
- public class RecipeToleranceChecker
- {
- Stopwatch _stopwatch;
- List<ToleranceObject> _toleranceObjects;
- string _Module;
- public RecipeToleranceChecker(string module)
- {
- _stopwatch = new Stopwatch();
- _Module = module;
- }
- public void Start( List<ToleranceObject> toleranceObjects)
- {
- _stopwatch.Restart();
- _toleranceObjects = toleranceObjects;
- }
- public void Monitor(params double[] feedBacks)
- {
- if (_toleranceObjects == null)
- {
- return;
- }
- for (int i = 0; i < _toleranceObjects.Count; i++)
- {
- if (_stopwatch.ElapsedMilliseconds > _toleranceObjects[i].DelayTime)
- {
- if ((feedBacks[i] < _toleranceObjects[i].WarningMin || feedBacks[i] > _toleranceObjects[i].WarningMax) && _toleranceObjects[i].WarningFlag == false)
- {
- _toleranceObjects[i].WarningFlag = true;
- LOG.Write(eEvent.WARN_PM_TOLERANCE, _Module, $"{_toleranceObjects[i].Name}:Currnt Value:{feedBacks[i]},Over Range {_toleranceObjects[i].WarningMin}-{_toleranceObjects[i].WarningMax}");
- }
- if ((feedBacks[i] < _toleranceObjects[i].AlarmMin || feedBacks[i] > _toleranceObjects[i].AlarmMax) && _toleranceObjects[i].AlarmFlag == false && _toleranceObjects[i].WarningFlag == true)
- {
- _toleranceObjects[i].AlarmFlag = true;
- LOG.Write(eEvent.ERR_PM_TOLERANCE, _Module, $"{_toleranceObjects[i].Name}:Currnt Value:{feedBacks[i]},Over Range {_toleranceObjects[i].AlarmMin}-{_toleranceObjects[i].AlarmMax}");
- }
- }
- }
- }
- public void End()
- {
- _stopwatch.Stop();
- }
- }
- public class ToleranceObject
- {
- public string Name { get; set; }
- public int SetPoint { get; set; }
- public int WarningScale { get; set; }
- public int AlarmScale { get; set; }
- public bool WarningFlag { get; set; }
- public bool AlarmFlag { get; set; }
- public int DelayTime { get; set; }
- public int WarningMax { get; set; }
- public int WarningMin { get; set; }
- public int AlarmMax { get; set; }
- public int AlarmMin { get; set; }
- public ToleranceObject(string name, int setPoint, int warningScale, int alarmScale, int delayTime, ToleranceMode toleranceMode)
- {
- Name = name;
- SetPoint = setPoint;
-
- DelayTime = delayTime;
- if (toleranceMode == ToleranceMode.Percent)
- {
- WarningScale = SetPoint * warningScale / 100;
- AlarmScale = SetPoint * alarmScale / 100;
- }
- else
- {
- WarningScale = warningScale;
- AlarmScale = alarmScale;
- }
- WarningMax = setPoint + WarningScale;
- WarningMin = setPoint - WarningScale;
- AlarmMax = setPoint + AlarmScale;
- AlarmMin = setPoint - AlarmScale;
- }
- }
- }
|