12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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
- {
- public class EthernetRevtechMatch : RevtechMatch
- {
- private AsyncSocketDevice _socket;
- private string _address;
- public EthernetRevtechMatch(ModuleName mod, string name, string configName = "") : base(mod, name, configName)
- {
- _address = SC.GetStringValue($"{mod}.{(string.IsNullOrWhiteSpace(configName) ? name : configName)}.IPAddress");
- _socket = new AsyncSocketDevice(_address,"\n");
- _socket.OnDataChanged += new AsyncSocketDevice.MessageHandler(OnDataChanged);
- _socket.OnErrorHappened += _socket_OnErrorHappened;
- }
- public override bool Initialize()
- {
- base.Initialize();
- LOG.Info($"{Module} {Name} Revtech match address:[{_address}] connect");
- _socket?.Connect(_address);
- return true;
- }
- protected override void SendCmd(string str)
- {
- base.SendCmd(str);
- _socket?.Write(Encoding.ASCII.GetBytes(str + "\n"));
- }
- private void _socket_OnErrorHappened(ErrorEventArgsDevice args)
- {
- EV.PostAlarmLog(Module, $"{Module} {Name} Revtech Match 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(new char[] { ',' });
- 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 = (ushort)Convert.ToSingle(matchData[12]);
- DCBias = Convert.ToSingle(matchData[13]);
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
|