hutongqing
2024-11-20 70233af5426b0d1c343ebe87183303a34a9aaa58
WIDESEAWCS_Server/WIDESEAWCS_Tasks/TestJob.cs
@@ -2,6 +2,8 @@
using HslCommunication.Core;
using Microsoft.VisualBasic.FileIO;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
@@ -14,7 +16,9 @@
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
{
@@ -27,45 +31,31 @@
            {
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                Console.Out.WriteLine(commonStackerCrane.DeviceName + "状态:" + commonStackerCrane.StackerCraneStatusDes);
                //1.SendCommand方法示例
                //堆垛机命令对象,继承DeviceCommand
                StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
                //调用发送任务命令方法
                commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                Console.Out.WriteLine(commonStackerCrane.DeviceName + "手自动状态:" + commonStackerCrane.StackerCraneAutoStatusDes);
                //2.GetValue方法示例
                //调用读取PLC数据方法,StackerCraneDBName为枚举类型,StackerCraneDBName.CurrentTaskNum为枚举值
                commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.CurrentTaskNum);
                Console.Out.WriteLine(commonStackerCrane.DeviceName + "作业状态:" + commonStackerCrane.StackerCraneWorkStatusDes);
                //3.SetValue方法示例
                //调用写入PLC数据方法,StackerCraneDBName为枚举类型,StackerCraneDBName.CurrentTaskNum为枚举值,121为写入的数据
                commonStackerCrane.SetValue(StackerCraneDBName.CurrentTaskNum, 121);
                //Console.Out.WriteLine(commonStackerCrane.DeviceName + "当前任务号:" + commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.CurrentTaskNum));
                //4.调用任务完成事件监测方法
                commonStackerCrane.CheckStackerCraneTaskCompleted();
                //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());
                //5.使用CommonStackerCrane中Communicator属性直接读写PLC地址的值
                string plcProtocolAddress = "DB1.0";//PLC通讯协议的地址,可直接使用源地址读取
                DeviceProDTO? deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(StackerCraneDBName.CurrentTaskNum));//PLC通讯协议的地址,也可通过[协议信息属性(DeviceProDTOs)],去查询到相关的源地址
                if (deviceProDTO != null)
                {
                    commonStackerCrane.Communicator.Read<short>(plcProtocolAddress);
                    commonStackerCrane.Communicator.Read<short>(deviceProDTO.DeviceProAddress);
                }
                Console.Out.WriteLine(DateTime.Now);