AxisTipControl.cs
4.9 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
using DeviceLibrary;
using HuichuanLibrary;
using OnlineStore.Common;
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;
public partial class AxisTipControl : Form
{
public AxisTipControl()
{
InitializeComponent();
this.Deactivate += AxisTipControl_Deactivate;
this.LostFocus += AxisTipControl_LostFocus;
this.TopMost = true;
}
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;
//【2】读取轴状态,如果读取出错将关闭此定时器
AxisSts sts = HCBoardManager.GetAxisSts(SlvAddr);
if (sts.ServoOn < 0)
{
showToolTip("伺服尚未使能");
return;
}
if (sts.ALM != 0 || sts.WARN != 0 || sts.EMG != 0) {
showToolTip("伺服警报状态中");
return;
}
readPosition();
this.Show();
}
void showToolTip(string txt) {
var m_ToolTip = new ToolTip();
m_ToolTip.ToolTipIcon = ToolTipIcon.Warning;
m_ToolTip.ToolTipTitle = "无法操作";
m_ToolTip.AutoPopDelay = 0;
m_ToolTip.AutomaticDelay = 0;
m_ToolTip.InitialDelay = 0;
m_ToolTip.ShowAlways = true;
m_ToolTip.Show(txt, c);
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 * 3, speed * 3);
}
private void btnAddMove_MouseDown(object sender, MouseEventArgs e)
{
if (!CanMove())
{
return;
}
if (btnAddMove.BackColor.Equals(Color.White))
{
int speed = Convert.ToInt32(comjSpeed.Text);
if (speed <= 0)
{
MessageBox.Show("提示", "请先输入正确的速度");
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())
{
return;
}
if (btnDelMove.BackColor.Equals(Color.White))
{
int speed = Convert.ToInt32(comjSpeed.Text);
if (speed <= 0)
{
MessageBox.Show("提示", "请先输入正确的速度");
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()
{
AxisSts sts = HCBoardManager.GetAxisSts(SlvAddr);
if (sts.ServoOn < 0)
{
showToolTip("伺服尚未使能");
return false;
}
if (sts.ALM != 0 || sts.WARN != 0 || sts.EMG != 0)
{
showToolTip("伺服警报状态中");
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();
}
}