-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
373 lines (310 loc) · 13.7 KB
/
MainForm.cs
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
using DevExpress.XtraEditors;
using DevExpress.XtraSplashScreen;
using HslCommunication.Profinet.Siemens;
using HslCommunication;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;
using System.Collections;
using DevExpress.Charts.Native;
using System.Threading;
namespace XXuanSCADA
{
public partial class MainForm : CCSkinMain
{
public SiemensS7Net S7 { get; set; }
public OperateResult ConectState;
double[] arr = new double[25];//运行数据
public MainForm()
{
InitializeComponent();
//this.Load += MainForm_Load;
//this.SizeChanged += MainForm_SizeChanged;
}
//窗体的默认宽和高
int normalWidth = 0;
int normalHeight = 0;
//需要记录的控件的位置以及宽和高(X,Y,Width,Height)
Dictionary<string, Rect> normalControl = new Dictionary<string, Rect>();
private void MainForm_Load(object sender, EventArgs e)
{
//记录相关对向及原始尺寸
normalWidth = this.imgPanel.Width;
normalHeight = this.imgPanel.Height;
foreach (Control item in this.imgPanel.Controls)
{
normalControl.Add(item.Name, new Rect(item.Left, item.Top, item.Width, item.Height));
}
try
{
S7 = new SiemensS7Net(SiemensPLCS.S200Smart, Com.PlcIp)
{
ConnectTimeOut = 3000
};
ConectState = S7.ConnectServer();
if (ConectState.IsSuccess)
{
this.timer_readdata.Enabled = true;
if (Com.IsSaveData)
{
this.timer_savedate.Enabled = true;
}
else
{
this.timer_savedate.Enabled = false;
}
}
else
{
this.timer_readdata.Enabled = false;
this.systemState.Text = "PLC连接断开…";
XtraMessageBox.Show("连接PLC超时!", "系统信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
}
}
private void ReadData()
{
try
{
this.systemState.Text = "正在读取数据…";
arr[0] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1000").Content));
设备入口压力.Text = arr[0].ToString("0.0") + "Mpa";
arr[1] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1016").Content));
设备入口温度.Text = arr[1].ToString("0.0") + "℃";
arr[2] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1100").Content));
设备出口压力.Text = arr[2].ToString("0.0") + "Mpa";
arr[3] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1120").Content));
设备出口温度.Text = arr[3].ToString("0.0") + "℃";
arr[4] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1190").Content));
气控压力.Text = arr[4].ToString("0.0") + "Mpa";
arr[5] = Convert.ToDouble(S7.ReadInt16("V1050").Content);
高压分离器液位计.Value = S7.ReadInt16("V1050").Content;
高压分离器液位.Text = arr[5].ToString() + "mm";
arr[6] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1260").Content));
高压分离器浓度.Text = arr[6].ToString("0.0") + "LEL%";
arr[7] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1136").Content));
旋流分离器浓度.Text = arr[7].ToString("0.0") + "LEL%";
arr[8] = Convert.ToDouble(S7.ReadInt16("V1088").Content);
旋流分离器液位计.Value = S7.ReadInt16("V1088").Content;
旋流分离器液位.Text = arr[8].ToString() + "mm";
arr[9] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1170").Content));
旋流分离器出口压力.Text = arr[9].ToString("0.0") + "Mpa";
arr[10] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1180").Content));
旋流分离器出口温度.Text = arr[10].ToString("0.0") + "℃";
arr[11] = Convert.ToDouble(S7.ReadInt16("V1290").Content);
JT阀开度监测.Text = arr[11].ToString() + "%";
arr[12] = Convert.ToDouble(S7.ReadInt16("V1280").Content);
水套炉液位计.Value = S7.ReadInt16("V1280").Content;
水套炉液位.Text = arr[12].ToString() + "mm";
arr[13] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1320").Content));
水套炉进气温度.Text = arr[13].ToString("0.0") + "℃";
arr[14] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1228").Content));
水套炉水温.Text = arr[14].ToString("0.0") + "℃";
arr[15] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1164").Content));
换热器入口压力.Text = arr[15].ToString("0.0") + "Mpa";
arr[16] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1208").Content));
换热器入口温度.Text = arr[16].ToString("0.0") + "℃";
arr[17] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1300").Content));
换热器出口压力.Text = arr[17].ToString("0.0") + "Mpa";
arr[18] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1310").Content));
换热器出口温度.Text = arr[18].ToString("0.0") + "℃";
arr[19] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1490").Content));
水套炉点火浓度.Text = arr[19].ToString("0.0") + "LEL%";
arr[20] = Convert.ToDouble(Com.IntToDubleString(S7.ReadInt16("V1480").Content));
//arr[20] = Convert.ToDouble(S7.ReadInt16("V1480").Content)/10;
露点仪.Text = arr[20].ToString() + "℃";
arr[21] = Convert.ToDouble(S7.ReadFloat("V56").Content.ToString("0.0"));
气体瞬时流量.Text = S7.ReadFloat("V56").Content.ToString("0.0") + "Nm3/d";
arr[22] = Convert.ToDouble(S7.ReadFloat("V60").Content.ToString("0.00"));
气体累计流量.Text = S7.ReadFloat("V60").Content.ToString("0.00") + "Nm3";
arr[23] = Convert.ToDouble(S7.ReadFloat("V64").Content.ToString("0.00"));
液体瞬时流量.Text = S7.ReadFloat("V64").Content.ToString("0.00") + "Nm3/d";
arr[24] = Convert.ToDouble(S7.ReadFloat("V68").Content.ToString("0.00"));
液体累计流量.Text = S7.ReadFloat("V68").Content.ToString("0.00") + "Nm3";
//
switch_JT阀.State = Convert.ToInt32(S7.ReadBool("M3.5").Content); //JT阀状态
switch_进口阀.State = Convert.ToInt32(S7.ReadBool("Q0.0").Content); //进口阀状态
switch_高压排污阀.State = Convert.ToInt32(S7.ReadBool("Q0.2").Content); //高压分离器排污阀状态
switch_高压放空阀.State = Convert.ToInt32(S7.ReadBool("Q0.6").Content); //高压分离器放空阀状态
switch_旋流排污阀.State = Convert.ToInt32(S7.ReadBool("Q1.0").Content); //旋流排污阀状态
switch_出口阀.State = Convert.ToInt32(S7.ReadBool("Q1.2").Content); //旋流排污阀状态
switch_燃料阀.State = Convert.ToInt32(S7.ReadBool("Q1.5").Content); //旋流排污阀状态
switch_主路阀.State = Convert.ToInt32(S7.ReadBool("Q1.6").Content); //旋流排污阀状态
//switch_水套炉火焰.State = Convert.ToInt32(S7.ReadBool("I1.4").Content);
//
}
catch (Exception err)
{
this.systemState.Text = "PLC连接断开…";
}
}
private void Alarm()
{
int alarm = Convert.ToInt32(S7.ReadBool("Q1.7").Content);
if (alarm == 0)
{
报警器.State = false;
//MessageBox.Show("0");
}
if (alarm == 1)
{
报警器.State = true;
timer_alarm.Interval = 3000;
//MessageBox.Show("1");
new clsMCI
{
FileName = "alarm2.mp3"
}.play();
}
}
/*
private void MainForm_SizeChanged(object sender, EventArgs e)
{
//根据原始比例进行新尺寸的计算
int w = this.imgPanel.Width;
int h = this.imgPanel.Height;
foreach (Control item in this.imgPanel.Controls)
{
if (normalControl.ContainsKey(item.Name))
{
var controlInfo = normalControl[item.Name];
int newX = (int)(w * 1.0 / normalWidth * controlInfo.X);
int newY = (int)(h * 1.0 / normalHeight * controlInfo.Y);
int newW = (int)(w * 1.0 / normalWidth * controlInfo.Width);
int newH = (int)(h * 1.0 / normalHeight * controlInfo.Height);
item.Left = newX;
item.Top = newY;
item.Width = newW;
item.Height = newH;
}
else
{
Console.WriteLine($"控件{item.Name}不存在于normalControl中");
}
}
//throw new NotImplementedException();
}
*/
public class Rect
{
public Rect(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public int X { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
private bool HaveOpened(string FormName)
{
bool bOpened = false;
for (int i = 0; i < this.MdiChildren.Length; i++)
{
if (this.MdiChildren[i].Name == FormName)
{
this.MdiChildren[i].Show();
this.MdiChildren[i].BringToFront();
bOpened = true;
break;
}
}
return bOpened;
}
//机组控制
private void btnControl_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (Com.LoginUserLe == "操作员")
{
XtraMessageBox.Show("你没有权限操作!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (ConectState.IsSuccess)
{
Form frmcheck = Application.OpenForms["Controls"];
if (frmcheck == null || frmcheck.IsDisposed)
{
Controls form = new Controls();
form.Show();
}
else
{
frmcheck.Activate();
}
}
else
{
XtraMessageBox.Show("未连接PLC,无法设置该项", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btnHistory_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
{
Form frmcheck = Application.OpenForms["HistoryData"];
if (frmcheck == null || frmcheck.IsDisposed)
{
HistoryData form = new HistoryData();
form.Show();
}
else
{
frmcheck.Activate();
}
}
}
private void timer_readdata_Tick(object sender, EventArgs e)
{
Thread t = new Thread(ReadData);
t.Start();
ReadData();
//Alarm();
}
private void timer_alarm_Tick(object sender, EventArgs e)
{
Alarm();
}
private void btnRunningConfig_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (Com.LoginUserLe == "操作员")
{
XtraMessageBox.Show("你没有权限操作!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (ConectState.IsSuccess)
{
Form frmcheck = Application.OpenForms["RunningConfig"];
if (frmcheck == null || frmcheck.IsDisposed)
{
RunningConfig form = new RunningConfig();
form.Show();
}
else
{
frmcheck.Activate();
}
}
else
{
XtraMessageBox.Show("未连接PLC,无法设置该项", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}