using HslCommunication;
using Sln.Iot.PLC;
using Sln.Iot.Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sln.Iot.Business
{
    public class RFID02Business
    {
        private Timer _timer;

        private readonly PLCConnect _plc;

        private readonly SerilogHelper _log;

        public RFID02Business()
        {
            _timer = new Timer(TimerCallback, null, 0, 5000);
        }

        /// <summary>
        /// RFID02上料提升机数据处理流程业务刷新
        /// </summary>
        /// <param name="state"></param>
        public void TimerCallback(object? state)
        {
            // 定时任务逻辑
            OperateResult<short> signalRes = _plc.ReadInt16(_plc.DeltaInstance1, "D500");
            if (signalRes.IsSuccess)
            {
                short signalValue = signalRes.Content;
                if(signalValue == 1001)
                {
                    OperateResult<byte[]> trayBytesResult = _plc.ReadBytes(_plc.DeltaInstance1, "D5000", 10);
                    OperateResult<byte[]> pordBytesResult = _plc.ReadBytes(_plc.DeltaInstance1, "D8000", 60);
                    if(trayBytesResult.IsSuccess && pordBytesResult.IsSuccess)
                    {
                        string traycode = "abcdefg";
                        string prodcode = "1234567890";
                    }
                }
            }
        }
    }
}
