You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
215 lines
6.0 KiB
C#
215 lines
6.0 KiB
C#
using Rs.Motion.Base;
|
|
using Rs.Motion.GugaoEcat;
|
|
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 Rs.Motion;
|
|
using System.Threading;
|
|
|
|
namespace Rs.MotionPlat
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
|
|
private IAxis Axis1
|
|
{
|
|
get
|
|
{
|
|
return GugaoCardManager.Instance.GetCard(0).GetAxis(1);
|
|
}
|
|
}
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
ErrorCode errcode = GugaoCardManager.Instance.Init();
|
|
if(errcode== ErrorCode.Ok)
|
|
{
|
|
timer1.Enabled = true;
|
|
richTextBox1.AppendText("卡初始化成功\r\n");
|
|
}
|
|
else
|
|
richTextBox1.AppendText("卡初始化失败\r\n");
|
|
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
ErrorCode errcode;
|
|
ICard card = GugaoCardManager.Instance.GetCard(0);
|
|
IAxis axis = card.GetAxis(1);
|
|
axis.IsEnable(out bool bEnable);
|
|
if(bEnable)
|
|
{
|
|
errcode = axis.Disable();
|
|
}
|
|
else
|
|
errcode = axis.Enable();
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
Axis1.GetPrfPosition(out double prfPos);
|
|
textBox1.Text = prfPos.ToString();
|
|
Axis1.GetEncoderPosition(out double encPos);
|
|
textBox2.Text = encPos.ToString();
|
|
|
|
Axis1.IsEnable(out bool bEnable);
|
|
if (bEnable)
|
|
btnSevon.BackColor = Color.Lime;
|
|
else
|
|
btnSevon.BackColor = SystemColors.Control;
|
|
|
|
Axis1.GetPelStatus(out bool bP);
|
|
if (bP)
|
|
btnPositive.BackColor = Color.Lime;
|
|
else
|
|
btnPositive.BackColor = SystemColors.Control;
|
|
|
|
Axis1.GetNelStatus(out bool bN);
|
|
if (bN)
|
|
btnNagetive.BackColor = Color.Lime;
|
|
else
|
|
btnNagetive.BackColor = SystemColors.Control;
|
|
|
|
Axis1.GetAlarmStatus(out bool bAlarm);
|
|
if (bAlarm)
|
|
btnAlarm.BackColor = Color.Lime;
|
|
else
|
|
btnAlarm.BackColor = SystemColors.Control;
|
|
|
|
Axis1.GetOrgStatus(out bool bOrg);
|
|
if (bOrg)
|
|
btnHome.BackColor = Color.Lime;
|
|
else
|
|
btnHome.BackColor = SystemColors.Control;
|
|
|
|
}
|
|
|
|
private void button5_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
ErrorCode errorCode = Axis1.MoveJog(1, 5);
|
|
if(errorCode> ErrorCode.Ok)
|
|
{
|
|
richTextBox1.AppendText($"运动失败{errorCode}");
|
|
}
|
|
}
|
|
|
|
private void button5_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
ErrorCode errorCode = Axis1.Stop();
|
|
if (errorCode > ErrorCode.Ok)
|
|
{
|
|
richTextBox1.AppendText($"停止{errorCode}");
|
|
}
|
|
}
|
|
|
|
private void button4_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
ErrorCode errorCode = Axis1.MoveJog(0, 5);
|
|
if (errorCode > ErrorCode.Ok)
|
|
{
|
|
richTextBox1.AppendText($"运动失败{errorCode}");
|
|
}
|
|
}
|
|
|
|
private void button4_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
ErrorCode errorCode = Axis1.Stop();
|
|
if (errorCode > ErrorCode.Ok)
|
|
{
|
|
richTextBox1.AppendText($"停止{errorCode}");
|
|
}
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
int step = 0;
|
|
Task.Run(() => {
|
|
|
|
while (true)
|
|
{
|
|
switch(step)
|
|
{
|
|
case 0:
|
|
Axis1.MovePos(startpos, vel);
|
|
step++;
|
|
break;
|
|
case 1:
|
|
Axis1.IsStop(out bool bStop);
|
|
if (bStop)
|
|
{
|
|
Thread.Sleep(200);
|
|
step++;
|
|
}
|
|
break;
|
|
case 2:
|
|
Axis1.MovePos(endpos, vel);
|
|
step++;
|
|
break;
|
|
case 3:
|
|
Axis1.IsStop(out bool bStoped);
|
|
if (bStoped)
|
|
{
|
|
Thread.Sleep(200);
|
|
step = 0;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
double startpos = -50;
|
|
double endpos = -170;
|
|
int vel = 50;
|
|
private void textBox3_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void textBox4_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void textBox5_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void textBox4_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if(e.KeyCode== Keys.Enter)
|
|
startpos = double.Parse(textBox4.Text);
|
|
}
|
|
|
|
private void textBox5_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
endpos = double.Parse(textBox5.Text);
|
|
}
|
|
|
|
private void textBox3_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
vel = int.Parse(textBox3.Text);
|
|
}
|
|
}
|
|
}
|