IOControls.cs
7.7 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
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
using DeviceLibrary;
using OnlineStore;
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;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine
{
public partial class IOControls : UserControl
{
Robot_Config _Config;
public Robot_Config Config
{
get { return _Config; }
set
{
_Config = value;
ioControl1.Config = value;
}
}
public IOControls()
{
InitializeComponent();
}
private void ioControl1_Load(object sender, EventArgs e)
{
}
private void btn_FlipEquip_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.FlipEquip.LiftUp(null);
LogUtil.info("手动点击:FlipEquip.LiftUp");
}
private void button1_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.FlipEquip.LiftDown(null);
LogUtil.info("手动点击:FlipEquip.LiftDown");
}
private void button2_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.RotateEquip.TurnToEnd(true);
LogUtil.info("手动点击:RotateEquip.TurnToEnd 水平");
}
private void button3_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.RotateEquip.TurnToEnd(false);
LogUtil.info("手动点击:RotateEquip.TurnToEnd 垂直");
}
private void button5_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.TPMove.ToLow(null);
}
private void button4_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.TPMove.ToHigh(null);
}
private void button6_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.RotateEquip.TurnDegree(45);
}
private void button7_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.RotateEquip.TurnDegree(-45);
}
private void button8_Click(object sender, EventArgs e)
{
var result = IsSafe();
if (!result.Item1)
{
MessageBox.Show(result.Item2);
return;
}
RobotManage.mainMachine.RotateEquip.TurnRound();
}
public static (bool, string) IsSafe()
{
if (RobotManage.mainMachine.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
return (false, "Emergency stop.");
if (RobotManage.isRunning)
return (false, "Safety interlock activated");
if (!RobotManage.mainMachine.IsAllDoorClosed())
return (false, "Safe door was not closed");
return (true, "");
}
private void button9_Click(object sender, EventArgs e)
{
var r= RobotManage.RFID.ReOpen();
RobotManage.RFID2.ReOpen();
LogUtil.info("RFID.ReOpen:" + r);
for (int i = 0; i < 6;i++) {
Thread.Sleep(200);
if (RobotManage.RFID.ReadEPC(16,out byte[] data)) {
if (data[0] != 0xFF)
{
MessageBox.Show("RFID:"+Encoding.ASCII.GetString(data).Trim());
return;
}
}
if (RobotManage.RFID2.ReadEPC(16, out data))
{
if (data[0] != 0xFF)
{
MessageBox.Show("RFID2:" + RobotManage.RFID2.HexBuff(data) + "\r\n" + Encoding.ASCII.GetString(data).Trim());
return;
}
}
}
MessageBox.Show("no data");
}
private void button10_Click(object sender, EventArgs e)
{
var epc = InputBox("Write EPC, maximum 16 words.", "Please enter EPC data, maximum 16 words.", "");
var r = RobotManage.RFID.ReOpen();
RobotManage.RFID2.ReOpen();
LogUtil.info("RFID.ReOpen:" + r+",epc="+ epc);
epc = epc.PadRight(16);
RobotManage.RFID.WriteByte(550, new byte[] { 0x40, 0x00 });
Thread.Sleep(300);
var result = RobotManage.RFID.WriteEPC(Encoding.ASCII.GetBytes(epc));
result = RobotManage.RFID2.WriteEPC(Encoding.ASCII.GetBytes(epc));
if (result)
{
MessageBox.Show(crc.GetString("Res0144","写入成功"));
return;
}
}
private string InputBox(string Caption, string Hint, string Default)
{
Form InputForm = new Form();
InputForm.MinimizeBox = false;
InputForm.MaximizeBox = false;
InputForm.StartPosition = FormStartPosition.CenterScreen;
InputForm.Width = 360;
InputForm.Height = 150;
//InputForm.Font.Name = "宋体";
//InputForm.Font.Size = 10;
InputForm.Text = Caption;
Label lbl = new Label();
lbl.Text = Hint;
lbl.Left = 10;
lbl.Top = 20;
lbl.Parent = InputForm;
lbl.AutoSize = true;
TextBox tb = new TextBox();
tb.Left = 30;
tb.Top = 45;
tb.Width = 300;
tb.Parent = InputForm;
tb.Text = Default;
tb.SelectAll();
Button btnok = new Button();
btnok.Left = 30;
btnok.Top = 80;
btnok.Parent = InputForm;
btnok.Text = "Ok";
InputForm.AcceptButton = btnok;//回车响应
btnok.DialogResult = DialogResult.OK;
Button btncancal = new Button();
btncancal.Left = 120;
btncancal.Top = 80;
btncancal.Parent = InputForm;
btncancal.Text = "Cancel";
btncancal.DialogResult = DialogResult.Cancel;
try
{
if (InputForm.ShowDialog() == DialogResult.OK)
{
return tb.Text;
}
else
{
return "";
}
}
finally
{
InputForm.Dispose();
}
}
}
}