|
@@ -14,6 +14,7 @@ using MECF.Framework.Common.Equipment;
|
|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
using Venus_Core;
|
|
@@ -245,4 +246,307 @@ namespace Venus_RT.Devices
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
+ static class TruPlasmaMatchMessage
|
|
|
+ {
|
|
|
+ public const string PRESET = "G";
|
|
|
+ public const string AUTO = "L";
|
|
|
+ public const string MANUAL = "M";
|
|
|
+ public const string PRESET_MEM = "P";
|
|
|
+ public const string START_QUERY = "S3";
|
|
|
+ public const string STOP_QUERY = "SP";
|
|
|
+ public const string WRITE_POS = "$APGR";
|
|
|
+ public const string READ_POS = "$APRR";
|
|
|
+ }
|
|
|
+
|
|
|
+ class TruPlasmaMatch : RfMatchBase
|
|
|
+ {
|
|
|
+ private readonly AsyncSerialPort _serial;
|
|
|
+ private const ushort S3_HEAD_LENGTH = 2;
|
|
|
+ private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
|
|
|
+ private int QUERY_INTERVAL = 1000;
|
|
|
+ //private int _scMatchPresetMode;
|
|
|
+ //private int _scMatchMode;
|
|
|
+ //private readonly SCConfigItem _scMatchPositionC1;
|
|
|
+ //private readonly SCConfigItem _scMatchPositionC2;
|
|
|
+ //private readonly bool _scEnableC1C2Position;
|
|
|
+
|
|
|
+ // --------------------------Properties------------------------
|
|
|
+ //
|
|
|
+ [Subscription("MatchWorkMode")]
|
|
|
+ public EnumRfMatchTuneMode WorkMode { get; set; }
|
|
|
+ public float C1 { get; set; }
|
|
|
+ public float C2 { get; set; }
|
|
|
+
|
|
|
+ //[Subscription("VPP")]
|
|
|
+ public ushort VPP { get; set; }
|
|
|
+ public new AITMatchData DeviceData
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return new AITMatchData
|
|
|
+ {
|
|
|
+ Module = Module,
|
|
|
+ DeviceName = Name,
|
|
|
+ WorkMode = WorkMode.ToString(),
|
|
|
+ C1 = TunePosition1,
|
|
|
+ C2 = TunePosition2,
|
|
|
+ VPP = "",
|
|
|
+ DCBias = DCBias.ToString()
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public TruPlasmaMatch(ModuleName mod, VenusDevice device) : base(mod.ToString(), device.ToString())
|
|
|
+ {
|
|
|
+ var portNum = SC.GetStringValue($"{mod}.{device}.Port");
|
|
|
+
|
|
|
+ _serial = new AsyncSerialPort(portNum, 9600, 8);
|
|
|
+
|
|
|
+ //_scMatchPresetMode = SC.GetValue<int>($"{Module}.Rf.PresetMode");
|
|
|
+ //_scMatchMode = SC.GetValue<int>($"{Module}.Rf.MatchMode");
|
|
|
+ //_scMatchPositionC1 = SC.GetConfigItem($"{Module}.Rf.MatchPositionC1");
|
|
|
+ //_scMatchPositionC2 = SC.GetConfigItem($"{Module}.Rf.MatchPositionC2");
|
|
|
+ //_scEnableC1C2Position = SC.GetValue<bool>($"{Module}.Rf.EnableC1C2Position");
|
|
|
+ SerachCommandList = new List<string>()
|
|
|
+ {
|
|
|
+ AdTecMatchMessage.READ_POS,
|
|
|
+ AdTecMatchMessage.START_QUERY
|
|
|
+ };
|
|
|
+ intervalTime = 100;
|
|
|
+ sendDataChangedEvent += TruMatch_sendDataChangedEvent;
|
|
|
+ baseStopwatch.Start();
|
|
|
+ baseTimer.Enabled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TruMatch_sendDataChangedEvent(string obj)
|
|
|
+ {
|
|
|
+ this.SendCmd(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ ~TruPlasmaMatch()
|
|
|
+ {
|
|
|
+ _serial?.Close();
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool Initialize()
|
|
|
+ {
|
|
|
+ base.Initialize();
|
|
|
+
|
|
|
+ if (_serial.Open())
|
|
|
+ {
|
|
|
+ _serial.OnBinaryDataChanged += SerialBinaryPortDataReceived;
|
|
|
+ _serial.OnErrorHappened += SerialPortErrorOccurred;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LOG.Write(eEvent.ERR_RF, Module, "Match 串口无法打开");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ DATA.Subscribe($"{Module}.{Name}.C1", () => TunePosition1);
|
|
|
+ DATA.Subscribe($"{Module}.{Name}.C2", () => TunePosition2);
|
|
|
+ DATA.Subscribe($"{Module}.{Name}.WorkMode", () => WorkMode.ToString());
|
|
|
+
|
|
|
+
|
|
|
+ OP.Subscribe($"{Module}.{Name}.SetC1", (func, args) =>
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ OP.Subscribe($"{Module}.{Name}.SetC2", (func, args) =>
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC1}", (out string reason, int time, object[] param) =>
|
|
|
+ {
|
|
|
+ SetMatchPositionC1((float)Convert.ToDouble(param[0]), out reason);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC2}", (out string reason, int time, object[] param) =>
|
|
|
+ {
|
|
|
+ SetMatchPositionC2((float)Convert.ToDouble(param[0]), out reason);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPosition}", (out string reason, int time, object[] param) =>
|
|
|
+ {
|
|
|
+ SetMatchPosition((float)Convert.ToDouble(param[0]), (float)Convert.ToDouble(param[1]), out reason);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchProcessMode}", (out string reason, int time, object[] param) =>
|
|
|
+ {
|
|
|
+ SetMatchMode((string)param[0] == "Auto" ? EnumRfMatchTuneMode.Auto : EnumRfMatchTuneMode.Manual, out reason);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ _timerQueryStatus.Start(QUERY_INTERVAL);
|
|
|
+ this.SendCmd(AdTecMatchMessage.START_QUERY);
|
|
|
+
|
|
|
+ //LOG.Write(eEvent.ERR_RF, Module, "Initialize done.");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Monitor()
|
|
|
+ {
|
|
|
+ //try
|
|
|
+ //{
|
|
|
+ // if (_timerQueryStatus.IsTimeout())
|
|
|
+ // {
|
|
|
+ // this.SendCmd(AdTecMatchMessage.READ_POS);
|
|
|
+ // _timerQueryStatus.Start(QUERY_INTERVAL);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //catch (Exception ex)
|
|
|
+ //{
|
|
|
+ // LOG.WriteExeption(ex);
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Terminate()
|
|
|
+ {
|
|
|
+ this.SendCmd(AdTecMatchMessage.STOP_QUERY);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Reset()
|
|
|
+ {
|
|
|
+ //SendCmd(AdTecMatchMessage.STOP_QUERY);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="c1,c2">百分比数字</param>
|
|
|
+ /// <param name="c2"></param>
|
|
|
+ ///
|
|
|
+ private void executeMatchPostion(float c1, float c2)
|
|
|
+ {
|
|
|
+ //SetWorkMode(EnumRfMatchTuneMode.Manual);
|
|
|
+ ////await Task.Delay(200);
|
|
|
+
|
|
|
+ SetPosition(c1, c2);
|
|
|
+ //await Task.Delay(200);
|
|
|
+
|
|
|
+ //SetPresetMemory(0);
|
|
|
+ //await Task.Delay(200);
|
|
|
+ // SetWorkMode(EnumRfMatchTuneMode.Auto);
|
|
|
+ }
|
|
|
+ public override void SetMatchPosition(float c1, float c2, out string reason)
|
|
|
+ {
|
|
|
+ float DataValue = BitConverter.ToSingle(new byte[] { 0x9A, 0x99, 0x19,0x3F }, 0);
|
|
|
+ byte[] floatAsBytes = BitConverter.GetBytes(DataValue);
|
|
|
+ float DataValue1= BitConverter.ToSingle(new byte[] { floatAsBytes[0], floatAsBytes[1], floatAsBytes[2], floatAsBytes[3] }, 0);
|
|
|
+ //LOG.Write(eEvent.WARN_RF, Module, $"AdTec Match error [{c1}, {c2}]");
|
|
|
+
|
|
|
+ base.SetMatchPosition(c1, c2, out reason);
|
|
|
+
|
|
|
+ executeMatchPostion(c1, c2);
|
|
|
+
|
|
|
+ reason = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetPresetMode(RfMatchPresetMode mode)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ // -----------------------Private Method-------------------------
|
|
|
+ //
|
|
|
+ private void SerialBinaryPortDataReceived(byte[] message)
|
|
|
+ {
|
|
|
+ if(message.Count()==0)
|
|
|
+ {
|
|
|
+ LOG.Write(eEvent.ERR_RF, Module, "收到 Match 数据为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (message[0] ==0x1D && message[6]==0x60 && message[7] == 0x00)
|
|
|
+ {
|
|
|
+ this.TunePosition1 = BitConverter.ToSingle(new byte[] { message[10], message[11], message[12], message[13] }, 0) * 10;
|
|
|
+ this.TunePosition2 = BitConverter.ToSingle(new byte[] { message[14], message[15], message[16], message[17] }, 0) * 10;
|
|
|
+ switch (message[7])
|
|
|
+ {
|
|
|
+ case 0x01:
|
|
|
+ this.WorkMode = EnumRfMatchTuneMode.Manual;
|
|
|
+ break;
|
|
|
+ case 0x02:
|
|
|
+ this.WorkMode = EnumRfMatchTuneMode.Auto;
|
|
|
+ break;
|
|
|
+ case 0x20:
|
|
|
+ this.WorkMode = EnumRfMatchTuneMode.Undefined;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void SerialPortErrorOccurred(string str)
|
|
|
+ {
|
|
|
+ LOG.Write(eEvent.ERR_RF, Module, $"AdTec Match error [{str}]");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SendCmd(string str)
|
|
|
+ {
|
|
|
+ _serial?.Write(str + "\r");
|
|
|
+ //EV.PostInfoLog(Module.ToString(), $"Match send [{str}]");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetPosition(float c1val, float c2val)
|
|
|
+ {
|
|
|
+
|
|
|
+ List<byte> Len = new List<byte>() { 0x16, 0xE9};
|
|
|
+ List<byte> DstSrc = new List<byte>() { 0x00, 0x0A, 0x00, 0x00};
|
|
|
+ List<byte> Cmd = new List<byte> { 0x60, 0x40 };
|
|
|
+ byte[] val1Bytes = BitConverter.GetBytes(c1val / 100);
|
|
|
+ byte[] val2Bytes = BitConverter.GetBytes(c2val / 100);
|
|
|
+ List<byte> Act = new List<byte>() { 0x64 };
|
|
|
+ List<byte> Ctr123 = new List<byte> { 0x08, 0x01, 0x80 };
|
|
|
+ List<byte> baseBytes = new List<byte>() { };
|
|
|
+ baseBytes.AddRange(Len);
|
|
|
+ baseBytes.AddRange(DstSrc);
|
|
|
+ baseBytes.AddRange(Cmd);
|
|
|
+ baseBytes.AddRange(val1Bytes);
|
|
|
+ baseBytes.AddRange(val2Bytes);
|
|
|
+ baseBytes.AddRange(Act);
|
|
|
+ baseBytes.AddRange(Ctr123);
|
|
|
+ byte ack=0x00;
|
|
|
+ for (int i=2; i< baseBytes.Count;i++)
|
|
|
+ {
|
|
|
+ ack += baseBytes[i];
|
|
|
+ }
|
|
|
+ baseBytes.Add(ack);
|
|
|
+ //SetPointCommandQueue.Add(cmd);
|
|
|
+ _serial.Write(baseBytes.ToArray());
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool SetMatchMode(EnumRfMatchTuneMode enumRfMatchTuneMode, out string reason)
|
|
|
+ {
|
|
|
+ reason = string.Empty;
|
|
|
+ SetWorkMode(enumRfMatchTuneMode);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetWorkMode(EnumRfMatchTuneMode mode)
|
|
|
+ {
|
|
|
+ //string data = mode == EnumRfMatchTuneMode.Auto ? AdTecMatchMessage.AUTO :
|
|
|
+ // mode == EnumRfMatchTuneMode.Manual ? AdTecMatchMessage.MANUAL : "";
|
|
|
+ //this.SendCmd(mode == EnumRfMatchTuneMode.Auto ? AdTecMatchMessage.AUTO :
|
|
|
+ // mode == EnumRfMatchTuneMode.Manual ? AdTecMatchMessage.MANUAL : "");
|
|
|
+ //SetPointCommandQueue.Add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetPresetMemory(byte gear)
|
|
|
+ {
|
|
|
+ //this.SendCmd(AdTecMatchMessage.PRESET_MEM + gear.ToString());
|
|
|
+ //SetPointCommandQueue.Add(AdTecMatchMessage.PRESET_MEM + gear.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|