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.
326 lines
14 KiB
C#
326 lines
14 KiB
C#
using Rs.Camera;
|
|
using Rs.Controls;
|
|
using Rs.DataAccess;
|
|
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.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
|
|
|
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()
|
|
{
|
|
HikCamera.Instance.SetTrigger("upCamera", ETriggerMode.Manual, ETriggerSource.Software);
|
|
Ops.On("上相机光源");
|
|
Thread.Sleep(500);
|
|
HikCamera.Instance.Grab("upCamera");
|
|
Thread.Sleep(500);
|
|
Ops.Off("上相机光源");
|
|
//AxisControl.LoadX.ComparePulse(2, false);
|
|
}
|
|
|
|
private void BindPoints()
|
|
{
|
|
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))
|
|
{
|
|
dgvRunPoints.DataSource = dtRunPoints;
|
|
}
|
|
PositionHelper.BindSinglePosition(txtStockTrayOffsetX);
|
|
PositionHelper.BindSinglePosition(txttxtStockTrayOffsetY);
|
|
}
|
|
|
|
private void StockTrayLocationRecipe_Load(object sender, EventArgs e)
|
|
{
|
|
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;
|
|
dgvRunPoints.AutoGenerateColumns = false;
|
|
BindPoints();
|
|
}
|
|
|
|
private void btnCreateMatrix_Click(object sender, EventArgs e)
|
|
{
|
|
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 = double.Parse(txtMarkX1.Text) + (j * double.Parse(txtSlotOffsetDistX.Text))+GlobalVar.StockTrayOffsetX;
|
|
double yRun = double.Parse(txtMarkY1.Text) + (i * double.Parse(txtSlotOffsetDistY.Text))+GlobalVar.StockTrayOffsetY;
|
|
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})";
|
|
db.ExecuteNonQuery(insertRunSql);
|
|
index++;
|
|
}
|
|
}
|
|
BindPoints();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
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 trayid={dt.Rows[0]["id"]} 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;
|
|
}
|
|
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", "")}={pos} 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") && Ops.IsStop("LoadY"))
|
|
break;
|
|
Thread.Sleep(10);
|
|
}
|
|
DialogResult dr = Msg.ShowQuestion("Are you sure to take product?", MessageBoxButtons.OKCancel);
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
errCode = AxisControl.GetAxis($"NozzleZ{nozzleIndex}").MovePos(SysConfigParam.GetValue<double>($"TrayNozzle{nozzleIndex}TakeHeight"), GlobalVar.WholeSpeed);
|
|
if (errCode > ErrorCode.Ok) return;
|
|
while (!Ops.IsStop($"NozzleZ{nozzleIndex}"))
|
|
{
|
|
Thread.Sleep(10);
|
|
}
|
|
Ops.On($"{nozzleIndex}号吸嘴真空吸电磁阀");
|
|
Thread.Sleep(200);
|
|
errCode = AxisControl.GetAxis($"NozzleZ{nozzleIndex}").MovePos(0, GlobalVar.WholeSpeed);
|
|
if (errCode > ErrorCode.Ok) return;
|
|
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") && Ops.IsStop("LoadY"))
|
|
break;
|
|
Thread.Sleep(10);
|
|
}
|
|
DialogResult dr = Msg.ShowQuestion("Are you sure to dump product?", MessageBoxButtons.OKCancel);
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
errCode = AxisControl.GetAxis($"NozzleZ{nozzleIndex}").MovePos(SysConfigParam.GetValue<double>($"TrayNozzle{nozzleIndex}TakeHeight")+1, GlobalVar.WholeSpeed);
|
|
if (errCode > ErrorCode.Ok) return;
|
|
while (!Ops.IsStop($"NozzleZ{nozzleIndex}"))
|
|
{
|
|
Thread.Sleep(10);
|
|
}
|
|
Ops.Off($"{nozzleIndex}号吸嘴真空吸电磁阀");
|
|
Thread.Sleep(50);
|
|
|
|
Ops.On($"{nozzleIndex}号吸嘴真空破电磁阀");
|
|
Thread.Sleep(100);
|
|
Ops.Off($"{nozzleIndex}号吸嘴真空破电磁阀");
|
|
errCode = AxisControl.GetAxis($"NozzleZ{nozzleIndex}").MovePos(0, GlobalVar.WholeSpeed);
|
|
if (errCode > ErrorCode.Ok) return;
|
|
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)
|
|
{
|
|
UpdateSysParam((TextBox)sender);
|
|
}
|
|
}
|
|
}
|