FrmEquipBase.cs
6.5 KB
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
using log4net;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UserFromControl;
namespace OnlineStore.AssemblyLine
{
internal partial class FrmEquipBase : FrmBase
{
internal FrmEquipBase()
{
InitializeComponent();
}
internal EquipBase equipBase = null;
protected Dictionary<string, IOTextControl> DIControlList = new Dictionary<string, IOTextControl>();
protected Dictionary<string, IOTextControl> DOControlList = new Dictionary<string, IOTextControl>();
protected void ReadIOList()
{
foreach (string key in DIControlList.Keys)
{
IOTextControl control = DIControlList[key];
int iov = (int)IOManager.IOValue(key, equipBase.DeviceID);
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
}
foreach (string key in this.DOControlList.Keys)
{
IOTextControl control = DOControlList[key];
int iov = (int)IOManager.DOValue(key, equipBase.DeviceID);
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
}
}
protected void BtnMove(Button btn, string defaultText, string targetText, string ioHighType)
{
LogUtil.info(equipBase.Name+"点击【" + btn.Text + "】 ");
if (btn.Text.Equals(defaultText))
{
equipBase.IOMove(ioHighType, IO_VALUE.HIGH);
btn.Text = targetText;
btn.BackColor = Color.Aqua;
}
else
{
equipBase.IOMove(ioHighType, IO_VALUE.LOW);
btn.Text = defaultText;
btn.BackColor = Color.White;
}
}
protected void BtnMove(Button btn, string defaultText, string targetText, string ioLowType, string ioHighType)
{
LogUtil.info(equipBase.Name + "点击【" + btn.Text + "】 ");
if (btn.Text.Equals(defaultText))
{
btn.Text = targetText;
btn.BackColor = Color.Aqua;
}
else
{
btn.Text = defaultText;
btn.BackColor = Color.SkyBlue;
}
}
protected void StartDebug()
{
if (equipBase.runStatus.Equals(LineRunStatus.Wait))
{
bool result = equipBase.StartRun(true);
if (result)
{
FormStatus(true);
}
else
{
MessageBox.Show(equipBase.WarnMsg,"启动失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show(equipBase.Name + "已启动,不能重复启动","提示",MessageBoxButtons.OK, MessageBoxIcon.Warning );
}
}
protected void StopRun()
{
try
{
if (equipBase.runStatus <= LineRunStatus.Wait)
{
MessageBox.Show(equipBase.Name + "请先启动设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
LogUtil.info(equipBase.Name + "点击:停止运行");
equipBase.StopRun();
FormStatus(false);
}
}
catch (Exception ex)
{
LogUtil.error("出错:" ,ex);
}
}
protected void Reset()
{
if (equipBase.runStatus >= (LineRunStatus.HomeMoving))
{
LogUtil.info(equipBase.Name + "点击 :复位");
equipBase.Reset();
}
else
{
MessageBox.Show(equipBase.Name + "请先启动设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning );
}
}
internal virtual void FormStatus(bool status)
{
}
protected List<Control> doList = new List<Control>();
protected void LoadDOBtn(GroupBox group)
{
doList = new List<Control>();
foreach (Control c in group.Controls)
{
if (c is Button)
{
if (equipBase.baseConfig.DOList.ContainsKey(c.Name))
{
doList.Add(c);
}
else if (c.Name.ToUpper().StartsWith("BTN"))
{
c.Visible = true;
}
else
{
c.Visible = false;
}
}
}
}
protected void ReadBtnDO()
{
foreach (Control labl in doList)
{
IO_VALUE value = IOManager.DOValue(labl.Name, equipBase.DeviceID);
if (value.Equals(IO_VALUE.HIGH))
{
labl.BackColor = Color.Lime;
}
else
//else if (value.Equals(IO_VALUE.LOW))
{
labl.BackColor = labl.Parent.BackColor;
}
}
}
protected void DoBtnClick(object sender)
{
Control c = (Control)sender;
string ioType = c.Name;
IO_VALUE value = IOManager.IOValue(c.Name,equipBase.DeviceID);
if (value.Equals(IO_VALUE.HIGH))
{
equipBase.IOMove(ioType, IO_VALUE.LOW);
c.BackColor = c.Parent.BackColor;
LogUtil.info(equipBase.Name+"界面点击:" + c.Text + ",写入DO" + ioType + "=LOW");
}
else
{
equipBase.IOMove(ioType, IO_VALUE.HIGH);
c.BackColor = Color.LawnGreen;
LogUtil.info(equipBase.Name + "界面点击:" + c.Text + ",写入DO" + ioType + "=HIGH");
}
}
}
}