using Aitex.Core.RT.Log; using MECF.Framework.Common.Communications; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.HiWin { public class HiwinRobotMessage : AsciiMessage { public string Data { get; set; } public string ErrorText { get; set; } } public class HiwinRobotConnection : TCPPortConnectionBase { private bool _isAckMode = false;//should read from config file public HiwinRobotConnection(string adress,string endof) : base(adress,endof,true) { } public override bool SendMessage(byte[] message) { return base.SendMessage(message); } protected override void ActiveHandlerProceedMessage(MessageBase msg) { lock (_lockerActiveHandler) { if (_activeHandler != null) { if(msg.IsFormatError|| (_activeHandler.HandleMessage(msg, out bool transactionComplete) && transactionComplete)) { _activeHandler = null; } } } } protected override MessageBase ParseResponse(string rawText) { HiwinRobotMessage msg = new HiwinRobotMessage(); msg.RawMessage = rawText; if (rawText.Length <= 0) { LOG.Error($"empty response"); msg.IsFormatError = true; return msg; } rawText = rawText.Replace("\r", "").Replace("\n", "").Replace(">",""); if (rawText.Contains("?")) { msg.IsError = true; msg.IsComplete = true; } msg.Data = rawText; msg.IsResponse = true; msg.IsAck = true; msg.IsComplete = true; return msg; } } }