using HslCommunication;
|
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;
|
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.DTO;
|
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
|
using WIDESEAWCS_Tasks.StackerCraneJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class TestJob : IJob
|
{
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
|
|
//1.SendCommand方法示例
|
//堆垛机命令对象,继承DeviceCommand
|
StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
|
//调用发送任务命令方法
|
commonStackerCrane.SendCommand(stackerCraneTaskCommand);
|
|
//2.GetValue方法示例
|
//调用读取PLC数据方法,StackerCraneDBName为枚举类型,StackerCraneDBName.CurrentTaskNum为枚举值
|
commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.CurrentTaskNum);
|
|
//3.SetValue方法示例
|
//调用写入PLC数据方法,StackerCraneDBName为枚举类型,StackerCraneDBName.CurrentTaskNum为枚举值,121为写入的数据
|
commonStackerCrane.SetValue(StackerCraneDBName.CurrentTaskNum, 121);
|
|
//4.调用任务完成事件监测方法
|
commonStackerCrane.CheckStackerCraneTaskCompleted();
|
|
//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);
|
|
Console.Out.WriteLine();
|
}
|
catch (Exception ex)
|
{
|
Console.Out.WriteLine(nameof(TestJob) + ":" + ex.Message);
|
}
|
|
return Task.CompletedTask;
|
}
|
}
|
|
|
}
|