|
|
|
|
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.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Rs.MotionPlat.Recipe
|
|
|
|
|
{
|
|
|
|
|
public partial class TurnoverTrayExceptionNozzle : BaseForm
|
|
|
|
|
{
|
|
|
|
|
string trayName = "ForceNozzleTurnover";
|
|
|
|
|
SqliteHelper db = new SqliteHelper();
|
|
|
|
|
DataTable dt = new DataTable();
|
|
|
|
|
TraySlot selectedSlot;
|
|
|
|
|
public TurnoverTrayExceptionNozzle()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCreateMatrix_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string deleteSql = $"delete from traypoints where recipename='{GlobalVar.CurRecipe}' and trayname='{trayName}'";
|
|
|
|
|
if(db.ExecuteNonQuery(deleteSql)>0)
|
|
|
|
|
{
|
|
|
|
|
int rowNum = 4;
|
|
|
|
|
int colNum = 8;
|
|
|
|
|
int index = 1;
|
|
|
|
|
|
|
|
|
|
SlotPoint slotPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 1);
|
|
|
|
|
double dischargeNozzleX1 = double.Parse(txtMarkX1.Text);
|
|
|
|
|
double dischargeNozzleY1 = double.Parse(txtMarkY1.Text);
|
|
|
|
|
|
|
|
|
|
double markx2 = double.Parse(txtMarkX2.Text);
|
|
|
|
|
double marky2 = double.Parse(txtMarkY2.Text);
|
|
|
|
|
SlotPoint dist = TrayPointManager.GetDistToNozzle1(1);
|
|
|
|
|
//slotPoint.X += dist.X;
|
|
|
|
|
//slotPoint.Y += dist.Y;
|
|
|
|
|
|
|
|
|
|
double offsetX = slotPoint.X - dischargeNozzleX1;
|
|
|
|
|
double offsetY = slotPoint.Y - dischargeNozzleY1;
|
|
|
|
|
//计算出周转吸头要移动的目标位置
|
|
|
|
|
double targetX = markx2 + offsetX +dist.X;
|
|
|
|
|
double targetY = marky2 + offsetY +dist.Y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rowNum; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < colNum; j++)
|
|
|
|
|
{
|
|
|
|
|
double xRun = targetX + (j * double.Parse(dt.Rows[0]["SlotOffsetDistX"].ToString()));
|
|
|
|
|
double yRun = targetY + (i * double.Parse(dt.Rows[0]["SlotOffsetDistY"].ToString()));
|
|
|
|
|
string insertRunSql = $"insert into TrayPoints(trayid,recipename,trayname,slotindex,x,y) values({dt.Rows[0]["id"]},'{GlobalVar.CurRecipe}', '{dt.Rows[0]["TrayName"]}',{index},{xRun},{yRun})";
|
|
|
|
|
db.ExecuteNonQuery(insertRunSql);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BindPoints();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BindPoints()
|
|
|
|
|
{
|
|
|
|
|
string querySql = $"select * from normaltray where recipename='{GlobalVar.CurRecipe}' and trayname='ForceNozzleTurnover'";
|
|
|
|
|
dt = db.GetDataTable(querySql);
|
|
|
|
|
if (ObjectHelper.IsNotNullorEmpty(dt))
|
|
|
|
|
{
|
|
|
|
|
txtMarkX1.Text = dt.Rows[0]["MarkX1"].ToString();
|
|
|
|
|
txtMarkY1.Text = dt.Rows[0]["MarkY1"].ToString();
|
|
|
|
|
|
|
|
|
|
txtMarkX2.Text = dt.Rows[0]["MarkX2"].ToString();
|
|
|
|
|
txtMarkY2.Text = dt.Rows[0]["MarkY2"].ToString();
|
|
|
|
|
}
|
|
|
|
|
querySql = $"select * from TrayPoints where trayname='{dt.Rows[0]["TrayName"]}'";
|
|
|
|
|
DataTable dtRunPoints = db.GetDataTable(querySql);
|
|
|
|
|
if (ObjectHelper.IsNotNullorEmpty(dtRunPoints))
|
|
|
|
|
{
|
|
|
|
|
dgvRunPoints.DataSource = dtRunPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
string updateSql = $"update NormalTray set {txt.Name.Replace("txt", "")}={pos} where recipename='{GlobalVar.CurRecipe}' and trayname='{trayName}'";
|
|
|
|
|
if (db.ExecuteNonQuery(updateSql) > 0)
|
|
|
|
|
{
|
|
|
|
|
Msg.ShowInfo("teach point ok!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCalcAndMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// ErrorCode errCode = ErrorCode.Ok;
|
|
|
|
|
// //先获取周转吸头的当前位置
|
|
|
|
|
// double curX = Ops.GetCurPosition(AxisControl.TurnoverX);
|
|
|
|
|
// double curY = Ops.GetCurPosition(AxisControl.TurnoverY);
|
|
|
|
|
// //取出排料吸嘴1到周转盘1号取料位的位置
|
|
|
|
|
// SlotPoint slotPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 1);
|
|
|
|
|
// double dischargeNozzleX1 = double.Parse(txtMarkX1.Text);
|
|
|
|
|
// double dischargeNozzleY1 = double.Parse(txtMarkY1.Text);
|
|
|
|
|
|
|
|
|
|
// double markx2 = double.Parse(txtMarkX2.Text);
|
|
|
|
|
// double marky2 = double.Parse(txtMarkY2.Text);
|
|
|
|
|
// SlotPoint dist = TrayPointManager.GetDistToNozzle1(1);
|
|
|
|
|
//// slotPoint.X += dist.X;
|
|
|
|
|
// //slotPoint.Y += dist.Y;
|
|
|
|
|
|
|
|
|
|
// double offsetX=slotPoint.X- dischargeNozzleX1;
|
|
|
|
|
// double offsetY=slotPoint.Y- dischargeNozzleY1;
|
|
|
|
|
// //计算出周转吸头要移动的目标位置
|
|
|
|
|
// double targetX = markx2 + offsetX +dist.X;
|
|
|
|
|
// double targetY = marky2 + offsetY +dist.Y;
|
|
|
|
|
// errCode = AxisControl.TurnoverX.MovePos(targetX, 4);
|
|
|
|
|
// if(errCode == ErrorCode.Ok)
|
|
|
|
|
// {
|
|
|
|
|
// errCode=AxisControl.TurnoverY.MovePos(targetY, 4);
|
|
|
|
|
// if(errCode > ErrorCode.Ok )
|
|
|
|
|
// {
|
|
|
|
|
// Msg.ShowError($"{AxisAlias.TurnoverX}轴运动失败 ret:{errCode}");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// Msg.ShowError($"{AxisAlias.TurnoverX}轴运动失败 ret:{errCode}");
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TurnoverTrayExceptionNozzle_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
dgvRunPoints.AutoGenerateColumns = false;
|
|
|
|
|
BindPoints();
|
|
|
|
|
LoadSysParam(groupBox4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void rsTray1_SlotClickEvent(Controls.TraySlot arg1, MouseEventArgs arg2)
|
|
|
|
|
{
|
|
|
|
|
selectedSlot = arg1;
|
|
|
|
|
contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void moveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (selectedSlot != null)
|
|
|
|
|
{
|
|
|
|
|
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());
|
|
|
|
|
DialogResult dr = Msg.ShowQuestion($"Are you sure to move turnoverx to {targetX},turnovery to {targetY}?");
|
|
|
|
|
if (dr == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Motion.ErrorCode errCode = AxisControl.GetAxis("TurnoverX").MovePos(targetX, 4);
|
|
|
|
|
if (errCode > Motion.ErrorCode.Ok)
|
|
|
|
|
{
|
|
|
|
|
Msg.ShowError($"axis TurnoverX move fail,ret={errCode}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
errCode = AxisControl.GetAxis("TurnoverY").MovePos(targetY, 4);
|
|
|
|
|
if (errCode > Motion.ErrorCode.Ok)
|
|
|
|
|
{
|
|
|
|
|
Msg.ShowError($"axis TurnoverY move fail,ret={errCode}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void txtPoint_KeyUp(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TextBox txtKey = (TextBox)sender;
|
|
|
|
|
if (e.KeyCode == Keys.Enter)
|
|
|
|
|
{
|
|
|
|
|
string key = txtKey.Name.Replace("txt", "");
|
|
|
|
|
string value = txtKey.Text;
|
|
|
|
|
if (SysConfigParam.Update(key, value) > 0)
|
|
|
|
|
{
|
|
|
|
|
Msg.ShowInfo("Save success!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|