using ATC_MaterialBind.Entity;
using Microsoft.IdentityModel.Logging;
using SlnMesnac.Business.@base;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
using SlnMesnac.Repository.service.@base;
using SlnMesnac.Repository.service.Impl;
using SlnMesnac.Rfid;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;

namespace SlnMesnac.Business.@base
{
    public class MaterialBindBusiness : BaseBusiness
    {
        private IStationQualityInfoService _stationQualityInfoService;
        public Action<bool> _PlcConnectState;
        public MaterialBindBusiness(List<PlcAbsractFactory> plcFactories,IStationQualityInfoService stationQualityInfoService) : base(plcFactories)
        {
            _stationQualityInfoService = stationQualityInfoService;
        }
        public bool OK_FXSignal(String PlcAddress)
        {
            try
            {
                var flag = false;
                var plc = base.GetPlcByKey("plc");
                if (plc != null)
                {
                    flag = plc.writeInt16ByAddress(PlcAddress, 1);
                }
                return flag;
            }
            catch (Exception ex)
            {
                return false;
            }
           
           
        }
        public bool NG_BJSignal(String PlcAddress,int value)
        {
            try
            {
                var flag = false;
                var plc = base.GetPlcByKey("plc");
                if (plc != null)
                {
                    flag = plc.writeInt16ByAddress(PlcAddress, value);
                }
                return flag;
            }
            catch (Exception ex)
            {
                return false;
            }


        }
        public bool PLCState()
        {
            var plc = base.GetPlcByKey("plc");
            _PlcConnectState?.Invoke(plc.IsConnected);
            return plc.IsConnected;

        }


    }
}
  