using OpcBasic;
using Robot.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MesWork
{
    public partial class Temp { }
    public partial class MesWorkForm
    {
      
        private void Loop_Slow_Task()
        {
            new Thread(new ThreadStart(Loop_Slow_Exec)) { IsBackground = true}.Start();
        }

        private void Loop_Slow_Exec()
        {
            while (true)
            {
                try
                {
                    var tagValue = Read();
                    S_C_B_Info_Slow(tagValue);
                }
                catch (Exception err)
                {
                }
                Thread.Sleep(2000);
            }
        }  
        
        private Param_Slow Read()
        {
            var param_Slow = new Param_Slow();

            param_Slow.produce_task_no = ReadPLC(10, "OP1000").ToString();
            param_Slow.agv_from_loc = agvRead.from_loc;
            param_Slow.agv_to_loc = agvRead.to_loc;


            var lib = new List<Param_Lib>();
            var jointArray = MesWorkForm.ReadPLC_GroupData("OP1000_L");
            foreach (KeyValuePair<string, object> item in jointArray)
            {
                var TF = (TagFormat)item.Value;
                var index = Convert.ToInt32(TF.ShaftID).ToString();
                var value = TF.TagValue.ToString().ToLower () == "true"?"1":"0";
                lib.Add(new Param_Lib { lib_loc_no = index , lib_content = value });
            }
            param_Slow.lib = lib.OrderBy(o=>Convert.ToInt32(o.lib_loc_no)).ToList();

            return param_Slow;
        }



    }
}

public class Param_Slow
{
    /// <summary>
    /// 
    /// </summary>
    public string produce_task_no
    {
        get;
        set;
    }
    /// <summary>
    /// 
    /// </summary>
    public string agv_from_loc
    { 
        get; 
        set; 
    }
    /// <summary>
    /// 
    /// </summary>
    public string agv_to_loc
    { 
        get; 
        set; 
    }
    /// <summary>
    /// 
    /// </summary>
    public List<Param_Lib> lib
    {
        get;
        set;
    }






}


public class Param_Lib
{
    public string lib_loc_no
    {
        get;
        set;
    }
    public string lib_content
    {
        get;
        set;
    }


}