UCRobot.cs
5.8 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
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 static JAKA.JKTYPE;
namespace JAKA
{
public partial class UCRobot : UserControl
{
public UCRobot()
{
Control.CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
private JAKABean jakaBean;
private JAKAServer server;
public void Regidter(JAKABean jakabean, JAKAServer jAKAServer)
{
this.jakaBean = jakabean;
groupBox1.Text = $"[{jakabean.IP}]";
server = jAKAServer;
foreach (var item in server.RobotCmds.Keys)
{
comboBox1.Items.Add(item);
}
if (comboBox1.Items.Count > 0)
comboBox1.SelectedIndex = 0;
jakabean.RegisterUpdataEvent(Update);
}
public void Update(RobotData robotData)
{
if (!this.IsHandleCreated)
return;
try
{
if (robotData == null) return;
this.Invoke((Action)(() =>
{
lblestop.BackColor = robotData.RobotStatus.emergency_stop == 0 ? Color.YellowGreen : Color.Red;
lblpoweredon.BackColor = robotData.RobotStatus.powered_on == 0 ? Color.Red : Color.YellowGreen;
lblservoenabled.BackColor = robotData.RobotStatus.enabled == 0 ? Color.Red : Color.YellowGreen;
lblinpos.BackColor = robotData.RobotStatus.inpos == 0 ? Color.Red : Color.YellowGreen;
lblprotectivestop.BackColor = robotData.RobotStatus.protective_stop == 0 ? Color.YellowGreen : Color.Red;
lblonsoftlimit.BackColor = robotData.RobotStatus.on_soft_limit == 0 ? Color.YellowGreen : Color.Red;
lblsdkconnect.BackColor = robotData.RobotStatus.is_socket_connect == 0 ? Color.Red : Color.YellowGreen;
lbldragstatus.BackColor = robotData.RobotStatus.drag_status == 0 ? Color.Red : Color.YellowGreen;
lblrapidrate.Text = $"运动倍率:{robotData.RobotStatus.rapidrate.ToString("f3")}";
lblerrorcode.Text = robotData.Errorinfo;
lblresponse.Text = $"命令反馈:{robotData.RecvMsg}";
if (robotData.ProgramState.Equals(ProgramState.PROGRAM_IDLE))
{
lblProgramstate.BackColor = Color.Red;
}
else if (robotData.ProgramState.Equals(ProgramState.PROGRAM_PAUSED))
{
lblProgramstate.BackColor = Color.Yellow;
}
else if (robotData.ProgramState.Equals(ProgramState.PROGRAM_RUNNING))
{
lblProgramstate.BackColor = Color.YellowGreen;
}
lblCmd.Text = $"当前命令:{robotData.CurCmd}";
if (robotData.Online)
{
groupBox1.Text = $"[{jakaBean.IP}][在线]";
}
else
{
groupBox1.Text = $"[{jakaBean.IP}][离线]";
}
}));
}
catch { }
}
private void btnPowerOn_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() => { jakaBean.PowerOn(); });
}
private void btnPowerOff_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() => { jakaBean.PowerOff(); });
}
private void btnEnable_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() => { jakaBean.EnableRobot(); });
}
private void btnDisable_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() => { jakaBean.DisableRobot(); });
}
private void btnStart_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() => { jakaBean.Run(); });
}
private void btnStop_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() => { jakaBean.Abort(); });
}
private void btnSend_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() =>
{
if (groupBox1.Text.Contains("在线"))
{
string cmd = comboBox1.SelectedItem.ToString();//textBox1.Text;
int.TryParse(textBox1.Text,out int round);
server.SendCmd(jakaBean.RemoteEndPoint, cmd, round);
}
});
}
private void btnRun_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() =>
{
if (jakaBean.PowerOn())
jakaBean.EnableRobot();
});
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (jakaBean?.GetDigitalOutput(IOType.IO_CABINET, 0, out bool insafe)??false)
{
lblSafe.BackColor = insafe ? Color.YellowGreen : Color.Red;
}
}
catch
{
}
}
private void UCRobot_Load(object sender, EventArgs e)
{
// timer1.Start();
}
private void button1_Click(object sender, EventArgs e)
{
jakaBean.ClearError();
}
private void button4_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(() =>
{
if (jakaBean.DisableRobot())
jakaBean.PowerOff();
});
}
}
}