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.
442 lines
18 KiB
C#
442 lines
18 KiB
C#
using Rs.Controls;
|
|
using Rs.DataAccess;
|
|
using Rs.Framework;
|
|
using Rs.Motion;
|
|
using Rs.MotionPlat.Commom;
|
|
using Rs.MotionPlat.Flow;
|
|
using Rs.MotionPlat.Flow.NormalFlow;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rs.MotionPlat.Recipe
|
|
{
|
|
public partial class StockTrayLocationRecipe : BaseForm
|
|
{
|
|
private TraySlot selectedSlot;
|
|
private string m_trayName = "";
|
|
DataTable dt = new DataTable();
|
|
SqliteHelper db=new SqliteHelper();
|
|
|
|
public StockTrayLocationRecipe()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
public StockTrayLocationRecipe(string trayName)
|
|
{
|
|
InitializeComponent();
|
|
m_trayName = trayName;
|
|
//cameraTemplate1.ItemName = m_trayName;
|
|
//cameraTemplate1.CustomDefineGrabEvent += CameraTemplate1_CustomDefineGrabEvent;
|
|
}
|
|
|
|
private void CameraTemplate1_CustomDefineGrabEvent()
|
|
{
|
|
AxisControl.LoadX.ComparePulse(2, false);
|
|
}
|
|
|
|
private void BindPoints()
|
|
{
|
|
BindBasePoint();
|
|
BindRunPoint();
|
|
}
|
|
|
|
void BindBasePoint()
|
|
{
|
|
string querySql = $"select * from TrayPoints where trayname='{m_trayName}' and recipename='{GlobalVar.CurRecipe}' order by slotindex";
|
|
DataTable dtRunPoints = db.GetDataTable(querySql);
|
|
if (ObjectHelper.IsNotNullorEmpty(dtRunPoints))
|
|
{
|
|
dgvBasePoints.DataSource = dtRunPoints;
|
|
}
|
|
}
|
|
|
|
void BindRunPoint()
|
|
{
|
|
dgvRunPoints.DataSource = TrayRunPointManager.GetData(m_trayName);
|
|
//string querySql = $"select * from TrayRunPoints where trayname='{m_trayName}' and recipename='{GlobalVar.CurRecipe}' order by slotindex";
|
|
//DataTable dtRunPoints = db.GetDataTable(querySql);
|
|
//if (ObjectHelper.IsNotNullorEmpty(dtRunPoints))
|
|
//{
|
|
// dgvRunPoints.DataSource = dtRunPoints;
|
|
//}
|
|
}
|
|
|
|
private void StockTrayLocationRecipe_Load(object sender, EventArgs e)
|
|
{
|
|
CheckPermission();
|
|
if(m_trayName=="Input" || m_trayName=="Grab")
|
|
{
|
|
btnThreePointLocation.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
btnThreePointLocation.Visible = true;
|
|
}
|
|
LanguageHelper.LoadLanguage(this, this.GetType());
|
|
rsTray1.HeadText= m_trayName;
|
|
string querySql = $"select * from NormalTray where trayname='{m_trayName}' and recipename='{GlobalVar.CurRecipe}'";
|
|
dt = db.GetDataTable(querySql);
|
|
if (ObjectHelper.IsNotNullorEmpty(dt))
|
|
{
|
|
DataRow dr = dt.Rows[0];
|
|
foreach (DataColumn dc in dt.Columns)
|
|
{
|
|
string columname = dc.ColumnName;
|
|
Control txt = ControlManager.FindControl(groupBox1, "txt" + columname);
|
|
if (txt != null)
|
|
{
|
|
txt.Text = dr[columname].ToString();
|
|
rsTray1.ColumnNum = int.Parse(dr["ColumnNum"].ToString());
|
|
rsTray1.RowNum = int.Parse(dr["RowNum"].ToString());
|
|
}
|
|
}
|
|
}
|
|
//dgvBasePoints.AutoGenerateColumns = false;
|
|
dgvBasePoints.AutoGenerateColumns = false;
|
|
dgvRunPoints.AutoGenerateColumns = false;
|
|
BindPoints();
|
|
|
|
}
|
|
|
|
private void btnCreateMatrix_Click(object sender, EventArgs e)
|
|
{
|
|
btnCreateMatrix.Enabled = false;
|
|
btnThreePointLocation.Enabled = false;
|
|
List<string> executeSql = new List<string>();
|
|
int rowEffect = 0;
|
|
if (ObjectHelper.IsNotNullorEmpty(dt))
|
|
{
|
|
string deleteSql = $"delete from TrayPoints where trayid='{dt.Rows[0]["ID"]}'";
|
|
rowEffect = db.ExecuteNonQuery(deleteSql);
|
|
if (rowEffect >= 0)
|
|
{
|
|
int rowNum = int.Parse(dt.Rows[0]["RowNum"].ToString());
|
|
int colNum = int.Parse(dt.Rows[0]["ColumnNum"].ToString());
|
|
int index = 1;
|
|
for (int i = 0; i < rowNum; i++)
|
|
{
|
|
for (int j = 0; j < colNum; j++)
|
|
{
|
|
int tempIndex = (colNum + 1) - (index - (i * colNum)) + (i * colNum);
|
|
double xRun = 0.0;
|
|
double yRun = 0.0;
|
|
if(rsTray1.SortDir== ESortDir.LeftToRight)
|
|
{
|
|
xRun = double.Parse(txtMarkX1.Text) + (j * double.Parse(txtSlotOffsetDistX.Text));
|
|
yRun = double.Parse(txtMarkY2.Text) + (i * double.Parse(txtSlotOffsetDistY.Text));
|
|
}
|
|
else if(rsTray1.SortDir== ESortDir.LeftBottomToTop)
|
|
{
|
|
xRun = double.Parse(txtMarkX1.Text) + (i * double.Parse(txtSlotOffsetDistX.Text));
|
|
yRun = double.Parse(txtMarkY2.Text) + (j * double.Parse(txtSlotOffsetDistY.Text));
|
|
}
|
|
|
|
string insertRunSql = $"insert into TrayPoints(trayid,recipename,trayname,slotindex,x,y) values('{dt.Rows[0]["id"]}','{dt.Rows[0]["recipename"]}','{dt.Rows[0]["TrayName"]}',{index},{xRun},{yRun})";
|
|
executeSql.Add(insertRunSql);
|
|
|
|
index++;
|
|
}
|
|
}
|
|
if(executeSql!=null&&executeSql.Count>0)
|
|
{
|
|
string sql = string.Join(";", executeSql);
|
|
rowEffect = db.ExecuteNonQuery(sql);
|
|
if(rowEffect>0)
|
|
{
|
|
Msgbox.ShowDialog(EButtonType.Ok, $"{rowEffect} data updated!");
|
|
}
|
|
}
|
|
BindPoints();
|
|
TrayPointManager.LoadPoint();
|
|
btnCreateMatrix.Enabled = true;
|
|
btnThreePointLocation.Enabled = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
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 = string.Empty;
|
|
//if(m_trayName=="Input" || m_trayName=="Ng")
|
|
{
|
|
querySql = $"select * from TrayPoints where trayname='{dt.Rows[0]["trayname"]}' and slotindex={selectedSlot.Index}";
|
|
}
|
|
//else
|
|
//{
|
|
//querySql = $"select * from TrayRunPoints where trayname='{dt.Rows[0]["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 += NozzleManager.GetNozzleToCameraOffsetX(nozzleIndex);
|
|
targetY += NozzleManager.GetNozzleToCameraOffsetY2(nozzleIndex);
|
|
}
|
|
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("LoadY1").MovePos(GlobalVar.StockSideY1, 4);
|
|
if (errCode > Motion.ErrorCode.Ok)
|
|
{
|
|
Msg.ShowError($"axis loady1 move fail,ret={errCode}");
|
|
return;
|
|
}
|
|
errCode = AxisControl.GetAxis("LoadY2").MovePos(targetY,4);
|
|
if (errCode > Motion.ErrorCode.Ok)
|
|
{
|
|
Msg.ShowError($"axis loady2 move fail,ret={errCode}");
|
|
return;
|
|
}
|
|
if (subMenu.Text.IndexOf("TakeProduct") >= 0)
|
|
{
|
|
TakeProduct(selectedSlot.Index, nozzleIndex);
|
|
}
|
|
else if (subMenu.Text.IndexOf("DumpProduct") >= 0)
|
|
{
|
|
DumpProduct(selectedSlot.Index, nozzleIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnTeach_Click(object sender, EventArgs e)
|
|
{
|
|
Button btnTeach = (Button)sender;
|
|
string name = btnTeach.Name.Replace("btnTeach", "");
|
|
Control txt = ControlManager.FindControl(groupBox1, "txt" + name);
|
|
if (txt != null)
|
|
{
|
|
double pos = Ops.GetCurPosition(txt.Tag.ToString());
|
|
txt.Text = pos.ToString("0.000");
|
|
if (ObjectHelper.IsNotNullorEmpty(dt))
|
|
{
|
|
string updateSql = $"update NormalTray set {txt.Name.Replace("txt", "")}={txt.Text} where recipename='{GlobalVar.CurRecipe}' and trayname='{dt.Rows[0]["trayname"]}'";
|
|
if (db.ExecuteNonQuery(updateSql) > 0)
|
|
{
|
|
Msg.ShowInfo("teach point ok!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnMove_Click(object sender, EventArgs e)
|
|
{
|
|
Button btnTeach = (Button)sender;
|
|
string name = btnTeach.Name.Replace("btnMove", "");
|
|
Control txt = ControlManager.FindControl(groupBox1, "txt" + name);
|
|
if (txt != null)
|
|
{
|
|
double targetPos = double.Parse(txt.Text);
|
|
DialogResult dr = Msg.ShowQuestion($"are you sure to move axis {txt.Tag} to postion at:{targetPos}?");
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
Motion.ErrorCode errCode = AxisControl.GetAxis(txt.Tag.ToString()).MovePos(targetPos, 4);
|
|
if (errCode != Motion.ErrorCode.Ok)
|
|
{
|
|
Msg.ShowError($"axis {txt.Tag.ToString()} move fail {errCode}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnSavePoint_Click(object sender, EventArgs e)
|
|
{
|
|
Button button = (Button)sender;
|
|
string name = button.Name.Replace("btnSave", "");
|
|
Control txt = ControlManager.FindControl(this, "txt" + name);
|
|
if (txt != null)
|
|
{
|
|
if(ObjectHelper.IsNotNullorEmpty(dt))
|
|
{
|
|
string updateSql = $"update NormalTray set {name}={txt.Text} where id={dt.Rows[0]["id"]}";
|
|
if(db.ExecuteNonQuery(updateSql)>0)
|
|
{
|
|
Msg.ShowInfo("save ok!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取料
|
|
/// </summary>
|
|
private void TakeProduct(int slotIndex, int nozzleIndex)
|
|
{
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
Task.Run(() => {
|
|
while (true)
|
|
{
|
|
if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
|
|
break;
|
|
Thread.Sleep(10);
|
|
}
|
|
DialogResult dr = Msg.ShowQuestion("Are you sure to take product?", MessageBoxButtons.OKCancel);
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
Nozzle takeNozzle=NozzleManager.GetNozzle(nozzleIndex);
|
|
if(Enum.TryParse<ETrayType>(m_trayName, out ETrayType takeTray))
|
|
{
|
|
double pos = NozzleManager.GetNozzleToTrayTakeProductPos(takeTray, nozzleIndex);
|
|
errCode = AxisControl.GetAxis($"NozzleZ{nozzleIndex}").MovePos(pos, GlobalVar.WholeSpeed);
|
|
if (errCode > ErrorCode.Ok) return;
|
|
while (!Ops.IsStop($"NozzleZ{nozzleIndex}"))
|
|
{
|
|
Thread.Sleep(10);
|
|
}
|
|
takeNozzle.VacSuction(EIoOperate.Open,nameof(StockTrayLocationRecipe));
|
|
if (NozzleManager.GotoSafePos(nozzleIndex))
|
|
{
|
|
while (!Ops.IsStop($"NozzleZ{nozzleIndex}"))
|
|
{
|
|
Thread.Sleep(10);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 放料
|
|
/// </summary>
|
|
private void DumpProduct(int slotIndex, int nozzleIndex)
|
|
{
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
Task.Run(() => {
|
|
while (true)
|
|
{
|
|
if (Ops.IsStop("LoadX", "LoadY1", "LoadY2"))
|
|
break;
|
|
Thread.Sleep(10);
|
|
}
|
|
DialogResult dr = Msg.ShowQuestion("Are you sure to dump product?", MessageBoxButtons.OKCancel);
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
Nozzle takeNozzle = NozzleManager.GetNozzle(nozzleIndex);
|
|
if (Enum.TryParse<ETrayType>(m_trayName, out ETrayType takeTray))
|
|
{
|
|
double pos = NozzleManager.GetNozzleToTrayTakeProductPos(takeTray, nozzleIndex);
|
|
errCode = AxisControl.GetAxis($"NozzleZ{nozzleIndex}").MovePos(pos, GlobalVar.WholeSpeed);
|
|
if (errCode > ErrorCode.Ok) return;
|
|
while (!Ops.IsStop($"NozzleZ{nozzleIndex}"))
|
|
{
|
|
Thread.Sleep(10);
|
|
}
|
|
takeNozzle.VacSuction(EIoOperate.Close,nameof(StockTrayLocationRecipe));
|
|
takeNozzle.VacBreak(EIoOperate.Open,nameof(StockTrayLocationRecipe));
|
|
takeNozzle.VacBreak(EIoOperate.Close, nameof(StockTrayLocationRecipe));
|
|
if (NozzleManager.GotoSafePos(nozzleIndex))
|
|
{
|
|
while (!Ops.IsStop($"NozzleZ{nozzleIndex}"))
|
|
{
|
|
Thread.Sleep(10);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private void btnCreateTrayStatus_Click(object sender, EventArgs e)
|
|
{
|
|
string deleteSql = $"delete from traystatus where trayname='{m_trayName}'";
|
|
db.ExecuteNonQuery(deleteSql);
|
|
string insertSql = "insert into traystatus(trayname,slotindex,status) values('{0}',{1},{2})";
|
|
for (int row = 1; row <= rsTray1.RowNum; row++)
|
|
{
|
|
for (int col = 1; col <= rsTray1.ColumnNum; col++)
|
|
{
|
|
int index = col + (row - 1) * rsTray1.ColumnNum;
|
|
string executeSql = string.Format(insertSql, m_trayName, index, 0);
|
|
db.ExecuteNonQuery(executeSql);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void txtSysParam_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if(e.KeyCode== Keys.Enter)
|
|
{
|
|
UpdateSysParam((TextBox)sender);
|
|
}
|
|
}
|
|
|
|
private void dgvRunPoints_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
DataGridView dgv=(DataGridView)sender;
|
|
if(e.RowIndex>=0)
|
|
{
|
|
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red ;
|
|
}
|
|
}
|
|
|
|
private void dgvRunPoints_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
DataGridView dgv = (DataGridView)sender;
|
|
if (e.RowIndex >= 0)
|
|
{
|
|
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(11, 16, 36);
|
|
}
|
|
}
|
|
|
|
private void btnThreePointLocation_Click(object sender, EventArgs e)
|
|
{
|
|
Task.Run(() => {
|
|
if(m_trayName=="Ng")
|
|
{
|
|
ThreePointLocationFlow.Instance.Location(ETrayType.Ng);
|
|
}
|
|
else if(m_trayName== "ReTest")
|
|
{
|
|
ThreePointLocationFlow.Instance.Location(ETrayType.ReTest);
|
|
}
|
|
else if (m_trayName == "Grr")
|
|
{
|
|
ThreePointLocationFlow.Instance.Location(ETrayType.Grr);
|
|
}
|
|
else if (m_trayName == "Ok")
|
|
{
|
|
ThreePointLocationFlow.Instance.Location(ETrayType.Ok);
|
|
}
|
|
BindPoints();
|
|
});
|
|
}
|
|
}
|
|
}
|