using Rs.Camera; using Rs.Controls; using Rs.Framework; using Rs.Motion; using Rs.MotionPlat.Commom; using Rs.MotionPlat.Flow; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace Rs.MotionPlat { public partial class TrayRecipe : BaseForm { private string m_ItemName; public TrayRecipe() { InitializeComponent(); } public TrayRecipe(string itemName) { InitializeComponent(); m_ItemName = itemName; cameraTemplate1.ItemName = m_ItemName; } private void TrayRecipe_Load(object sender, EventArgs e) { dataGridView1.AutoGenerateColumns = false; rsTray1.HeadText = m_ItemName; timer1.Interval = 1000; timer1.Enabled = true; rsTray1.ItemName = m_ItemName; rsTray1.OffsetX = -12.8f; rsTray1.OffsetY = 33.9f; if (m_ItemName == "Turnover") { rsTray1.SinglePoint = true; rsTray1.RowNum = 4; rsTray1.ColumnNum = 8; rsTray1.OffsetX = 45; rsTray1.OffsetY = -50; } else if (m_ItemName == "下相机") { panel2.Visible = false; } //rsTray1.Init(); rsTray1.Clear(); //slot_lefttop.Position = rsTray1.GetLeftTop();//.LeftTop; //slot_leftbottom.Position = rsTray1.GetLeftBottom(); //slot_rightbottom.Position = rsTray1.GetRightBottom(); //dataGridView1.DataSource = rsTray1.GetAllSlot().Select(sp => new { Index = sp.Index, X = sp.Position.X, Y = sp.Position.Y }).ToList(); } int val = 0; private void timer1_Tick(object sender, EventArgs e) { if (val == 0) val = 1; else if (val == 1) val = 0; if (m_ItemName=="中转盘") { rsTray1.ChangeStatus(1, val == 0 ? ESlotStatus.NotHave : ESlotStatus.Have); rsTray1.ChangeStatus(25, val == 0 ? ESlotStatus.NotHave : ESlotStatus.Have); } else { rsTray1.ChangeStatus(1, val == 0 ? ESlotStatus.NotHave : ESlotStatus.Have); rsTray1.ChangeStatus(251, val == 0 ? ESlotStatus.NotHave : ESlotStatus.Have); } rsTray1.ChangeStatus(1, val==0? ESlotStatus.NotHave:ESlotStatus.Have); rsTray1.ChangeStatus(251, val == 0 ? ESlotStatus.NotHave : ESlotStatus.Have); //rsTray1.ChangeStatus(260, val == 0 ? ESlotStatus.NotHave : ESlotStatus.Have); } protected void SavePosEvent(object sender, EventArgs e) { //if (rsTray1.Save()) //{ // dataGridView1.DataSource = null; // dataGridView1.DataSource = rsTray1.GetAllSlot().Select(sp => new { Index = sp.Index, X = sp.Position.X, Y = sp.Position.Y }).ToList(); // Msg.ShowInfo("Save point success!"); //} } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { //if (e.RowIndex >= 0) //{ // if (e.ColumnIndex == 3) // { // int slot = e.RowIndex + 1; // DialogResult dr = MessageBox.Show($"确定移动到{slot}号槽位吗?","Tips",MessageBoxButtons.OKCancel,MessageBoxIcon.Question); // if(dr== DialogResult.OK) // { // TraySlot ts =rsTray1.GetAllSlot()[slot - 1]; // AxisControl.LoadX.MovePos(ts.Position.X,10); // AxisControl.LoadY.MovePos(ts.Position.Y, 10); // } // } //} } private void rsTray1_SlotClickEvent(TraySlot obj, MouseEventArgs e) { contextMenuStrip1.Show(rsTray1, new Point(e.Location.X+15,e.Location.Y+40)); } private void tsmi_go_Click(object sender, EventArgs e) { //DialogResult dr = MessageBox.Show($"确定移动到{rsTray1.SelectSlot.Index.ToString()}号槽位吗?", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); //if(dr== DialogResult.OK) //{ // TraySlot ts =rsTray1.GetSlot(rsTray1.SelectSlot.Index); // AxisControl.LoadX.MovePos(ts.Position.X, 10); // AxisControl.LoadY.MovePos(ts.Position.Y, 10); //} } private void slot_lefttop_MoveCameraEvent(object sender, EventArgs e) { MoveToThis(sender); } private void slot_leftbottom_MoveCameraEvent(object sender, EventArgs e) { MoveToThis(sender); } private void slot_rightbottom_MoveCameraEvent(object sender, EventArgs e) { MoveToThis(sender); } private void MoveToThis(object sender) { TrayLocation trayLocation = (TrayLocation)sender; AxisControl.LoadX.MovePos(trayLocation.PosX, 10); AxisControl.LoadY.MovePos(trayLocation.PosY, 10); } private void slot_lefttop_FetchPositionEvent(object sender, EventArgs e) { //ErrorCode errCode = AxisControl.LoadX.GetEncoderPosition(out double dEncPosX); //if (errCode > ErrorCode.Ok) //{ // Msg.ShowError(errCode.ToString()); // return; //} //AxisControl.LoadY.GetEncoderPosition(out double dEncPosY); //if (errCode > ErrorCode.Ok) //{ // Msg.ShowError(errCode.ToString()); // return; //} //slot_lefttop.Position = new PointF((float)dEncPosX, (float)dEncPosY); //rsTray1.SetLeftTop(slot_lefttop.Position); } private void slot_leftbottom_FetchPositionEvent(object sender, EventArgs e) { //ErrorCode errCode = AxisControl.LoadX.GetEncoderPosition(out double dEncPosX); //if (errCode > ErrorCode.Ok) //{ // Msg.ShowError(errCode.ToString()); // return; //} //AxisControl.LoadY.GetEncoderPosition(out double dEncPosY); //if (errCode > ErrorCode.Ok) //{ // Msg.ShowError(errCode.ToString()); // return; //} //slot_leftbottom.Position = new PointF((float)dEncPosX, (float)dEncPosY); //rsTray1.SetLeftBottom(slot_leftbottom.Position); } private void TrayRecipe_FormClosing(object sender, FormClosingEventArgs e) { cameraTemplate1.RemoveGrabEvent(); } } }