using Rs.Controls; using Rs.DataAccess; using Rs.Framework; using Rs.MotionPlat.Commom; using Rs.MotionPlat.Flow; using Rs.MotionPlat.Flow.Camera; using Rs.MotionPlat.Flow.SubFlow; 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 Rs.MotionPlat.Recipe { /// /// 周转盘产品定位 /// public partial class TurnoverTrayProductLocate : BaseForm { private TraySlot selectedSlot; private string m_trayName = ETrayType.Turnover.ToString(); DataTable dt = new DataTable(); SqliteHelper db = new SqliteHelper(); public TurnoverTrayProductLocate() { InitializeComponent(); cameraTemplate1.ItemName = "周转盘产品定位"; cameraTemplate1.CustomDefineGrabEvent += () => { AxisControl.LoadX.ComparePulse(2, false); }; //cameraTemplate1.SetFindShapeMode(EFindShapeMode.SelfDefine); //cameraTemplate1.FindShapeEvent += CameraTemplate1_FindShapeEvent; } private void CameraTemplate1_FindShapeEvent(ChoiceTech.Halcon.Control.HWindow_Final arg1, HalconDotNet.HObject arg2) { string sn = BarCodeManager.FindCode(arg2); //throw new NotImplementedException(); } private void BindPoints() { string querySql = $"select * from TrayPoints where trayname='{m_trayName}' and recipename='{GlobalVar.CurRecipe}' order by slotindex"; DataTable dtBasePoints = db.GetDataTable(querySql); if (ObjectHelper.IsNotNullorEmpty(dtBasePoints)) { dgvBasePoints.DataSource = dtBasePoints; } } private void rsTray1_SlotClickEvent(TraySlot arg1, MouseEventArgs arg2) { selectedSlot = arg1; contextMenuStrip1.Show(MousePosition.X, MousePosition.Y); } private void goToolStripMenuItem_Click(object sender, EventArgs e) { if (selectedSlot != null) { int nozzleIndex = 0; string querySql = $"select * from TrayPoints where trayname='{m_trayName}' and slotindex={selectedSlot.Index}"; DataTable dtGoPosition = db.GetDataTable(querySql); if (ObjectHelper.IsNotNullorEmpty(dtGoPosition)) { double targetX = double.Parse(dtGoPosition.Rows[0]["X"].ToString()); double targetY = double.Parse(dtGoPosition.Rows[0]["Y"].ToString()); ToolStripMenuItem subMenu = sender as ToolStripMenuItem; ToolStripMenuItem parentMenu = (ToolStripMenuItem)subMenu.OwnerItem; if (parentMenu.Text.IndexOf("Nozzle") >= 0) { nozzleIndex = int.Parse(parentMenu.Text.Replace("Nozzle", "").Replace("GO", "")); SlotPoint dist = TrayPointManager.GetDistToNozzle1(nozzleIndex); targetX += dist.X; targetY += dist.Y; } DialogResult dr = Msg.ShowQuestion($"Are you sure to move loadx to {targetX},loady to {targetY}?"); if (dr == DialogResult.OK) { Motion.ErrorCode errCode = AxisControl.GetAxis("LoadX").MovePos(targetX, 4); if (errCode > Motion.ErrorCode.Ok) { Msg.ShowError($"axis loadx move fail,ret={errCode}"); return; } errCode = AxisControl.GetAxis("LoadY").MovePos(targetY, 4); if (errCode > Motion.ErrorCode.Ok) { Msg.ShowError($"axis loady move fail,ret={errCode}"); return; } } } } } private void TurnoverTrayProductLocate_Load(object sender, EventArgs e) { dgvBasePoints.AutoGenerateColumns = false; BindPoints(); PositionHelper.BindSinglePosition(txtTurnoverTrayLocateXRange); PositionHelper.BindSinglePosition(txtTurnoverTrayLocateYRange); PositionHelper.BindSinglePosition(txtTurnoverTrayLocateRRange); } private void btnLocateCheck_Click(object sender, EventArgs e) { Task.Run(() => { Invoke(new Action(() => { btnLocateCheck.Enabled = false; })); VisionResult vr = UpCameraScanBarCodeFlow.Instance.ScanSingle(1,false,true,false); //VisionResult vr= UpCameraScanBarCodeFlow.Instance.WaitSingle(); if(vr != null) { bool result = UpCameraScanBarCodeFlow.Instance.CheckResult(vr); if(result) { Invoke(new Action(() => { lblResult.BackColor = Color.Lime; lblResult.Text = "OK"; })); } else { Invoke(new Action(() => { lblResult.BackColor = Color.Red; lblResult.Text = "NG"; })); } } Invoke(new Action(() => { btnLocateCheck.Enabled = true; })); }); } private void txtTurnoverTrayLocateRange_KeyUp(object sender, KeyEventArgs e) { TextBox txt = (TextBox)sender; UpdateSysParam(txt); } } }