| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 | using Aitex.Core.Common.DeviceData;using Aitex.Core.RT.DataCenter;using Aitex.Core.RT.Device;using Aitex.Core.RT.Log;using Aitex.Core.RT.OperationCenter;using MECF.Framework.Common.Device.Bases;using MECF.Framework.Common.Equipment;using System;using System.Diagnostics;using Venus_Core;using Venus_RT.Devices.AdLinkEthercat;namespace Venus_RT.Devices{    public class TruPlasmaRF_Ethercat : RfPowerBase    {        //Int32 v_card_name = 0;        Int32 v_board_id = -1;        //Int32 v_StartAxisID = 0;        Int32 BUS_No = 0;        Int32 Mod_ID = 0;        private readonly VenusDevice _device;        private Stopwatch _stopWatch = new Stopwatch();        private JetPMBase _chamber;        public new AITRfData DeviceData =>            new AITRfData            {                Module = Module,                DeviceName = Name,                ScalePower = ScalePower,                ForwardPower = ForwardPower,                ReflectPower = ReflectPower,                IsRfOn = IsPowerOn,                PowerSetPoint = PowerSetPoint,            };        public TruPlasmaRF_Ethercat(ModuleName mod, VenusDevice device, Int32 board_id) : base(mod.ToString(), device.ToString())        {            _device = device;            v_board_id = board_id;            _stopWatch.Start();            _chamber = DEVICE.GetDevice<JetPMBase>(Module);        }        public override bool Initialize()        {            base.Initialize();            DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);            OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetPowerOnOff}", (out string reason, int time, object[] param) =>            {                SetPowerOnOff(Convert.ToBoolean((string)param[0]), out reason);                return true;            });            OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetPower}", (out string reason, int time, object[] param) =>            {                reason = "";                ushort val = Convert.ToUInt16(param[0]);                SetPower(val);                return true;            });            return true;        }        public override void Monitor()        {            if (_stopWatch.ElapsedMilliseconds > 50)            {                IsPowerOn = GetPowerOnOff();                ForwardPower = GetPower();                ReflectPower=GetReflectPower();                _stopWatch.Restart();                if (IsPowerOn == true && _chamber != null && _chamber.RFInterlock(_device) == false)                {                    SetPowerOnOff(false, out _);                }            }        }        public override bool SetPowerOnOff(bool on, out string str)        {            str = "";            Int32 ret;            UInt16 ByteOffset = 0;            UInt16 Size = 1;            uint Value = 0;            string operation;            if (on)            {                operation = "ON";                Value = 1;                ret = APS168.APS_set_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, Value);            }            else            {                operation = "OFF";                ret = APS168.APS_set_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, Value);            }            if (ret != 0)            {                LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Power {operation} Fail!");            }            else            {                LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Power {operation} Success!");            }            return true;        }        public  bool GetPowerOnOff()        {            Int32 ret;            UInt16 ByteOffset = 0;            UInt16 Size = 1;            uint Value = 0;            ret = APS168.APS_get_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, ref Value);            if (ret != 0)            {                LOG.Write(eEvent.ERR_RF, Module, $"{_device} Get Power ON/OFF Fail!");            }            else            {                //LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Get Power ON/OFF Success!");                if (Value == 3)                {                    return true;                }            }            return false;        }        public override void SetPower(float val)        {            Int32 ret;            UInt16 ByteOffset = 2;            UInt16 Size = 4;            uint Value = 0;            byte[] byteArray = BitConverter.GetBytes(val);            Value = BitConverter.ToUInt32(byteArray, 0);            ret = APS168.APS_set_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, Value);            if (ret != 0)            {                LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Power Setpoint {val} Fail!");            }            else            {                PowerSetPoint = val;                LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Power Setpoint {val} Success!");            }        }        public float GetPower()        {            Int32 ret;            Int32 BUS_No = 0;            UInt16 ByteOffset = 6;            UInt16 Size = 4;            uint Value = 0;            ret = APS168.APS_get_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, ref Value);            if (ret != 0)            {                LOG.Write(eEvent.ERR_RF, Module, $"{_device} Get Power Setpoint  Fail!");            }            else            {                //LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Get Power Setpoint  Success!");            }            return  BitConverter.ToSingle(BitConverter.GetBytes(Value), 0);         }        public float GetReflectPower()        {            Int32 ret;            Int32 BUS_No = 0;            UInt16 ByteOffset = 10;            UInt16 Size = 4;            uint Value = 0;            ret = APS168.APS_get_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, ref Value);            if (ret != 0)            {                //LOG.Write(eEvent.ERR_RF, Module, $"{_device} Get Reflect Power Fail");            }            else            {                return BitConverter.ToSingle(BitConverter.GetBytes(Value), 0); ;            }            return -1;        }        public override void SetPulseMode(bool on)        {            Int32 ret = 0;            Byte[] Data = new Byte[32];            UInt16 OD_index = 0x7001;            UInt16 OD_Subindex = 1;            UInt32 DataLength = 1;            UInt32 TimeOut = 10000;            Int32 Datatemp;            UInt32 Flags = 0;            string operation;            if (on)            {                operation = "Enable";                Datatemp = 1;            }            else            {                operation = "Disable";                Datatemp = 0;            }            for (Int32 i = 0; i < 8; i++)            {                Data[i] = (Byte)((Datatemp >> (i * 8)) & 0xFF);            }            ret = APS168.APS_set_field_bus_sdo(v_board_id, BUS_No, Mod_ID, OD_index, OD_Subindex, Data, DataLength, TimeOut, Flags);            if (ret != 0)            {                LOG.Write(eEvent.ERR_RF, Module, $"{_device} {operation} Pulsing Mode Fail!");            }            else            {                LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} {operation} Pulsing Mode Success!");            }        }        public override void SetPulseRateFreq(int nFreq)        {            if (nFreq < 0)            {                return;            }            float f = Convert.ToSingle(nFreq);            Int32 ret = 0;            Byte[] Data = new Byte[32];            UInt16 OD_index = 0x7008;            UInt16 OD_Subindex = 1;            UInt32 DataLength = 32;            UInt32 TimeOut = 10000;            UInt32 Flags = 0;            Data = BitConverter.GetBytes(f);            ret = APS168.APS_set_field_bus_sdo(v_board_id, BUS_No, Mod_ID, OD_index, OD_Subindex, Data, DataLength, TimeOut, Flags);            if (ret != 0)            {                LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Pulse Rate Freq{nFreq} Fail!");            }            else            {                LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Pulse Rate Freq{nFreq} Success!");            }        }        public override void SetPulseDutyCycle(int percentage)        {            if (percentage <= 10 && percentage >= 90)            {                return;            }            float f = Convert.ToSingle(percentage);            Int32 ret = 0;            Byte[] Data = new Byte[32];            UInt16 OD_index = 0x7008;            UInt16 OD_Subindex = 2;            UInt32 DataLength = 32;            UInt32 TimeOut = 10000;            UInt32 Flags = 0;            Data = BitConverter.GetBytes(f);            ret = APS168.APS_set_field_bus_sdo(v_board_id, BUS_No, Mod_ID, OD_index, OD_Subindex, Data, DataLength, TimeOut, Flags);            if (ret != 0)            {                LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Pulse Duty Cycle {percentage} Fail!");            }            else            {                LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Pulse Duty Cycle {percentage} Success!");            }        }    }}
 |