using Rs.Controls; using Rs.Framework; using Rs.MotionPlat.Flow; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button; namespace Rs.MotionPlat.Commom { public class PositionHelper { public static void BindPosition(Control control,string dataType="double") { foreach (Control ctl in control.Controls) { if (ctl is TextBox) { TextBox txt = ((TextBox)ctl); if(dataType=="double") { txt.Text = SysConfigParam.GetValue(txt.Name.Replace("txt", "")).ToString("0.000"); } else if(dataType=="int") { txt.Text = SysConfigParam.GetValue(txt.Name.Replace("txt", "")).ToString(); } } } } public static void Teach(Form form,object btnSource,string xy="") { Button btn = (Button)btnSource; if(string.IsNullOrEmpty(xy)) { string name = "txt" + btn.Name.Replace("btnTeach", ""); Control control = ControlManager.FindControl(form, name); if (control != null) { string axisname = ((TextBox)control).Tag.ToString(); double pos = Ops.GetCurPosition(axisname); DialogResult dr = Msg.ShowQuestion($"Are you sure teach {name.Replace("txt", "")} axis position at {pos}?"); if (dr == DialogResult.OK) { ((TextBox)control).Text = pos.ToString("0.000"); SysConfigParam.Update(((TextBox)control).Name.Replace("txt", ""), pos.ToString()); } } } else { string[] axises = xy.Split(','); foreach (var item in axises) { string name = "txt" + btn.Name.Replace("btnTeach", "")+item; Control control = ControlManager.FindControl(form, name); if (control != null) { string axisname = ((TextBox)control).Tag.ToString(); double pos = Ops.GetCurPosition(axisname); DialogResult dr = Msg.ShowQuestion($"Are you sure teach {name.Replace("txt", "")} axis position at {pos}?"); if (dr == DialogResult.OK) { ((TextBox)control).Text = pos.ToString("0.000"); SysConfigParam.Update(((TextBox)control).Name.Replace("txt", ""), pos.ToString()); } } } } } public static void Move2This(Form form, object btnSource,string xy="") { Button btn = (Button)btnSource; if(string.IsNullOrEmpty(xy)) { string name = "txt" + btn.Name.Replace("btnMove", ""); Control control = ControlManager.FindControl(form, name); if (control != null) { string axisname = ((TextBox)control).Tag.ToString(); double gotoPos = double.Parse(((TextBox)control).Text); DialogResult dr = Msg.ShowQuestion($"Are you sure to move {axisname} to postion at: {gotoPos}"); if (dr == DialogResult.OK) { Motion.ErrorCode errCode = AxisControl.GetAxis(axisname).MovePos(gotoPos, 2); if(errCode> Motion.ErrorCode.Ok) { Msg.ShowError($"axis {axisname} move fail {errCode}"); } } } } else { string[] axises = xy.Split(','); foreach (var item in axises) { string name = "txt" + btn.Name.Replace("btnMove", "")+item; Control control = ControlManager.FindControl(form, name); if (control != null) { string axisname = ((TextBox)control).Tag.ToString(); double gotoPos = double.Parse(((TextBox)control).Text); DialogResult dr = Msg.ShowQuestion($"Are you sure to move {axisname} to postion at: {gotoPos}"); if (dr == DialogResult.OK) { AxisControl.GetAxis(axisname).MovePos(gotoPos, 2); } } } } } public static void Stop(object sender) { TextBox txt = (TextBox)sender; string axisname = txt.Tag.ToString(); AxisControl.GetAxis(axisname).Stop(); } } }