2
schangxiang@126.com
2024-10-01 ffa9dc9c2d28c0b8d88b26d483ba9667e316db01
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using iWareCommon.Utils;
using iWareModel;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace iWareSda
{
    /// <summary>
    /// 堆垛机实体类
    /// </summary>
    public static class Srm_CacheEntity
    {
        public static LogType curLogType = LogType.SrmSdaService;
 
        #region 堆垛机地址
 
        /// <summary>
        /// 写入DB的地址(带分隔符)
        /// </summary>
        public static string W_DBHeaderWithSeparate = "540" + WareSdaStruct.PLCDBADDRESS_SEPARATE;
        /// <summary>
        /// 读取DB的地址(带分隔符)
        /// </summary>
        public static string R_DBHeaderWithSeparate = "541" + WareSdaStruct.PLCDBADDRESS_SEPARATE;
 
        /// <summary>
        /// 入库取货请求 DB的地址(带分隔符)
        /// </summary>
        public static string R_RKQH_DBHeaderWithSeparate = "221" + WareSdaStruct.PLCDBADDRESS_SEPARATE;
 
        /// <summary>
        /// 读取DB(报警专用)
        /// </summary>
        public static string R_DBHeader_Alert = "542";
 
 
        private static SrmDBForWrite _dbBlockForWrite = new SrmDBForWrite()
        {
            //TODO:这里写配置的DB地址
            #region 写入
 
            W_HandShake = W_DBHeaderWithSeparate + "0",
            W_SrmNo = W_DBHeaderWithSeparate + "2",
            W_PalletType = W_DBHeaderWithSeparate + "4",
 
            W_SourcePosX = W_DBHeaderWithSeparate + "6",
            W_SourcePosY = W_DBHeaderWithSeparate + "8",
            W_SourcePosZ = W_DBHeaderWithSeparate + "10",
            W_DestinationPosX = W_DBHeaderWithSeparate + "12",
            W_DestinationPosY = W_DBHeaderWithSeparate + "14",
            W_DestinationPosZ = W_DBHeaderWithSeparate + "16",
 
            W_Command = W_DBHeaderWithSeparate + "18",
            W_EmergencyStop = W_DBHeaderWithSeparate + "20",
            W_CancleAlarm = W_DBHeaderWithSeparate + "22",
            W_TaskFinishConfirm = W_DBHeaderWithSeparate + "24",
 
 
            W_Stb = W_DBHeaderWithSeparate + "30",
            W_Ack = W_DBHeaderWithSeparate + "32",
 
            W_TaskNo = W_DBHeaderWithSeparate + "34",
 
            #endregion
        };
        private static SrmDBForRead _dbBlockForRead = new SrmDBForRead()
        {
            //TODO:这里写配置的DB地址
            #region 读取
 
            R_PickReqForInStore = R_RKQH_DBHeaderWithSeparate + "2.0",
 
            R_HandShake = R_DBHeaderWithSeparate + "0",
            R_SrmNo = R_DBHeaderWithSeparate + "2",
            R_Mode = R_DBHeaderWithSeparate + "4",
            R_Alarm = R_DBHeaderWithSeparate + "6",
            R_LiftFull = R_DBHeaderWithSeparate + "8",
 
            R_PosX = R_DBHeaderWithSeparate + "10",
            R_PosY = R_DBHeaderWithSeparate + "12",
            R_PosZ = R_DBHeaderWithSeparate + "14",
            R_PosXmm = R_DBHeaderWithSeparate + "16",
            R_PosYmm = R_DBHeaderWithSeparate + "20",
            R_PosZmm = R_DBHeaderWithSeparate + "24",
 
            R_PickFinish = R_DBHeaderWithSeparate + "28",
            R_DeliveryFinish = R_DBHeaderWithSeparate + "30",
            R_TaskFinish = R_DBHeaderWithSeparate + "32",
 
            R_AlarmCode = R_DBHeaderWithSeparate + "34",
            R_State = R_DBHeaderWithSeparate + "36",
 
            R_ActualLane = R_DBHeaderWithSeparate + "38",
            R_TaskNo = R_DBHeaderWithSeparate + "40",
 
            #endregion
        };
 
        #endregion
 
        private static List<SrmEntity> _deviceObjList = null;
        private static object objLock = new object();
 
        /// <summary>
        /// 生成设备实体类
        /// </summary>
        public static List<SrmEntity> DeviceObjs
        {
            get
            {
                if (_deviceObjList == null)
                {
                    lock (objLock)
                    {
                        if (_deviceObjList == null)
                        {
                            _deviceObjList = new List<SrmEntity>();
                            _deviceObjList.AddRange(GetSrmList());
                        }
                    }
                }
                return Srm_CacheEntity._deviceObjList;
            }
            set { Srm_CacheEntity._deviceObjList = value; }
        }
 
        public static T GetDeviceObj<T>(int deviceId)
        {
            var device = Srm_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
            return (T)(Object)device;
        }
 
 
        /// <summary>
        /// 实例化SrmEntity集合
        /// </summary>
        /// <returns></returns>
        private static List<SrmEntity> GetSrmList()
        {
            List<SrmEntity> srmList = new List<SrmEntity>();
            srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm1_Address, EDevice.一号堆垛机));
            srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm2_Address, EDevice.二号堆垛机));
            srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm3_Address, EDevice.三号堆垛机));
            srmList.Add(GetSingleSrmEntity(WareSdaStruct.Srm4_Address, EDevice.四号堆垛机));
 
            return srmList;
        }
 
        /// <summary>
        ///  实例化单个SrmEntity
        /// </summary>
        /// <param name="_ip"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        private static SrmEntity GetSingleSrmEntity(string _ip, EDevice device)
        {
            SS7Param s7Param = new SS7Param()
            {
                cpu = WareSdaStruct.Srm_PLC_CpuType,
                ip = _ip,
                rack = WareSdaStruct.Srm_Rack,
                slot = WareSdaStruct.Srm_Slot,
            };
            HslCommunicationParam hslCommunicationParam = new HslCommunicationParam()
            {
                cpu = WareSdaStruct.Srm_SiemensPLCS,
                ip = _ip,
                rack = WareSdaStruct.Srm_Rack,
                slot = WareSdaStruct.Srm_Slot,
                port = WareSdaStruct.Srm_Port
            };
            PLCService PLCService = PLCFactory.GetOPCService(WareSdaStruct.System_PlcServiceTypeEnum, s7Param, hslCommunicationParam);
            SrmEntity srm = new SrmEntity("Srm" + (int)device, (int)device, _dbBlockForWrite, _dbBlockForRead, PLCService);
            return srm;
        }
    }
}