123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.Simulator;
- using Aitex.Core.Util;
- using Aitex.Triton160.RT.PLC;
- using Aitex.Triton160.RT.Simulator;
- namespace Aitex.Jet.RT.Simulator
- {
- class SimulatorTriton160 : ISimulatorManager
- {
- private Random _rd = new Random();
- private PeriodicJob _thread;
- SimulatorBuffer _bufferLocal = new SimulatorBuffer();
- public SimulatorTriton160()
- {
- _bufferLocal.Initialize(Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.DI),
- Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.DO),
- Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.AI),
- Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.AO));
- SimulatorCaseManager.Instance.Initialize();
- SetDefaultValue();
- _thread = new PeriodicJob(200, Monitor, "SimulatorTriton160", true);
- }
- public object Read(string type)
- {
- if (type == "local")
- return _bufferLocal.Input;
- return null;
- }
- public bool Write(string type, PLC_OUTPUT_DATA buffer)
- {
- if (type == "local")
- return _bufferLocal.Write(buffer);
- return true;
- }
- private bool Monitor()
- {
- foreach (var forces in DiForce.Instance.ForceValues)
- {
- _bufferLocal.SetDI(forces.Key, forces.Value ? (byte)1 : (byte)0);
- }
- foreach (var forces in AiForce.Instance.ForceValues)
- {
- _bufferLocal.SetAI(forces.Key, forces.Value);
- }
- try
- {
- MonitorValve();
- MonitorRf();
- MonitorPressure();
- MonitorFlowRamp();
- MonitorDryPump();
- MonitorSensor();
- MonitorSystem();
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- return true;
- }
- private void MonitorSystem()
- {
- if (!ExceptionCase.ExLostHeartBeat)
- {
- _bufferLocal.SetAI(IoNameTriton160.AI_heartbeat_fb, _bufferLocal.GetAO(IoNameTriton160.AO_heartbeat));
- }
- //_bufferLocal.SetDI(IoNameTriton160.DI_pump_door_sw, ExceptionCase.ExPumpDoorOpened ? (byte)0 : (byte)1);
- //_bufferLocal.SetDI(IoNameTriton160.DI_back_panle_door_sw, ExceptionCase.ExBackPanelDoorOpened ? (byte)0 : (byte)1);
- _bufferLocal.SetDI(IoNameTriton160.DI_Chamber_door_sw, ExceptionCase.ExChamberDoorOpend ? (byte)0 : (byte)1);
- _bufferLocal.SetDI(IoNameTriton160.DI_Main_conctactor, ExceptionCase.ExMainContactorOff ? (byte)0 : (byte)1);
- _bufferLocal.SetDI(IoNameTriton160.DI_EMG_stop_botton, ExceptionCase.ExEmoButtonPushed ? (byte)1 : (byte)0);
- var signalLight = new List<Tuple<string, string>>
- {
- new Tuple<string, string>(IoNameTriton160.DI_Red_light_fb, IoNameTriton160.DO_Red_light),
- new Tuple<string, string>(IoNameTriton160.DI_Green_light_fb, IoNameTriton160.DO_Green_light),
- new Tuple<string, string>(IoNameTriton160.DI_Yellow_light_fb, IoNameTriton160.DO_Yellow_light),
- new Tuple<string, string>(IoNameTriton160.DI_Buzzer_fb, IoNameTriton160.DO_Buzzer),
- };
- foreach (var s in signalLight)
- {
- _bufferLocal.SetDI(s.Item1, _bufferLocal.GetDO(s.Item2));
- }
- _bufferLocal.SetAI(IoNameTriton160.AI_Time, DateTime.Now.Hour);
- _bufferLocal.SetAI(IoNameTriton160.AI_Minute, DateTime.Now.Minute);
- _bufferLocal.SetAI(IoNameTriton160.AI_Second, DateTime.Now.Second);
- }
- void SetDefaultValue()
- {
- _bufferLocal.SetAI(IoNameTriton160.AI_Thorttle_valve_real_position_fb, 100);
- _bufferLocal.SetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_, 50000);
- _bufferLocal.SetAI(IoNameTriton160.AI_Year, DateTime.Now.Year - IoPlcDateTime.YEAR_OFFSET);
- _bufferLocal.SetAI(IoNameTriton160.AI_Month, DateTime.Now.Month);
- _bufferLocal.SetAI(IoNameTriton160.AI_Day, DateTime.Now.Day);
- _bufferLocal.SetDI(IoNameTriton160.DI_Main_conctactor, 1);
- _bufferLocal.SetDI(IoNameTriton160.DI_RF_hardware_interlock, 1);
- _bufferLocal.SetDI(IoNameTriton160.DI_Chamber_door_sw, 1);
- //_bufferLocal.SetDI(IoNameTriton160.DI_pump_door_sw, 1);
- //_bufferLocal.SetDI(IoNameTriton160.DI_back_panle_door_sw, 1);
- _bufferLocal.SetAI(IoNameTriton160.AI_thorttle_valve_state, 1);
- _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_running, 1);
- _bufferLocal.SetAI(IoNameTriton160.AI_Lever1_pump__water_flow_fb, 30);
- _bufferLocal.SetAI(IoNameTriton160.AI_match_work_mode_fb, 0);
- _bufferLocal.SetAI(IoNameTriton160.AI_match_hold_or_preset_fb, 0);
- }
- #region valve
- void MonitorValve()
- {
- var valveList = new List<Tuple<string, string>>
- {
- new Tuple<string, string>(
- IoNameTriton160.DI_MFC1_valve_state_fb,
- IoNameTriton160.DO_MFC1_valve__
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_MFC2_valve_state_fb,
- IoNameTriton160.DO_MFC2_valve
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_MFC3_valve_state_fb,
- IoNameTriton160.DO_MFC3_valve
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_MFC4_valve_state_fb,
- IoNameTriton160.DO_MFC4_valve
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_MFC5_valve_state_fb,
- IoNameTriton160.DO_MFC5_valve
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_Chamber_purge_valve_state_fb,
- IoNameTriton160.DO_Chamber_purge_valve
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_Process_gas_final_valve_state_fb,
- IoNameTriton160.DO_Process_gas_final_valve
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_Pumping_valve_state_fb,
- IoNameTriton160.DO_Pumping_valve_
- ),
- new Tuple<string, string>(
- IoNameTriton160.DI_Chamber_vent_valve_state_fb,
- IoNameTriton160.DO_Chamber_vent_valve
- ),
- };
- foreach (var valve in valveList)
- {
- _bufferLocal.SetDI(valve.Item1, _bufferLocal.GetDO(valve.Item2));
- }
- }
- #endregion
- void MonitorPressure()
- {
- bool IsPumpingValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Pumping_valve_state_fb) == 1;
- bool IsPurgeValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Chamber_purge_valve_state_fb) == 1;
- bool IsGasFinalValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Process_gas_final_valve_state_fb) == 1;
- bool IsVentValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Chamber_vent_valve_state_fb) == 1;
- bool IsPumpOn = _bufferLocal.GetDI(IoNameTriton160.DI_Lever1_pump_running) == 1;
- double pressureStep = (750000.0 / 5.0) / 30.0;
- if (IsPumpOn && IsPumpingValveOpen)
- {
- double pressure = _bufferLocal.GetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_);
- pressure -= pressureStep;
- if (pressure < 100)
- pressure = 100;
- pressure += (_rd.Next(0, 20) - 10);
- _bufferLocal.SetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_, (float)pressure);
- }
- if ((IsPurgeValveOpen && IsGasFinalValveOpen) || IsVentValveOpen)
- {
- double pressure = _bufferLocal.GetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_);
- pressure += pressureStep;
- if (pressure > 756000)
- pressure = 756000;
- pressure += (_rd.Next(0, 20) - 10);
- _bufferLocal.SetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_, (float)pressure);
- }
- }
- void MonitorFlowRamp()
- {
- var rampList = new List<Tuple<string, string>>
- {
- new Tuple<string, string>(
- IoNameTriton160.AI_MFC1_real_flow__fb,
- IoNameTriton160.AO_MFC1_flow_setpoint
- ),
- new Tuple<string, string>(
- IoNameTriton160.AI_MFC2_real_flow_fb,
- IoNameTriton160.AO_MFC2_flow_setpoint
- ),
- new Tuple<string, string>(
- IoNameTriton160.AI_MFC3_real_flow_fb,
- IoNameTriton160.AO_MFC3_flow_setpoint
- ),
- new Tuple<string, string>(
- IoNameTriton160.AI_MFC4_real_flow_fb,
- IoNameTriton160.AO_MFC4_flow_setpoint
- ),
- new Tuple<string, string>(
- IoNameTriton160.AI_MFC5_real_flow_fb,
- IoNameTriton160.AO_MFC5_flow_setpoint
- ),
- };
- foreach (var item in rampList)
- {
- float setpoint = 0;
- float result = 0;
- float current = 0;
- if (_bufferLocal.FindAI(item.Item1) != null)
- {
- current = _bufferLocal.GetAI(item.Item1);
- setpoint = _bufferLocal.GetAO(item.Item2);
- }
- else if (_bufferLocal.FindAI(item.Item1) != null)
- {
- current = _bufferLocal.GetAI(item.Item1);
- setpoint = _bufferLocal.GetAO(item.Item2);
- }
- if (current > setpoint)
- {
- result = current - 20;
- if (result < setpoint)
- result = setpoint;
- }
- if (current < setpoint)
- {
- result = current + 20;
- if (result > setpoint)
- result = setpoint;
- }
- result = result + (float)_rd.NextDouble();
- _bufferLocal.SetAI(item.Item1, result);
- _bufferLocal.SetAI(item.Item1, result);
- }
- }
- #region RF
- void MonitorRf()
- {
- _bufferLocal.SetDI(IoNameTriton160.DI_RF_power_state_fb, _bufferLocal.GetDO(IoNameTriton160.DO_RF_on_off));
- _bufferLocal.SetAI(IoNameTriton160.AI_match_work_mode_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_work_mode_setpoint));
- _bufferLocal.SetAI(IoNameTriton160.AI_match_hold_or_preset_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_hold_or_preset_setpoint));
- _bufferLocal.SetAI(IoNameTriton160.AI_match_c1_positon_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_C1_position_setpoint));
- _bufferLocal.SetAI(IoNameTriton160.AI_match_c2_positon_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_C2_position_setpoint));
- float setpoint = _bufferLocal.GetAO(IoNameTriton160.AO_RF_power_setpoint);
- bool isOn = _bufferLocal.GetDI(IoNameTriton160.DI_RF_power_state_fb) == 1;
- if (!isOn)
- {
- _bufferLocal.SetAI(IoNameTriton160.AI_RF_forward_power_fb, 0);
- _bufferLocal.SetAI(IoNameTriton160.AI_RF_reflect_power_fb, 0);
- return;
- }
- double step = (900.0 / 5.0) / 10.0;
- double feedback = _bufferLocal.GetAI(IoNameTriton160.AI_RF_forward_power_fb);
- feedback += step;
- if (feedback > setpoint * 0.9)
- feedback = (setpoint * 0.9);
- _bufferLocal.SetAI(IoNameTriton160.AI_RF_forward_power_fb, (float)feedback);
- double step1 = (100.0 / 5.0) / 10.0;
- feedback = _bufferLocal.GetAI(IoNameTriton160.AI_RF_reflect_power_fb);
- feedback = feedback + step1;
- if (feedback > setpoint * 0.1)
- feedback = (float)(setpoint * 0.1);
- _bufferLocal.SetAI(IoNameTriton160.AI_RF_reflect_power_fb, (float)feedback);
- }
- #endregion
- void MonitorDryPump()
- {
- _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_start_bt, 1);
- _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_stop_bt, 0);
- _bufferLocal.SetAI(IoNameTriton160.AI_Lever1_N2_pressure_fb, (float)(_rd.NextDouble()));
- _bufferLocal.SetAI(IoNameTriton160.AI_Lever1_pump__water_flow_fb, (float)(80 + _rd.Next(5) + _rd.NextDouble()));
- }
- private void MonitorSensor()
- {
- int simValue = (int)_bufferLocal.GetAO(IoNameTriton160.AO_match_C1_position_setpoint);
- if (simValue == 51)
- {
- _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_overload, 1);
- }
- if (simValue == 52)
- {
- //_bufferLocal.SetDI(IoNameTriton160.DI_booster_inv_alarm, 1);
- }
- if (simValue == 59)
- {
- _bufferLocal.SetDI(IoNameTriton160.DI_Pump_N2_pressure_alam, 1);
- _bufferLocal.SetDI(IoNameTriton160.DI_Pump_water_flow_alam, 1);
- }
- }
- }
- }
|