123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- using Aitex.Core.Common.DeviceData;
- using MECF.Framework.Common.Communications;
- using System;
- using System.Linq;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.RFMatchs.Serens
- {
- public abstract class SerenRfMatchHandler : HandlerBase
- {
- public SerenRfMatch Device { get; }
- private string _command;
- protected SerenRfMatchHandler(SerenRfMatch device, string command)
- : base($"{command}\r")
- {
- Device = device;
- _command = command;
- }
- public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
- {
- SerenRfMatchMessage response = msg as SerenRfMatchMessage;
- ResponseMessage = msg;
- if (response.RawMessage.Length >= 1)
- {
- ParseData(response);
- }
- SetState(EnumHandlerState.Acked);
- SetState(EnumHandlerState.Completed);
- transactionComplete = true;
- return true;
- }
- protected virtual void ParseData(SerenRfMatchMessage msg)
- {
- }
- }
- public class SerenRfMatchGotoHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGotoHandler(SerenRfMatch device)
- : base(device, "GOTO")
- {
- Name = $"Goto the preset position";
- }
- }
- public class SerenRfMatchSetLoadControlModeHandler : SerenRfMatchHandler
- {
- public SerenRfMatchSetLoadControlModeHandler(SerenRfMatch device, bool isAuto)
- : base(device, isAuto ? "ALD" : "MLD")
- {
- if (isAuto)
- {
- Name = $"Set Load Control Mode to Auto";
- }
- else
- {
- Name = $"Set Load Control Mode to Manual";
- }
- }
- }
- public class SerenRfMatchEnablePresetHandler : SerenRfMatchHandler
- {
- public SerenRfMatchEnablePresetHandler(SerenRfMatch device, bool enable)
- : base(device, enable ? "INT" : "OFF")
- {
- if (enable)
- {
- Name = $"Enable preset mode";
- }
- else
- {
- Name = $"Disable preset mode";
- }
- }
- }
- public class SerenRfMatchGetPresetHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetPresetHandler(SerenRfMatch device )
- : base(device, "QPMD" )
- {
- Name = $"Query preset mode";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (msg.RawMessage.StartsWith("0"))
- Device.NotePresetMode("0");
- if (msg.RawMessage.StartsWith("1"))
- Device.NotePresetMode("1");
- if (msg.RawMessage.StartsWith("2"))
- Device.NotePresetMode("2");
- }
- }
- public class SerenRfMatchGetLoadControlModeHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetLoadControlModeHandler(SerenRfMatch device)
- : base(device, "QAML")
- {
- Name = $"Get Load Control Mode";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (msg.RawMessage.StartsWith( "A"))
- Device.NoteLoadControlMode(true);
- if (msg.RawMessage.StartsWith("M"))
- Device.NoteLoadControlMode(false);
- }
- }
- public class SerenRfMatchSetTuneControlModeHandler : SerenRfMatchHandler
- {
- public SerenRfMatchSetTuneControlModeHandler(SerenRfMatch device, bool isAuto)
- : base(device, isAuto ? "ATN" : "MTN")
- {
- if (isAuto)
- {
- Name = $"Set Tune Control Mode to Auto";
- }
- else
- {
- Name = $"Set Tune Control Mode to Manual";
- }
- }
- }
- public class SerenRfMatchGetTuneControlModeHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetTuneControlModeHandler(SerenRfMatch device)
- : base(device, "QAMT")
- {
- Name = $"Get Tune Control Mode";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (msg.RawMessage.StartsWith("A"))
- Device.NoteTuneControlMode(true);
- if (msg.RawMessage.StartsWith("M"))
- Device.NoteTuneControlMode(false);
- }
- }
- //Reports the current Load capacitor position, in Percent x10.
- public class SerenRfMatchGetLoadPositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetLoadPositionHandler(SerenRfMatch device )
- : base(device, device.MatchType=="ATS" ? "CPLP" : "LPS?")
- {
- Name = "Get Load Position";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (Device.MatchType == "ATS")
- {
- if (int.TryParse(msg.RawMessage, out int pos))
- Device.NoteLoadPosition((float)(pos / 10.0));
- }
- else
- {
- if (int.TryParse(msg.RawMessage, out int pos))
- Device.NoteLoadPosition((float)(pos));
- }
- }
- }
- //Reports the current Tune capacitor position, in Percent x10.
- public class SerenRfMatchGetTunePositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetTunePositionHandler(SerenRfMatch device)
- : base(device, device.MatchType=="ATS" ? "CPTP" : "TPS?")
- {
- Name = "Get Tune Position";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (Device.MatchType == "ATS")
- {
- if (int.TryParse(msg.RawMessage, out int pos))
- Device.NoteTunePosition((float)(pos / 10.0));
- }
- else
- {
- if (int.TryParse(msg.RawMessage, out int pos))
- Device.NoteTunePosition((float)(pos ));
- }
- }
- }
-
- //set load position
- public class SerenRfMatchSetLoadPositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchSetLoadPositionHandler(SerenRfMatch device, float position)
- : base(device, BuildMessage(position))
- {
- Name = "set load position";
- }
- private static string BuildMessage(float position)
- {
- position = Math.Max(0, Math.Min(100, position));
- int value = (int)(position * 10) ;
- return $"{value} MVLD";
- }
- }
- //set load preset1 position
- //Command syntax: X<sp>MPLS<CR>
- //Where: “X” is the desired Load Capacitor Preset Position 1 value, in percent.
- //1 to 5 digits, range: 0.0 to 100
- public class SerenRfMatchSetLoadPreset1PositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchSetLoadPreset1PositionHandler(SerenRfMatch device, float position)
- : base(device, BuildMessage(device, position))
- {
- Name = "set load preset1 position";
- }
- private static string BuildMessage(SerenRfMatch device, float position)
- {
- if (device.MatchType == "ATS")
- {
- position = Math.Max(0, Math.Min(100, position));
- return $"{position:F1} MPLS";
- }
- else
- {
- int pos = (int)Math.Max(2, Math.Min(98, position));
- return $"{pos} MPL";
- }
- }
- }
- public class SerenRfMatchGetLoadPreset1PositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetLoadPreset1PositionHandler(SerenRfMatch device)
- : base(device, "QP1L")
- {
- Name = "get load preset1 position";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (int.TryParse(msg.RawMessage, out int data))
- Device.NoteLoadPresetPosition((float)(data/10.0));
- }
- }
- //set tune position
- public class SerenRfMatchSetTunePositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchSetTunePositionHandler(SerenRfMatch device, float position)
- : base(device, BuildMessage(device, position))
- {
- Name = "set tune position";
- }
- private static string BuildMessage(SerenRfMatch device, float position)
- {
- if (device.MatchType == "ATS")
- {
- position = Math.Max(0, Math.Min(100, position));
- int value = (int)(position * 10);
- return $"{value} MVTN";
- }
- else
- {
- float pos = (float)Math.Max(2, Math.Min(98, position));
- return $"{pos:F1} MPT";
- }
- }
- }
- public class SerenRfMatchSetTunePreset1PositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchSetTunePreset1PositionHandler(SerenRfMatch device, float position)
- : base(device, BuildMessage(device, position))
- {
- Name = "set tune preset position";
- }
- private static string BuildMessage(SerenRfMatch device, float position)
- {
- if (device.MatchType == "ATS")
- {
- position = Math.Max(0, Math.Min(100, position));
- return $"{position:F1} MPTS";
- }
- else
- {
- float pos = (float) Math.Max(2, Math.Min(98, position));
- return $"{pos:F1} MPT";
- }
- }
- }
- public class SerenRfMatchGetTunePreset1PositionHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetTunePreset1PositionHandler(SerenRfMatch device)
- : base(device, "QP1T")
- {
- Name = "get tune preset1 position";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (int.TryParse(msg.RawMessage, out int data))
- Device.NoteTunePresetPosition((float)(data / 10.0));
- }
- }
- public class SerenRfMatchGetMagnitudeErrorHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetMagnitudeErrorHandler(SerenRfMatch device)
- : base(device, "MAG")
- {
- Name = "Get Magnitude Error";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (int.TryParse(msg.RawMessage, out int error))
- Device.NoteMagnitudeError(error);
- }
- }
- public class SerenRfMatchGetPhaseErrorHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetPhaseErrorHandler(SerenRfMatch device)
- : base(device, "PHS")
- {
- Name = "Get Phase Error";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (int.TryParse(msg.RawMessage, out int error))
- Device.NotePhaseError(error);
- }
- }
- public class SerenRfMatchGetDCVoltageHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetDCVoltageHandler(SerenRfMatch device)
- : base(device, device.MatchType=="ATS" ? "QDP":"0?")
- {
- Name = "Get DC Voltage";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (int.TryParse(msg.RawMessage, out int voltage))
- Device.NoteDCVoltage(voltage);
- }
- }
- public class SerenRfMatchGetRFVoltageHandler : SerenRfMatchHandler
- {
- public SerenRfMatchGetRFVoltageHandler(SerenRfMatch device)
- : base(device, device.MatchType == "ATS" ? "QRP":"0?")
- {
- Name = "Get RF Voltage";
- }
- protected override void ParseData(SerenRfMatchMessage msg)
- {
- if (int.TryParse(msg.RawMessage, out int voltage))
- Device.NoteRFVoltage(voltage);
- }
- }
- }
|