FrmRobot.cs
6.3 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
using Common;
using DeviceLib.BLL;
using DeviceLib.Model.AGV;
using System;
using System.Text;
using UIControl.Forms;
namespace AGVDispatch
{
public partial class FrmRobot : FrmBase
{
public FrmRobot()
{
InitializeComponent();
loadRobot();
loadMission();
timer1.Start();
}
void loadRobot()
{
listBox1.DataSource = RobotManager.GetAllRobots();
listBox1.DisplayMember = "name";
}
void loadMission(int group_id=1)
{
listBox2.DataSource = MissionManager.GetMissions(group_id);
listBox2.DisplayMember = "alias";
}
Robot robot;
Mission mission;
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1) return;
//robot = RobotManager.GetRobot((int)listBox1.SelectedValue);
robot = (Robot)listBox1.SelectedValue;
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox2.SelectedIndex == -1) return;
//mission = MissionManager.GetMission(listBox2.SelectedValue.ToString());
mission = (Mission)listBox2.SelectedValue;
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
lblSelectedInfo.Text = $"【{robot?.name ?? ""}】【{robot?.ip ?? ""}】" +
$"【{robot?.mission_state?.mission?.name ?? ""}】【{robot?.mission_state?.mission?.alias ?? ""}】" +
$"【{robot?.mission_state?.run_id ?? -1}】";
if (robot != null && robot.io_modules != null)
{
StringBuilder sb = new StringBuilder();
foreach (var item in robot.io_modules)
{
sb.AppendLine(JsonHelper.SerializeObject(item));
}
lblIO.Text = $"{sb.ToString()}";
}
}
catch { }
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (robot.auto) return;
robot?.operation?.Add_Mission(mission);
LogUtil.Info($"{robot.name} 手动发送任务:{mission}");
}
catch(Exception ex)
{
LogUtil.Error($"手动发送任务出错:{mission}",ex);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
robot?.operation?.Set_Ready();
LogUtil.Info($"手动点击运行");
}
catch (Exception ex)
{
LogUtil.Error($"手动点击运行出错", ex);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
robot?.operation?.Set_Pause();
LogUtil.Info($"手动点击暂停");
}
catch (Exception ex)
{
LogUtil.Error($"手动点击暂停出错", ex);
}
}
private void button4_Click(object sender, EventArgs e)
{
try
{
robot?.operation?.Clear_Error();
LogUtil.Info($"手动点击清除错误");
}
catch (Exception ex)
{
LogUtil.Error($"手动点击清除错误出错", ex);
}
}
private void button5_Click(object sender, EventArgs e)
{
try
{
int.TryParse(txtRegister.Text, out int reg);
if (robot?.operation?.Get_Register(reg, out double regVal)??false)
{
txtRegisterVal.Text = regVal.ToString();
LogUtil.Info($"手动获取寄存器{reg}的值为{regVal}");
}
}
catch (Exception ex)
{
LogUtil.Error($"手动获取寄存器{txtRegister.Text}的值出错", ex);
}
}
private void button6_Click(object sender, EventArgs e)
{
try
{
int.TryParse(txtRegister.Text, out int reg);
double.TryParse(txtRegisterVal.Text, out double regVal);
if (robot?.operation?.Set_Register(reg, regVal) ?? false)
{
txtRegisterVal.Text = regVal.ToString();
LogUtil.Info($"手动设置寄存器{reg}的值为{regVal}");
}
}
catch (Exception ex)
{
LogUtil.Error($"手动设置寄存器{txtRegister.Text}的值为{txtRegisterVal.Text}出错", ex);
}
}
private void btnSetIO_Click(object sender, EventArgs e)
{
try
{
int.TryParse(txtBoxIOAddr.Text, out int addr);
int.TryParse(txtIOIdx.Text, out int idx);
if (robot?.operation?.Set_IO_Output(robot?.io_modules?[addr].ip??"",
new Arg_IO_Status() { on=true, port=idx}) ?? false)
{
LogUtil.Info($"手动点亮 addr={addr},idx={idx}");
}
}
catch (Exception ex)
{
LogUtil.Error($"手动点亮 addr={txtBoxIOAddr.Text},idx={txtIOIdx.Text}出错", ex);
}
}
private void btnSetOff_Click(object sender, EventArgs e)
{
try
{
int.TryParse(txtBoxIOAddr.Text, out int addr);
int.TryParse(txtIOIdx.Text, out int idx);
if (robot?.operation?.Set_IO_Output(robot?.io_modules?[addr].ip ?? "",
new Arg_IO_Status() { on = false, port = idx }) ?? false)
{
LogUtil.Info($"手动关闭 addr={addr},idx={idx}");
}
}
catch (Exception ex)
{
LogUtil.Error($"手动关闭 addr={txtBoxIOAddr.Text},idx={txtIOIdx.Text}出错", ex);
}
}
private void button7_Click(object sender, EventArgs e)
{
MissionManager.Load();
}
}
}