using HslCommunication;
using HslCommunication.Core;
using Microsoft.VisualBasic.FileIO;
using Quartz;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;

namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class TestJob : IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");

                Console.Out.WriteLine(commonStackerCrane.DeviceName + "状态:" + commonStackerCrane.StackerCraneStatusDes);

                Console.Out.WriteLine(commonStackerCrane.DeviceName + "手自动状态:" + commonStackerCrane.StackerCraneAutoStatusDes);

                Console.Out.WriteLine(commonStackerCrane.DeviceName + "作业状态:" + commonStackerCrane.StackerCraneWorkStatusDes);

                //Console.Out.WriteLine(commonStackerCrane.DeviceName + "当前任务号:" + commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.CurrentTaskNum));

                //commonStackerCrane.SetValue(StackerCraneDBName.CurrentTaskNum, DateTime.Now.Second);

                //OperateResult<TimeSpan> operateResult = commonStackerCrane.Communicator.Wait("DB1.18", 1000, 60000, 1);
                //Console.Out.WriteLine(operateResult.Serialize());

                byte[] bytes = commonStackerCrane.Communicator.Read("DB1.1", 2);
                Console.Out.WriteLine(bytes.ToBoolArray().ToList().Serialize());

                bool[] bools = new bool[] { true, false, true };
                byte[] bytes1 = bools.ToByteArray();
                Console.Out.WriteLine(bytes1.ToList().Serialize());

                //StackerCraneCommand stackerCraneCommand = new StackerCraneCommand()
                //{
                //    TaskNum = 999,
                //    WorkType = 1,
                //    TrayType = 2,
                //    StartRow = 12,
                //    StartColumn = 13,
                //    StartLayer = 14,
                //    EndRow = 22,
                //    EndColumn = 23,
                //    EndLayer = 24,
                //};

                //bool flag = commonStackerCrane.SendCommand(stackerCraneCommand);
                //Console.Out.WriteLine(flag);

                //StackerCraneCommand stackerCraneCommand2 = new StackerCraneCommand();
                //stackerCraneCommand2 = commonStackerCrane.Communicator.ReadCustomer<StackerCraneCommand>("DB2.2");
                //Console.Out.WriteLine(stackerCraneCommand2.Serialize());

                Console.Out.WriteLine(DateTime.Now);

                Console.Out.WriteLine();
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(nameof(TestJob) + ":" + ex.Message);
            }

            return Task.CompletedTask;
        }
    }

    
}