FrmMain.cs
5.0 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
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;
namespace Test
{
public partial class FrmMain : Form
{
private readonly log4net.ILog LOG;
private Neotel.Rmaxis axis;
private bool testLoop;
private System.Threading.Thread tStatus;
private System.Threading.Thread tTest;
public FrmMain()
{
InitializeComponent();
LOG = log4net.LogManager.GetLogger("Test");
}
private void ReadStatus()
{
while (true)
{
if (!axis.IsPortOpen) break;
LblStatus.Invoke(new Action(() =>
{
LblStatus.Text = "出力:" + axis.GetTorque() + "\r\n速度:" + axis.GetVelocity() + "\r\n位置:" + axis.GetPosition() + "\r\n错误代码:" + axis.ErrorCode;
}));
System.Threading.Thread.Sleep(50);
}
}
private void PushTest(object obj)
{
int[] param = (int[])obj;
int times = 0;
int timeout = 5000;
bool push = false;
bool rtn;
while (testLoop)
{
if (times == param[3])
{
StopTest();
break;
}
if (push)
{
rtn = axis.PushWait(param[0], param[1], param[2], timeout);
times++;
}
else
{
rtn = axis.GoHomeWait(timeout);
}
Invoke(new Action(() => { TsslStatus.Text = string.Format("PushWait {0} 次数{1}", rtn, times); }));
if (!rtn)
{
StopTest();
break;
}
push = !push;
System.Threading.Thread.Sleep(param[4]);
}
}
private void StopTest()
{
testLoop = false;
BtnStability.Invoke(new Action(() => { BtnStability.Text = "测试"; }));
}
private void FrmMain_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 30; i++)
CboPort.Items.Add("COM" + i);
axis = new Neotel.Rmaxis();
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
axis.ClosePort();
if (tStatus != null) tStatus.Abort();
}
private void BtnOpenPort_Click(object sender, EventArgs e)
{
bool rtn = axis.OpenPort(CboPort.Text);
TsslStatus.Text = BtnOpenPort.Text + " " + rtn;
if (rtn)
{
LblVersion.Text = "版本号\r\n" + axis.GetVersion();
tStatus = new System.Threading.Thread(new System.Threading.ThreadStart(ReadStatus));
tStatus.Start();
}
}
private void BtnClosePort_Click(object sender, EventArgs e)
{
axis.ClosePort();
if (tStatus != null) tStatus.Abort();
TsslStatus.Text = BtnClosePort.Text;
}
private void BtnGoHome_Click(object sender, EventArgs e)
{
bool rtn = axis.GoHomeWait(5000);
TsslStatus.Text = "GoHomeWait " + rtn;
}
private void BtnPush_Click(object sender, EventArgs e)
{
bool rtn = axis.PushWait(Convert.ToSingle(NudForce1.Value),
Convert.ToSingle(NudDistance1.Value), Convert.ToSingle(NudVelocity1.Value), 5000);
TsslStatus.Text = "PushWait " + rtn + " IsPushEmpty=" + axis.IsPushEmpty;
}
private void BtnAbsolute_Click(object sender, EventArgs e)
{
bool rtn = axis.MoveAbsoluteWait(Convert.ToSingle(NudPosition.Value),
Convert.ToSingle(NudVelocity2.Value), Convert.ToSingle(NudAcceleration.Value),
Convert.ToSingle(NudDeacceleration.Value), Convert.ToSingle(NudBand.Value), 5000);
TsslStatus.Text = "MoveAbsoluteWait " + rtn;
}
private void BtnReset_Click(object sender, EventArgs e)
{
axis.ResetError();
}
private void BtnStability_Click(object sender, EventArgs e)
{
if (testLoop)
{
StopTest();
return;
}
testLoop = true;
BtnStability.Text = "停止";
int[] param = new int[5];
param[0] = Convert.ToInt32(NudForce2.Value);
param[1] = Convert.ToInt32(NudDistance2.Value);
param[2] = Convert.ToInt32(NudVelocity3.Value);
param[3] = Convert.ToInt32(NudTimes.Value);
param[4] = Convert.ToInt32(NudInterval.Value);
tTest = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(PushTest));
tTest.Start(param);
}
}
}