using MECF.Framework.Common.Communications;
using System.Collections.Generic;

namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner
{
    public class HwAlignerGuideConnection : SerialPortConnectionBase
    {
        private readonly List<byte> _lstCacheBuffer = new();
        private object _lockerActiveHandler = new object();

        public HwAlignerGuideConnection(string portName)
            : base(portName, 115200, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r", false)
        {   
        }
        public override bool SendMessage(byte[] message)
        {
            _lstCacheBuffer.Clear();
            return base.SendMessage(message);
        }
        protected override MessageBase ParseResponse(byte[] rawMessage)
        {
         
            _lstCacheBuffer.AddRange(rawMessage);
            var temps = _lstCacheBuffer.ToArray();

            HwAlignerGuideMessage msg = new HwAlignerGuideMessage();
            msg.IsResponse = false;
            msg.IsAck = false;
            msg.IsComplete = false;
            msg.RawMessage = _lstCacheBuffer.ToArray();
            msg.Data = _lstCacheBuffer.ToArray();
            msg.IsResponse = true;
            msg.IsAck = true;
            msg.IsComplete = true;

            return msg;
        }

    }

}
