wanshenmean
2025-04-08 413b51f88d342dc90d92ebfa2e500b8f660db09c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
        }
    }
 
    
}