wangxinhui
2026-04-20 5d9c24c02c8685fd931e0ae93e54c811726af8c6
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_Tasks.StackerCraneJob
{
    /// <summary>
    /// 隔热&坯料堆垛机系统
    /// </summary>
    public class StackerSocketState_BTI
    {
        public string IPAddress { get; set; } = string.Empty;
        public bool IsEventSubscribed { get; set; }
    }
    /// <summary>
    /// 隔热&坯料堆垛机管理
    /// </summary>
    public static class CraneManager_BTI
    {
        private static readonly ConcurrentDictionary<string, Dictionary<string, CraneStacker>> _ipCranes = new();
 
        // 初始化3台堆垛机(一个IP下)
        public static Dictionary<string, CraneStacker> GetOrCreateCraneList(string ip)
        {
            return _ipCranes.GetOrAdd(ip, _ => new Dictionary<string, CraneStacker>
            {
                { "CRAN32-01", new CraneStacker("CRAN32-01", "1#堆垛机") },
                { "CRAN32-02", new CraneStacker("CRAN32-02", "2#堆垛机") },
                { "CRAN32-03", new CraneStacker("CRAN32-03", "3#堆垛机") },
            });
        }
 
        // 获取某一台堆垛机
        public static CraneStacker? GetCrane(string ip, string craneCode)
        {
            if (_ipCranes.TryGetValue(ip, out var list) && list.TryGetValue(craneCode, out var crane))
                return crane;
            return null;
        }
    }
    /// <summary>
    /// 成品堆垛机系统1
    /// </summary>
    public class StackerSocketState_CP01
    {
        public string IPAddress { get; set; } = string.Empty;
        public bool IsEventSubscribed { get; set; }
    }
    /// <summary>
    /// 成品堆垛机1管理
    /// </summary>
    public static class CraneManager_CP01
    {
        private static readonly ConcurrentDictionary<string, Dictionary<string, CraneStacker>> _ipCranes = new();
 
        // 初始化3台堆垛机(一个IP下)
        public static Dictionary<string, CraneStacker> GetOrCreateCraneList(string ip)
        {
            return _ipCranes.GetOrAdd(ip, _ => new Dictionary<string, CraneStacker>
            {
                { "CRAN30-01", new CraneStacker("CRAN30-01", "1#堆垛机") },
                { "CRAN30-02", new CraneStacker("CRAN30-02", "2#堆垛机") },
                { "CRAN30-03", new CraneStacker("CRAN30-03", "3#堆垛机") },
            });
        }
 
        // 获取某一台堆垛机
        public static CraneStacker? GetCrane(string ip, string craneCode)
        {
            if (_ipCranes.TryGetValue(ip, out var list) && list.TryGetValue(craneCode, out var crane))
                return crane;
            return null;
        }
    }
    /// <summary>
    /// 成品堆垛机系统2
    /// </summary>
    public class StackerSocketState_CP02
    {
        public string IPAddress { get; set; } = string.Empty;
        public bool IsEventSubscribed { get; set; }
    }
    /// <summary>
    /// 成品堆垛机2管理
    /// </summary>
    public static class CraneManager_CP02
    {
        private static readonly ConcurrentDictionary<string, Dictionary<string, CraneStacker>> _ipCranes = new();
 
        // 初始化3台堆垛机(一个IP下)
        public static Dictionary<string, CraneStacker> GetOrCreateCraneList(string ip)
        {
            return _ipCranes.GetOrAdd(ip, _ => new Dictionary<string, CraneStacker>
            {
                { "CRAN31-01", new CraneStacker("CRAN31-01", "1#堆垛机") },
                { "CRAN31-02", new CraneStacker("CRAN31-02", "2#堆垛机") },
                { "CRAN31-03", new CraneStacker("CRAN31-03", "3#堆垛机") },
            });
        }
 
        // 获取某一台堆垛机
        public static CraneStacker? GetCrane(string ip, string craneCode)
        {
            if (_ipCranes.TryGetValue(ip, out var list) && list.TryGetValue(craneCode, out var crane))
                return crane;
            return null;
        }
    }
    /// <summary>
    /// 单台堆垛机独立状态(多台之间完全隔离,不共享、不串值)
    /// </summary>
    public class CraneStacker
    {
        public string CraneCode { get; set; } = string.Empty;
        public string DisplayName { get; set; } = string.Empty;
 
        // 运行状态
        public int RunMode { get; set; } = 0;        // 1=自动 2=停止 3=手动/离线
        public int ErrorState { get; set; } = 0;      // 0=正常 1=故障
        public string CurrentPosition { get; set; } = string.Empty;
        public DateTime LastHeartbeat { get; set; } = DateTime.Now;
 
        // 当前任务
        public Dt_Task? CurrentTask { get; set; }
 
        // 独立序列号(每台堆垛机自己计数)
        public int SendSeq { get; set; } = 1;
        public object SeqLock { get; set; } = new object();
 
        public CraneStacker(string code, string name)
        {
            CraneCode = code;
            DisplayName = name;
        }
    }
}