namespace Main
{
public partial class ManipulatorControl : UserControl
{
private RobotManipulator robotManipulator = new RobotManipulator();
private RobotActionAndName _Finger;
public ManipulatorControl()
{
InitializeComponent();
}
/// <summary>
/// 显示数据
/// </summary>
public RobotActionAndName Finger
{
get
{
return _Finger;
}
set
{
_Finger = value;
if (_Finger == null) return;
txtIphoneName.Name = "TxtName" + _Finger.ID;
this.txtIphoneName.Text = _Finger.Name;
txtPhone1.Name = "txt" + _Finger.ID;
txtPhone1.Text = _Finger.SensorPortNO.ToString();
labPhoneState.Name = "lab" + _Finger.ID;
DeiveNO.Text = _Finger.DeviceNo.ToString();
DeiveNO.Name = "Dev" + _Finger.ID;
if (SensorController.Instance.jointComProvider != null)
labPhoneState.BackColor = SensorController.Instance.jointComProvider.GetInValue(_Finger.SensorPortNO) == 1 ? Color.Red : Color.Green;
}
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="finger"></param>
public ManipulatorControl(RobotManipulator manipulator, int ID) : this()
{
robotManipulator = manipulator;
var model = manipulator.robortActions.Where(p => p.ID == ID).FirstOrDefault();
if (model == null)
{
throw new Exception("初始化失败!");
}
this.Finger = model;
}
/// <summary>
/// 录入点位
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void butSetAction_Click(object sender, EventArgs e)
{
//切换坐标系。
JointRobotController.Instance.IphonCheng(_Finger.DeviceNo);
FormCreateActions form = new FormCreateActions(OperateEnums.SaveJson, null, robotManipulator, Finger.ID);
form.ShowDialog();
}
/// <summary>
/// 测试拿起
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void butTestup_Click(object sender, EventArgs e)
{
try
{
butTestup.Enabled = false;
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
if (Finger.Values.Count < 1)
{
MessageUtil.Warning("未配置坐标");
return;
}
JointRobotController.Instance.PlayActions(Finger.ID, 1);
}
finally
{
butTestup.Enabled = true;
this.Cursor = Cursors.Default;
}
}
/// <summary>
/// 测试放下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void butTestdown_Click(object sender, EventArgs e)
{
try
{
butTestdown.Enabled = false;
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
if (Finger.Values.Count < 1)
{
MessageUtil.Warning("未配置坐标");
return;
}
JointRobotController.Instance.PlayActions(Finger.ID, 2);
}
finally
{
butTestdown.Enabled = true;
this.Cursor = Cursors.Default;
}
}
/// <summary>
/// 添加仅限输入数字
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tb_KeyPress(object sender, KeyPressEventArgs e)
{
//如果输入的不是退格和数字,则屏蔽输入
if (!(e.KeyChar == '\b' || (e.KeyChar >= '0' && e.KeyChar <= '9')))
{
e.Handled = true;
}
}
}
}