分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-06-20 00ad010a45f2f58807eb0f4f70e2dcf66ef35085
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
179
180
181
182
183
using HslCommunication;
using HslCommunication.ModBus;
using HslCommunication.Profinet.Melsec;
using HslCommunication.Profinet.Siemens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Entity.DomainModels;
 
namespace WIDESEA_WCS.WCSClient
{
    public class PLCClient
    {
        /// <summary>
        /// PLC连接对象集合
        /// </summary>
        public static List<PLCClient> Clients = new List<PLCClient>();
 
 
        #region 基础参数
        /// <summary>
        /// PLC名称
        /// </summary>
        public string PLCName { get; set; }
 
        /// <summary>
        /// PLC类型\协议类型
        /// </summary>
        public string PLCType { get; set; }
 
        /// <summary>
        /// Ip地址
        /// </summary>
        public string Ip { get; set; }
 
        /// <summary>
        /// Ip地址
        /// </summary>
        public int Port { get; set; }
 
        /// <summary>
        /// 插槽
        /// </summary>
        public int Slot { get; set; }
        #endregion
 
        #region 拓展属性
        /// <summary>
        /// 交互协议
        /// </summary>
        public List<DBItemGroup> itemGroups = new List<DBItemGroup>();
 
        /// <summary>
        /// 心跳
        /// </summary>
        public bool Heart { get; set; }
 
        /// <summary>
        /// 是否连接
        /// </summary>
        public bool IsConnected { get; set; }
        #endregion
 
        #region PLC对象
        /// <summary>
        /// 西门子 PLC
        /// </summary>
        public SiemensS7Net siemensPLCClient { get; set; }
 
        public ModbusTcpNet modbusTcpNet { get; set; }
 
        public MelsecMcNet melsecMcNet { get; set; }
        #endregion
 
        #region 公用方法
        /// <summary>
        /// 连接PLC
        /// </summary>
        /// <returns></returns>
        public virtual string Connect()
        {
            throw new NotImplementedException();
        }
 
        /// <summary>
        /// 断开PLC连接
        /// </summary>
        /// <returns></returns>
        public virtual bool DisConnect()
        {
            throw new NotImplementedException();
        }
 
        /// <summary>
        /// 读取数据,根据DB地址
        /// </summary>
        /// <typeparam name="DataType"></typeparam>
        /// <param name="dbAddress"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public virtual DataType Read<DataType>(string dbAddress, int len = 1)
        {
            throw new NotImplementedException();
        }
 
        /// <summary>
        /// 读取数据,根据数据库指令
        /// </summary>
        /// <typeparam name="DataType"></typeparam>
        /// <param name="orderName"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public virtual DataType ReadByOrder<DataType>(string orderName, string Method = null)
        {
            throw new NotImplementedException();
        }
 
        public object ReadValues(string equipNum)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 写入数据,根据DB地址
        /// </summary>
        /// <param name="dbAddress"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public virtual bool Write(string dbAddress, object value)
        {
            throw new NotImplementedException();
        }
 
        /// <summary>
        /// 写入数据,根据数据库指令
        /// </summary>
        /// <param name="orderName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public virtual bool WriteByOrder(string orderName, object value, string Method = null)
        {
            throw new NotImplementedException();
        }
 
        /// <summary>
        /// 获取内容
        /// </summary>
        /// <param name="operateResult"></param>
        /// <param name="item"></param> 
        public object GetContent<T>(OperateResult<T> operateResult, DBItemGroup item)
        {
            if (!operateResult.IsSuccess)
            {
                IsConnected = false;
                throw new Exception($"【Error】数据读取失败,指令{item.name},DB地址{item.dbAddress}\n错误信息:{operateResult.Message}");
            }
            return operateResult.Content;
        }
 
        /// <summary>
        /// 获取内容
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="operateResult"></param>
        /// <param name="dbAddress"></param>
        /// <returns></returns>
        public object GetContent<T>(OperateResult<T> operateResult, string dbAddress)
        {
            if (!operateResult.IsSuccess)
            {
                IsConnected = false;
                throw new Exception($"【Error】数据读取失败,DB地址{dbAddress}\n错误信息:{operateResult.Message}");
            }
            return operateResult.Content;
        }
 
        #endregion
    }
}