using HslCommunication;
using System.Linq;

namespace DataBlockHelper.Entity.DB2107Entity
{
    public class PIDEntity
    {

        byte[] bytes;

        public PIDEntity(byte[] bytes)
        {
            this.bytes = bytes;
        }

        public PID_HMI Convey_V1 => new PID_HMI(614, bytes);
        public PID_HMI Purge_V1 => new PID_HMI(622, bytes);
        public PID_HMI Convey_V2 => new PID_HMI(630, bytes);
        public PID_HMI Purge_V2 => new PID_HMI(638, bytes);
        public PID_HMI Convey_V3 => new PID_HMI(646, bytes);
        public PID_HMI Purge_V3 => new PID_HMI(654, bytes);
        public PID_HMI Convey_V4 => new PID_HMI(662, bytes);
        public PID_HMI Purge_V4 => new PID_HMI(670, bytes);
        public PID_HMI Convey_V5 => new PID_HMI(678, bytes);
        public PID_HMI Purge_V5 => new PID_HMI(686, bytes);
    }

    public class PID_HMI
    {
        public PID_HMI(ushort startSet, byte[] bytes)
        {
            //OperateResult<byte[]> read = PlcConnect.Instance.Read("DB2107." + startSet + ".0", 8);

            var content = bytes.Skip(startSet).Take(8).ToArray();

            PV = PlcConnect.Instance.ByteTransform.TransSingle(content, 0);
            SV = PlcConnect.Instance.ByteTransform.TransSingle(content, 4);
        }

        public float PV { get; private set; }
        public float SV { get; private set; }
    }
}