AxisTipControl.cs
7.4 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
using DeviceLibrary;
using HuichuanLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
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 AxisManager = OnlineStore.DeviceLibrary.AxisManager;
public partial class AxisTipControl : Form
{
//static AxisManager AxisManager = AxisManager;
public AxisTipControl()
{
InitializeComponent();
this.Deactivate += AxisTipControl_Deactivate;
this.LostFocus += AxisTipControl_LostFocus;
this.TopMost = true;
crc.OpenResourceLog = true;
crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
crc.LanguageProcess(this);
}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
{
crc.LanguageProcess(this);
}
private void AxisTipControl_LostFocus(object sender, EventArgs e)
{
//this.Close();
}
private void AxisTipControl_Deactivate(object sender, EventArgs e)
{
this.Close();
}
short SlvAddr;
string PortName;
int targetSpeed;
static Control c;
public void ShowTips(Control _c,string title, short axisid, int _targetSpeed)
{
if (_c.Tag == null)
return;
if (c!=null && c.Name == _c.Name)
return;
Text = title;
/*var cp = c.PointToScreen(new Point(0, 0));
var cc = this.Parent.PointToClient(cp);
cc.Y += c.Height;
this.Location = cc;
*/
c = _c;
SlvAddr = axisid;
PortName = c.Name;
targetSpeed = _targetSpeed;
comjSpeed.Items.Clear();
for (int i = 1; i <= 10; i++)
{
comjSpeed.Items.Add(targetSpeed * i / 10);
}
comjSpeed.SelectedIndex = 4;
comjSpeed.KeyUp += ComjSpeed_KeyUp;
SetRelList((int)comjSpeed.SelectedItem);
//【2】读取轴状态,如果读取出错将关闭此定时器
AxisSts sts = HCBoardManager.GetAxisSts(SlvAddr);
if (sts.ServoOn < 0)
{
showToolTip(crc.GetString("Res0191","伺服尚未使能"),c);
return;
}
if (sts.ALM != 0 || sts.WARN != 0 || sts.EMG != 0) {
showToolTip(crc.GetString("Res0192","伺服警报状态中"),c);
return;
}
readPosition();
this.Show();
//LanguageProcess();
}
private void ComjSpeed_KeyUp(object sender, KeyEventArgs e)
{
if (!int.TryParse(comjSpeed.Text, out _))
{
//e.Handled = false;
return;
}
SetRelList(int.Parse(comjSpeed.Text));
}
private void ComjSpeed_KeyPress(object sender, KeyPressEventArgs e)
{
}
void SetRelList(int speed) {
flowLayoutPanel1.Controls.Clear();
int[] zoom = new int[] { 1, 3, 5, 7, 9, 11 };
for (int i = 0; i < zoom.Length; i++) {
Button b = new Button();
b.Size = new Size(60, 30);
var bs = (int)Math.Floor(speed / (decimal)zoom[i]);
b.Text = "+" + bs.ToString();
b.Tag = bs;
b.Click += B_Click;
flowLayoutPanel1.Controls.Add(b);
}
for (int i = 0; i < zoom.Length; i++)
{
Button b = new Button();
b.Size = new Size(60, 30);
var bs = (int)Math.Floor(speed / (decimal)zoom[zoom.Length-i-1]) *-1;
b.Text = bs.ToString();
b.Tag = bs;
b.Click += B_Click;
flowLayoutPanel1.Controls.Add(b);
}
}
private void B_Click(object sender, EventArgs e)
{
var b = sender as Button;
int pos = (int)b.Tag;
LogUtil.info("【" + PortName + "_" + SlvAddr + "】相对运动: 点位:" + pos);
AxisManager.RelMove(PortName, SlvAddr, pos, targetSpeed, targetSpeed * 3, targetSpeed * 3);
}
void showToolTip(string txt,Control control) {
var m_ToolTip = new ToolTip();
m_ToolTip.ToolTipIcon = ToolTipIcon.Warning;
m_ToolTip.ToolTipTitle = crc.GetString("Res0193","无法操作");
m_ToolTip.AutoPopDelay = 0;
m_ToolTip.AutomaticDelay = 0;
m_ToolTip.InitialDelay = 0;
m_ToolTip.ShowAlways = true;
m_ToolTip.Show(txt, control);
Task.Run(() => {
Task.Delay(5000).Wait();
m_ToolTip.Dispose();
});
}
private void AxisMove(int speed)
{
LogUtil.info("【" + PortName + "_" + SlvAddr + "】点动: 速度:" + speed);
AxisManager.SpeedMove(PortName, SlvAddr, speed, speed*4, speed*4);
}
private void btnAddMove_MouseDown(object sender, MouseEventArgs e)
{
if (!CanMove(sender))
{
return;
}
if (btnAddMove.BackColor.Equals(Color.White))
{
int speed = Convert.ToInt32(comjSpeed.Text);
if (speed <= 0)
{
MessageBox.Show(crc.GetString("Res0187","提示"), crc.GetString("Res0188","请先输入正确的速度"));
return;
}
btnAddMove.BackColor = Color.Green;
AxisMove(speed);
}
}
private void btnAddMove_MouseUp(object sender, MouseEventArgs e)
{
if (btnAddMove.BackColor == Color.Green)
{
btnAddMove.BackColor = Color.White;
AxisManager.SuddenStop(PortName, SlvAddr);
readPosition();
}
}
void readPosition()
{
textBox_pos.Text = AxisManager.GetActualtPosition(PortName, SlvAddr).ToString();
}
private void btnDelMove_MouseDown(object sender, MouseEventArgs e)
{
if (!CanMove(sender))
{
return;
}
if (btnDelMove.BackColor.Equals(Color.White))
{
int speed = Convert.ToInt32(comjSpeed.Text);
if (speed <= 0)
{
MessageBox.Show(crc.GetString("Res0187","提示"), crc.GetString("Res0188","请先输入正确的速度"));
return;
}
btnDelMove.BackColor = Color.Green;
AxisMove(-speed);
}
}
private void btnDelMove_MouseUp(object sender, MouseEventArgs e)
{
if (btnDelMove.BackColor == Color.Green)
{
btnDelMove.BackColor = Color.White;
AxisManager.SuddenStop(PortName, SlvAddr);
readPosition();
}
}
bool CanMove(object sender)
{
AxisSts sts = HCBoardManager.GetAxisSts(SlvAddr);
if (sts.ServoOn < 0)
{
showToolTip(crc.GetString("Res0191","伺服尚未使能"), (Control)sender);
return false;
}
if (sts.ALM != 0 || sts.WARN != 0 || sts.EMG != 0)
{
showToolTip(crc.GetString("Res0192","伺服警报状态中"), (Control)sender);
return false;
}
return true;
}
private void btn_cancel_Click(object sender, EventArgs e)
{
this.Close();
//c.Select();
//c.Focus();
}
private void btn_ok_Click(object sender, EventArgs e)
{
c.Text = textBox_pos.Text;
this.Close();
}
private void AxisTipControl_Load(object sender, EventArgs e)
{
}
private void comjSpeed_SelectedIndexChanged(object sender, EventArgs e)
{
SetRelList((int)comjSpeed.SelectedItem);
}
}