123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using System;
- using System.Collections;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.RT.Tolerance;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Device.Bases;
- using MECF.Framework.Common.Equipment;
- using VirgoCommon;
- using VirgoRT.Modules;
- namespace VirgoRT.Devices
- {
- static class RevtechMatchMessage
- {
- public const string QUERY_STATE_INFORMATION = "MATCH:FETCH?";
- public const string SET_C1_POS = "MATCH:POS:C1";
- public const string SET_C2_POS = "MATCH:POS:C2";
- public const string SET_WORK_MODE = "MATCH:MODE";
- public const string PRE_SET = "MATCH:PSET:SET 00";
- }
- public enum MatchCommunicationType
- {
- RS232,
- Ethernet
- }
- class RevtechMatch : RfMatchBase
- {
- private AsyncSocketDevice _socket;
- private MatchCommunicationType _matchCommunicationType;
- private string _address;
- private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
- private int QUERY_INTERVAL = 1000;
- private Dictionary<string, string> _nameMap = new Dictionary<string, string>() {
- {VirgoDevice.Match.ToString(), "match" },
- {VirgoDevice.BiasMatch.ToString(),VirgoDevice.BiasRf.ToString() }
- };
- private Dictionary<string, string> _modeMap = new Dictionary<string, string>() {
- {"Preset", EnumRfMatchTuneMode.Auto.ToString() },
- {"Hold",EnumRfMatchTuneMode.Manual.ToString() }
- };
- [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 override AITRfMatchData DeviceData
- {
- get
- {
- return new AITRfMatchData
- {
- };
- }
- }
- public RevtechMatch(ModuleName mod, string name, string configName = "") : base(mod.ToString(), name)
- {
- _address = SC.GetStringValue($"{mod}.{(string.IsNullOrWhiteSpace(configName) ? name : configName)}.IPAddress");
- _socket = new AsyncSocketDevice(_address);
- _socket.OnDataChanged += new AsyncSocketDevice.MessageHandler(OnDataChanged);
- _socket.OnErrorHappened += _socket_OnErrorHappened;
- }
- private void _socket_OnErrorHappened(ErrorEventArgsDevice args)
- {
- LOG.Error($"{Module} {Name} Error {args.Reason}");
- }
- private void OnDataChanged(byte[] obj)
- {
- try
- {
- string data = System.Text.Encoding.ASCII.GetString(obj);
- if (data.Length < 10 && data.Length > 20)
- {
- return;
- }
- string[] matchData = data.Split(',');
- if (matchData.Length > 13)
- {
- if (matchData[0].Contains("MANUAL") || matchData[0].Contains("AUTO"))
- {
- WorkMode = matchData[0] == "MANUAL" ? EnumRfMatchTuneMode.Manual : EnumRfMatchTuneMode.Auto;
- TunePosition1 = Convert.ToSingle(matchData[8]);
- TunePosition2 = Convert.ToSingle(matchData[7]);
- VPP = Convert.ToUInt16(matchData[12], 16);
- DCBias = Convert.ToSingle(matchData[13]);
- }
- }
- }
- catch
- {
- }
- }
- public override bool Initialize()
- {
- base.Initialize();
- LOG.Info($"{Module} {Name} Revtech match address:[{_address}] connect");
- _socket?.Connect(_address);
- DATA.Subscribe($"{Module}.{Name}.C1", () => TunePosition1);
- DATA.Subscribe($"{Module}.{Name}.C2", () => TunePosition2);
- DATA.Subscribe($"{Module}.{Name}.MatchProcessMode", () => (int)WorkMode);
- 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) =>
- {
- var mode = EnumRfMatchTuneMode.Auto.ToString();
- if (_modeMap.ContainsKey((string)param[0]))
- mode = _modeMap[(string)param[0]];
- SetMatchMode(mode, out reason);
- return true;
- });
- OP.Subscribe($"{Module}.{_nameMap[Name]}.{AITRfOperation.SetMatchProcessMode}", (out string reason, int time, object[] param) =>
- {
- var mode = EnumRfMatchTuneMode.Auto.ToString();
- if (_modeMap.ContainsKey((string)param[0]))
- mode = _modeMap[(string)param[0]];
- SetMatchMode(mode, out reason);
- return true;
- });
- OP.Subscribe($"{Module}.{_nameMap[Name]}.{AITRfOperation.SetMatchPositionC1}", (out string reason, int time, object[] param) =>
- {
- SetMatchPositionC1((float)Convert.ToDouble(param[0]), out reason);
- return true;
- });
- OP.Subscribe($"{Module}.{_nameMap[Name]}.{AITRfOperation.SetMatchPositionC2}", (out string reason, int time, object[] param) =>
- {
- SetMatchPositionC2((float)Convert.ToDouble(param[0]), out reason);
- return true;
- });
- _timerQueryStatus.Start(QUERY_INTERVAL);
- return true;
- }
- public override void Monitor()
- {
- try
- {
- if (_timerQueryStatus.IsTimeout())
- {
- this.SendCmd(RevtechMatchMessage.QUERY_STATE_INFORMATION);
- _timerQueryStatus.Start(QUERY_INTERVAL);
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- }
- public override void Terminate()
- {
- }
- public override void Reset()
- {
- }
- public override void SetMatchPosition(float c1, float c2, out string reason)
- {
- reason = "";
- base.SetMatchPosition(c1, c2, out reason);
- ExecuteMatchPostion(c1, c2);
- }
- public override bool SetMatchMode(string mode, out string reason)
- {
- reason = string.Empty;
- if (mode == EnumRfMatchTuneMode.Manual.ToString())
- SetWorkMode(EnumRfMatchTuneMode.Manual);
- else
- SetWorkMode(EnumRfMatchTuneMode.Auto);
- return true;
- }
- public override void SetMatchPositionC1(float c1, out string reason)
- {
- reason = string.Empty;
- LoadPosition1 = c1;
- base.SetMatchPositionC1(c1, out reason);
- ushort val1 = (ushort)(c1);
- SendCmd(RevtechMatchMessage.SET_C1_POS + $" {val1.ToString("X3")}");
- }
- public override void SetMatchPositionC2(float c2, out string reason)
- {
- reason = string.Empty;
- LoadPosition2 = c2;
- base.SetMatchPositionC2(c2,out reason);
- ushort val2 = (ushort)(c2);
- SendCmd(RevtechMatchMessage.SET_C2_POS + $" {val2.ToString("X3")}");
- }
- private void ExecuteMatchPostion(float c1, float c2)
- {
- SetPosition(c1, c2);
- }
- private void SetPosition(float c1val, float c2val)
- {
- LoadPosition1 = c1val;
- LoadPosition2 = c2val;
- ushort val1 = (ushort)(c1val);
- ushort val2 = (ushort)(c2val);
- SendCmd(RevtechMatchMessage.SET_C1_POS + $" {val1.ToString("X3")}");
- SendCmd(RevtechMatchMessage.SET_C2_POS + $" {val2.ToString("X3")}");
- }
- private void SetWorkMode(EnumRfMatchTuneMode mode)
- {
- if (mode == EnumRfMatchTuneMode.Auto)
- {
- SendCmd("MATCH:MODE HAUTO");
- }
- else if (mode == EnumRfMatchTuneMode.Manual)
- {
- SendCmd("MATCH:MODE MANUAL");
- }
- }
- private void SendCmd(string str)
- {
- if(!str.Contains(RevtechMatchMessage.QUERY_STATE_INFORMATION))
- {
- LOG.Write($"{Module} {Name} Revtech match send {str}");
- }
- _socket?.Write(Encoding.ASCII.GetBytes(str + "\n"));
- //EV.PostInfoLog(Module.ToString(), $"Revtech match send [{str}]");
- }
- }
- }
|