CylinderButton.cs
6.2 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
using DeviceLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
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;
namespace TheMachine
{
using crc = OnlineStore.CodeResourceControl;
public class CylinderButton : Button
{
Timer timer;
public CylinderButton()
{
this.FlatStyle = FlatStyle.Flat;
this.BackColor = Color.White;
this.Tag = "not";
//RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
this.Click += CylinderButton_Click;
timer = new Timer();
timer.Interval = 1000;
timer.Tick += Timer_Tick;
GC.KeepAlive(timer);
this.HandleCreated += CylinderButton_HandleCreated;
}
private void CylinderButton_HandleCreated(object sender, EventArgs e)
{
if (!DesignMode)
DataUpdate();
}
private void Timer_Tick(object sender, EventArgs e)
{
if(Visible)
StateUpdate();
}
private void RobotManage_LoadFinishEvent(bool state, string msg)
{
if (state)
{
DataUpdate();
//this.Invoke((EventHandler)delegate { DataUpdate(); });
}
}
string io_high;
string io_low;
ConfigIO configio_high;
ConfigIO configio_low;
IO_VALUE io_state = IO_VALUE.LOW;
[Category("数据"), Description("IO名称"), Browsable(true)]
public string IO_HIGH
{
get
{
return io_high;
}
set
{
io_high = value;
this.Text = io_high;
}
}
[Category("数据"), Description("IO名称"), Browsable(true)]
public string IO_LOW
{
get
{
return io_low;
}
set
{
io_low = value;
}
}
string devicetype = "root";
[Category("数据"), Description("设备ID"), Browsable(true)]
public string DeviceType
{
get
{
return devicetype;
}
set
{
devicetype = value;
DataUpdate();
}
}
void DataUpdate() {
if (string.IsNullOrEmpty(io_high) || !RobotManage.Config.DOList[devicetype].ContainsKey(io_high))
this.Text = $"IO {io_high} Not Find";
else
{
if (RobotManage.Config.DOList[devicetype].ContainsKey(io_high))
configio_high = RobotManage.Config.DOList[devicetype][io_high];
}
if (!string.IsNullOrEmpty(io_low))
{
if (!RobotManage.Config.DOList[devicetype].ContainsKey(io_low))
this.Text = $"IO {io_low} Not Find";
else
{
if (RobotManage.Config.DOList[devicetype].ContainsKey(io_low))
configio_low = RobotManage.Config.DOList[devicetype][io_low];
}
}
//this.Text = DeviceConfig.AllDOlist[io_high].Explain;
StateUpdate();
timer.Start();
}
void StateUpdate()
{
if (configio_high == null)
return;
io_state = IOManager.GetDOValue(configio_high.DeviceName, configio_high.SlaveID, configio_high.GetIOAddr());
if (configio_low != null)
{
if (io_state.Equals(IO_VALUE.LOW))
{
this.Text = configio_high.ElectricalDefinition+" "+crc.GetString(configio_high.ProName,configio_high.Explain);
this.BackColor = Color.White;
}
else
{
this.Text = configio_low.ElectricalDefinition + " "+ crc.GetString(configio_low.ProName,configio_low.Explain);
this.BackColor = Color.LightGreen;
}
}
else
{
if (io_state.Equals(IO_VALUE.LOW))
{
this.Text = "(ON) " + configio_high.ElectricalDefinition + " " + crc.GetString(configio_high.ProName, configio_high.Explain);
this.BackColor = Color.White;
}
else if (configio_low == null)
{
this.Text = "(OFF) " + configio_high.ElectricalDefinition + " " + crc.GetString(configio_high.ProName, configio_high.Explain);
this.BackColor = Color.LightGreen;
}
}
}
private void CylinderButton_Click(object sender, EventArgs e)
{
if (io_state.Equals(IO_VALUE.LOW))
{
LogUtil.info($"手动点击: Set {configio_high.ElectricalDefinition}{configio_high.Explain}=HIGH");
IOManager.WriteSingleDO(configio_high.DeviceName, configio_high.SlaveID, configio_high.GetIOAddr(), IO_VALUE.HIGH);
if (configio_low != null)
IOManager.WriteSingleDO(configio_low.DeviceName, configio_low.SlaveID, configio_low.GetIOAddr(), IO_VALUE.LOW);
}
else if (configio_low != null)
{
LogUtil.info($"手动点击: Set {configio_high.ElectricalDefinition}{configio_high.Explain}=LOW");
IOManager.WriteSingleDO(configio_high.DeviceName, configio_high.SlaveID, configio_high.GetIOAddr(), IO_VALUE.LOW);
IOManager.WriteSingleDO(configio_low.DeviceName, configio_low.SlaveID, configio_low.GetIOAddr(), IO_VALUE.HIGH);
}
else {
LogUtil.info($"手动点击: Set {configio_high.ElectricalDefinition}{configio_high.Explain}=LOW");
IOManager.WriteSingleDO(configio_high.DeviceName, configio_high.SlaveID, configio_high.GetIOAddr(), IO_VALUE.LOW);
}
}
}
}