分支自 SuZhouGuanHong/TaiYuanTaiZhong

PCS
dengjunjie
2023-12-13 113d1d4262d8f9e78a9d92123713c41669ad6c87
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
75
76
77
78
79
80
81
using Microsoft.Extensions.Hosting;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Entity.DomainModels.ApiEntity.Test;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS
{
    /// <summary>
    /// 测试调度类
    /// </summary>
    [DisallowConcurrentExecution]
    internal class TestJob : IJob
    {
        static int index = 0;
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
                if (client == null)
                {
                    return Task.CompletedTask;
                }
 
                //自动重连
                if (!client.IsConnected)
                {
                    client.Connect();
                    return Task.CompletedTask;
                }
 
                DoAction(client);
            }
            catch { }
            return Task.CompletedTask;
        }
 
        private void DoAction(PLCClient client)
        {
            try
            {
                index++;
 
                //写入
                //client.Write("DB10.100", index);
                client.WriteByOrder("R_request_in", index);
                client.Write("DB10.105", "abc" + index);
 
                //读取
                var res1 = client.Read<int>("DB10.100");
                var res2 = client.ReadByOrder<int>("R_request_in");
                var res3 = client.Read<string>("DB10.105", 20);
 
                //日志写入
                WriteDBLog.Info("测试调度", res3, "WCS");
 
                //接口请求
                //var res = HttpHelper.Post<Weather>("http://apis.juhe.cn/simpleWeather/query", null, "测试接口");
                //var reee = HttpHelper.Get<object>("https://v0.yiketianqi.com/api", new { unescape = 1, version = "v91", appid = "43656176", appsecret = "I42og6Lm" });
 
                //获取任务号
                var taskNo = IdenxManager.GetTaskNo("KH-");
 
                //执行完成时间
                Console.WriteLine(DateTime.Now);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}