| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 | 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 Aitex.Core.RT.SCCore;using Aitex.Core.RT.Tolerance;using MECF.Framework.Common.Communications;using MECF.Framework.Common.DataCenter;using MECF.Framework.Common.Device.Bases;using MECF.Framework.Common.Equipment;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.Threading.Tasks;using Venus_Core;namespace Venus_RT.Devices{    public class TruPlasmaRF : RfPowerBase    {        private readonly AsyncSerialPort _serial;        public TruPlasmaRF(ModuleName mod, VenusDevice device) : base(mod.ToString(), device.ToString())        {            var portNum = SC.GetStringValue(device == VenusDevice.Rf ? $"{mod}.Rf.Port" : $"{mod}.BiasRf.Port");            _serial = new AsyncSerialPort(portNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r\r");        }        public override bool Initialize()        {            base.Initialize();                       if (_serial.Open())            {                _serial.OnDataChanged += SerialPortDataReceived;                _serial.OnErrorHappened += SerialPortErrorOccurred;            }            else            {                LOG.Write(eEvent.ERR_RF, Module, "Tru 射频发生器串口无法打开");                return false;            }                     return true;        }        private void SerialPortDataReceived(string str)        {        }        private void SerialPortErrorOccurred(string obj)        {            LOG.Write(eEvent.ERR_RF, Module, $"Tru 射频串口出错, [{obj}]");        }        public override void SetPower(float val)        {            var power = !_scEnableCalibration.BoolValue ? val : CalibrationData(val, true);            List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x06, 0x00, 0x01, 0x00, 0x04 };            byte[] valueBytes = BitConverter.GetBytes((int)val);            baseBytes.AddRange(valueBytes);            baseBytes = CRC16(baseBytes.ToArray());            baseBytes.Add(0x55);            _serial.Write(baseBytes.ToArray());        }        public override bool SetPowerOnOff(bool on, out string str)        {            str = "";            var _chamber = DEVICE.GetDevice<JetPMBase>(Module);            if (on && !_chamber.CheckGeneratorAndHVInterlock(VenusDevice.Rf))            {                return false;            }            List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6F, 0x00, 0x01, 0x00, 0x07 };            if (on == true)            {                baseBytes.AddRange(new List<byte> { 0x01, 0x00, 0x00, 0x00 });            }            else            {                baseBytes.AddRange(new List<byte> { 0x00, 0x00, 0x00, 0x00 });            }            baseBytes = CRC16(baseBytes.ToArray());            baseBytes.Add(0x55);            _serial.Write(baseBytes.ToArray());            return true;        }        public override void SetPulseMode(bool on)        {            List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6A, 0x01, 0x01, 0x00, 0x04 };            if (on == true)            {                baseBytes.AddRange(new List<byte> { 0x01, 0x00, 0x00, 0x00 });            }            else            {                baseBytes.AddRange(new List<byte> { 0x00, 0x00, 0x00, 0x00 });            }            baseBytes = CRC16(baseBytes.ToArray());            baseBytes.Add(0x55);            _serial.Write(baseBytes.ToArray());        }        public override void SetPulseRateFreq(int nFreq)        {            if (nFreq > 0)            {                              List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6C, 0x01, 0x01, 0x00, 0x04 };                byte[] valueBytes = BitConverter.GetBytes(nFreq);                baseBytes.AddRange(valueBytes);                baseBytes = CRC16(baseBytes.ToArray());                baseBytes.Add(0x55);                _serial.Write(baseBytes.ToArray());            }            else            {                LOG.Write(eEvent.ERR_RF, Module, $"{Name},SetPulseRateFreq() parameter error: {nFreq}");            }        }        public override void SetPulseDutyCycle(int percentage)        {            if (percentage >= 10 && percentage <= 90)            {                List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6D, 0x01, 0x01, 0x00, 0x04 };                byte[] valueBytes = BitConverter.GetBytes(percentage);                baseBytes.AddRange(valueBytes);                baseBytes = CRC16(baseBytes.ToArray());                baseBytes.Add(0x55);                _serial.Write(baseBytes.ToArray());            }            else            {                LOG.Write(eEvent.ERR_RF, Module, $"{Name},SetPulseDutyCycle() parameter error: {percentage}");            }        }        #region 霍廷格RF协议crc-16/CCITT-FALSE校验        private bool CRC16(byte[] buffer, ref byte[] ResCRC16)  // crc-16/CCITT-FALSE,判断校验        {            bool status = false;            ushort crc = 0xFFFF;            int size = buffer.Length;  //计算待计算的数据长度            int i = 0;            if (size > 0)            {                while (size-- > 0)                {                    crc = (ushort)((crc >> 8) | (crc << 8));                    crc ^= buffer[i++];                    crc ^= (ushort)(((byte)crc) >> 4);                    crc ^= (ushort)(crc << 12);                    crc ^= (ushort)((crc & 0xff) << 5);                }            }            //判断输入的ResCRC16与计算出来的是否一致            if (ResCRC16[0] == (byte)((crc >> 8) & 0xff) && ResCRC16[1] == (byte)(crc & 0xff))            {                status = true;            }            return status;        }        private List<byte> CRC16(byte[] buffer)  // crc-16/CCITT-FALSE,补全两个字节        {            ushort crc = 0xFFFF;            int size = buffer.Length;  //计算待计算的数据长度            int i = 0;            if (size > 0)            {                while (size-- > 0)                {                    crc = (ushort)((crc >> 8) | (crc << 8));                    crc ^= buffer[i++];                    crc ^= (ushort)(((byte)crc) >> 4);                    crc ^= (ushort)(crc << 12);                    crc ^= (ushort)((crc & 0xff) << 5);                }            }            var byteList = buffer.ToList();            byteList.Add((byte)(crc & 0xff));            byteList.Add((byte)((crc >> 8) & 0xff));            return byteList;        }        #endregion    }}
 |