using HighWayIot.Log4net;
using HslCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HighWayIot.Plc.PlcHelper
{
    public class RecipeSignal
    {
        /// <summary>
        /// 读取排程信号
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, bool> ReadSchedulingSignal()
        {
            Dictionary<int, bool> result = new Dictionary<int, bool>();

            OperateResult<byte[]> operateResult = PlcConnect.ReadByte2("B901", 8);

            if (!operateResult.IsSuccess)
            {
                LogHelper.Instance.Error("排程监视PLC点位读取失败，检查PLC连接情况");
                return null;
            }

            byte[] bytes = operateResult.Content;

            int boolIndex = 0;
            for (int i = 0x901 - 0x901; i < 0x93E - 0x901 + 1; i++)
            {
                result.Add(boolIndex, bytes[i / 8].GetBoolByIndex(i % 8));
                boolIndex++;
            }

            for (int i = 0x941 - 0x901; i < 0x97E - 0x901 + 1; i++)
            {
                result.Add(boolIndex, bytes[i / 8].GetBoolByIndex(i % 8));
                boolIndex++;
            }

            return result;
        }
    }
}
