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.Threading;
|
using System.Windows.Forms;
|
using Newtonsoft.Json;
|
using EnumType;
|
using IWareDataAccess.EF;
|
using Seagull.BarTender.Print;
|
using System.IO;
|
|
namespace DeviceWCS
|
{
|
public partial class Form1 : Form
|
{
|
srmSER.SrmService srmOPC = new srmSER.SrmService();
|
rgvSRM.RgvService rgvOPC = new rgvSRM.RgvService();
|
tranSRM.SrmTranService tranOPC = new tranSRM.SrmTranService();
|
srmInfo SrmInfo = new srmInfo();
|
rgvINFO Rgvinfo = new rgvINFO();
|
tranInfo TranInfo = new tranInfo();
|
int srmNO = 1;
|
int rgvNO = 1;
|
int tranNO = 1;
|
|
//static Engine btEngine = new Engine();
|
//LabelFormatDocument btFormatEu = btEngine.Documents.Open(Path.Combine(@"F:\", "EUPrint.btw"));//这里是Bartender软件生成的模板文件,你需要先把模板文件做好。
|
//LabelFormatDocument btFormatIs = btEngine.Documents.Open(Path.Combine(@"F:\", "IsOkPrint.btw"));//这里是Bartender软件生成的模板文件,你需要先把模板文件做好。
|
public Form1()
|
{
|
InitializeComponent();
|
this.dGVQuery.AutoGenerateColumns = false;
|
|
Control.CheckForIllegalCrossThreadCalls = false;
|
Thread thsrm = new Thread(srmInfo);
|
thsrm.Start();
|
Thread thrgv = new Thread(rgvinfo);
|
thrgv.Start();
|
Thread thtran = new Thread(traninfo);
|
thtran.Start();
|
|
//Thread thprint = new Thread(thprintinfo);
|
// thprint.Start();
|
|
}
|
|
//private void thprintinfo(object obj)
|
//{
|
// while (true)
|
// {
|
// using (Model md = new Model())
|
// {
|
// var printinfo = md.BASE_PRINT.OrderBy(x => x.CREATETIME).FirstOrDefault(x=>x.STATE==0);
|
// int type = printinfo.TYPE;
|
// LabelFormatDocument btFormat;
|
// if (type == 1)
|
// {
|
|
// btFormat = btFormatEu;
|
// }
|
// else
|
// {
|
// btFormat = btFormatIs;
|
// }
|
|
// btEngine.Start();
|
// btFormat.PrintSetup.PrinterName = printinfo.PRINTDEVNAME;// "80mmThermalPrinter";//打印机名称
|
// btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; //打印份数
|
// Messages messages;
|
// int waitout = 1000; // 10秒 超时
|
|
// if (type == 1)
|
// {
|
// btFormat.SubStrings["ItemNum"].Value = printinfo.ITEMNUM;//为Bartender里的数据源(文本框、条码等等)传值
|
// btFormat.SubStrings["ItemTypeNum"].Value = printinfo.ITEMTYPENUM;//为Bartender里的数据源(文本框、条码等等)传值
|
// btFormat.SubStrings["CVIQRCode"].Value = printinfo.CVIQRCODE;//为Bartender里的数据源(文本框、条码等等)传值
|
// }
|
// else
|
// {
|
// btFormat.SubStrings["Num"].Value = printinfo.NUM;//为Bartender里的数据源(文本框、条码等等)传值
|
// btFormat.SubStrings["ItemCode"].Value = printinfo.ITEMCODE;//为Bartender里的数据源(文本框、条码等等)传值
|
// btFormat.SubStrings["ItemName"].Value = printinfo.ITEMNAME;//为Bartender里的数据源(文本框、条码等等)传值
|
// btFormat.SubStrings["ProductLine"].Value = printinfo.BACKUP1;//为Bartender里的数据源(文本框、条码等等)传值
|
// }
|
// btFormat.SubStrings["CVICode"].Value = printinfo.CVICODE;//为Bartender里的数据源(文本框、条码等等)传值
|
// btFormat.SubStrings["IsOk"].Value = printinfo.ISOK; ;//为Bartender里的数据源(文本框、条码等等)传值
|
|
// btFormat.SubStrings["CreateTime"].Value = ((DateTime)printinfo.CREATETIME).ToString("yyyy-MM-dd");//为Bartender里的数据源(文本框、条码等等)传值
|
// Result nResult1 = btFormat.Print("标签打印软件", waitout, out messages);
|
// btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.Daily;
|
// Resolution rl = new Resolution(300, 300);
|
// //string name = DateTime.Now.ToLongDateString();
|
// // btFormat.ExportImageToFile(@"F:\"+"name.png", ImageType.PNG, ColorDepth.Mono, rl, OverwriteOptions.Overwrite);
|
// btFormat.Close(SaveOptions.DoNotSaveChanges);//不保存对打开模板的修改
|
// btEngine.Stop();
|
|
// if (nResult1.ToString() == "Success" || nResult1.ToString() == "0")
|
// {
|
// printinfo.STATE=1;
|
// }
|
// md.SaveChanges();
|
// }
|
// Thread.Sleep(1000);
|
// }
|
//}
|
#region 枚举
|
|
/// <summary>堆垛机号
|
///
|
/// </summary>
|
public enum srmid
|
{
|
一号堆垛机 = 1,
|
二号堆垛机 = 2,
|
三号堆垛机 = 3,
|
四号堆垛机 = 4,
|
五号堆垛机 = 5,
|
六号堆垛机 = 6,
|
七号堆垛机 = 7,
|
八号堆垛机 = 8,
|
九号堆垛机 = 9
|
}
|
|
/// <summary>堆垛机命令
|
///
|
/// </summary>
|
public enum command
|
{
|
搬运 = 1,
|
单放 = 2,
|
移动 = 3
|
}
|
|
/// <summary>堆垛机模式
|
///
|
/// </summary>
|
public enum srmMode
|
{
|
自动模式 = 1,
|
手动模式 = 2,
|
半自动模式 = 3,
|
维修模式 = 4,
|
关机模式 = 0
|
}
|
|
/// <summary>堆垛机状态
|
///
|
/// </summary>
|
public enum srmState
|
{
|
空闲 = 0,
|
取货定位中 = 1,
|
请求取货 = 2,
|
取货中 = 3,
|
取货完成放货定位中 = 4,
|
请求放货 = 5,
|
放货中 = 6,
|
维修 = 98,
|
报警 = 99
|
}
|
|
/// <summary>货叉位置
|
///
|
/// </summary>
|
public enum liftPosition
|
{
|
货叉原位 = 0,
|
货叉在左侧 = 1,
|
货叉在右侧 = 2
|
}
|
/// <summary>RGVid枚举
|
///
|
/// </summary>
|
public enum rgvid
|
{
|
一号RGV = 1,
|
二号RGV = 2,
|
三号RGV = 3,
|
四号RGV = 4
|
}
|
|
#endregion
|
|
|
/// <summary>自动选择任务号
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void comboBox2_SelectionChangeCommitted(object sender, EventArgs e)
|
{
|
int a = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
textBox1.Text = (a * 1111).ToString();
|
}
|
/// <summary>优化显示
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
if (comboBox1.Text == "单放" || comboBox1.Text == "移动")
|
{
|
textBox2.Enabled = false;
|
//comboBox3.Enabled = false;
|
}
|
else
|
{
|
textBox2.Enabled = true;
|
comboBox3.Enabled = true;
|
}
|
}
|
|
/// <summary>发送堆垛机任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button1_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
if (comboBox1.Text == "搬运")
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
int taskid = int.Parse(textBox1.Text);
|
int pallet = int.Parse(comboBox3.Text.Split('-')[0]);
|
int result = srmOPC.SendSrmTask(id, taskid, textBox2.Text, textBox3.Text, pallet, 1);
|
#region 判断返回值
|
if (result == 1)
|
{
|
label9.Text = id + "号堆垛机搬运成功发送";
|
label9.ForeColor = Color.Green;
|
}
|
else if (result == 2)
|
{
|
label9.Text = id + "号堆垛机搬运任务参数错误!!!!!!!!1";
|
label9.ForeColor = Color.Red;
|
}
|
else
|
{
|
label9.Text = id + "号堆垛机搬运发送失败!!!!!!!!1";
|
label9.ForeColor = Color.Red;
|
}
|
#endregion
|
}
|
|
else
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
int taskid = int.Parse(textBox1.Text);
|
int comm = (int)Enum.Parse(typeof(command), comboBox1.Text);
|
int pallet = int.Parse(comboBox3.Text.Split('-')[0]);
|
int result = srmOPC.SendSrmMove(id, taskid, textBox3.Text, comm, pallet, 1);
|
#region 判断返回值
|
if (result == 1)
|
{
|
label9.Text = id + "号堆垛机单放或移动成功发送";
|
label9.ForeColor = Color.Green;
|
}
|
else if (result == 2)
|
{
|
label9.Text = id + "号堆垛机单放或移动任务参数错误!!!!!!!!1";
|
label9.ForeColor = Color.Red;
|
}
|
else
|
{
|
label9.Text = id + "号堆垛机单放或移动任务发送失败!!!!!!!!1";
|
label9.ForeColor = Color.Red;
|
}
|
#endregion
|
}
|
}
|
catch (Exception)
|
{
|
label9.Text = "堆垛机单放或移动任务发送异常!!!!!!!!1";
|
label9.ForeColor = Color.Red;
|
}
|
|
|
}
|
|
|
/// <summary>确认任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button2_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
int result = srmOPC.SendSrmTaskFinishConfirm(id);
|
if (result == 1)
|
{
|
label9.Text = id + "号堆垛机确认任务发送成功";
|
label9.ForeColor = Color.Green;
|
}
|
else
|
{
|
label9.Text = id + "号堆垛机确认任务发送失败";
|
label9.ForeColor = Color.Red;
|
}
|
}
|
catch (Exception)
|
{
|
|
label9.Text = "堆垛机确认任务发送异常";
|
label9.ForeColor = Color.Red;
|
}
|
|
|
}
|
/// <summary>堆垛机解除报警
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button5_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
srmOPC.SrmRlsAlert(id);
|
}
|
catch (Exception)
|
{
|
label9.Text = "堆垛机解除报警发送异常";
|
label9.ForeColor = Color.Red;
|
}
|
|
|
}
|
/// <summary>删除任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button4_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
int result = srmOPC.SendSrmDelete(id);
|
if (result == 1)
|
{
|
label9.Text = id + "号堆垛机删除任务发送成功";
|
label9.ForeColor = Color.Green;
|
}
|
else
|
{
|
label9.Text = id + "号堆垛机删除任务发送失败";
|
label9.ForeColor = Color.Red;
|
}
|
}
|
catch (Exception)
|
{
|
|
label9.Text = "堆垛机删除任务发送异常";
|
label9.ForeColor = Color.Red;
|
}
|
MessageBox.Show("已单独删除此堆垛机任务");
|
}
|
/// <summary>急停任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button3_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
int result = srmOPC.SendSrmEStop(id);
|
if (result == 1)
|
{
|
label9.Text = id + "号堆垛机急停任务发送成功";
|
label9.ForeColor = Color.Green;
|
}
|
else
|
{
|
label9.Text = id + "号堆垛机急停任务发送失败";
|
label9.ForeColor = Color.Red;
|
}
|
}
|
catch (Exception)
|
{
|
|
label9.Text = "堆垛机急停任务发送异常";
|
label9.ForeColor = Color.Red;
|
}
|
}
|
|
/// <summary>读取堆垛机状态
|
///
|
/// </summary>
|
public void srmInfo()
|
{
|
while (true)
|
{
|
try
|
{
|
Thread.Sleep(1000);
|
// var ff =srmOPC.GetSrmInfo(srmNO);
|
SrmInfo = JsonConvert.DeserializeObject<srmInfo>(srmOPC.GetSrmInfo(srmNO));
|
label10.Text = "心跳:" + SrmInfo.RhandShake;
|
label11.Text = "模式:" + Enum.GetName(typeof(srmMode), SrmInfo.Rmode);
|
label18.Text = "状态:" + Enum.GetName(typeof(srmState), SrmInfo.Rstate);
|
label19.Text = "堆垛机名:" + SrmInfo.SrmName;
|
label17.Text = "系统任务号:" + SrmInfo.RtaskNO + " 设备任务号:" + SrmInfo.RDevicetaskNO;
|
label12.Text = "是否报警:" + (SrmInfo.Ralarm == 1 ? "报警状态" : "状态正常");
|
label13.Text = "是否有货:" + (SrmInfo.RliftFull == 1 ? "货叉上有货" : "货叉上无货");
|
label14.Text = "当前列:" + SrmInfo.Rposx + "列";
|
label15.Text = "当前层:" + SrmInfo.Rposy + "层";
|
label16.Text = "货叉位置:" + Enum.GetName(typeof(liftPosition), SrmInfo.Rposz);
|
label29.Text = "报警内容:" + Enum.GetName(typeof(ESrmAlarm), SrmInfo.RalarmNumber);
|
|
label54.Text = "任务是否完成:" + SrmInfo.RtaskFinish;
|
}
|
catch (Exception ex)
|
{
|
label19.Text = "堆垛机名:" + SrmInfo.SrmName + "产生异常" + ex;
|
|
}
|
|
|
}
|
|
}
|
|
/// <summary>选择设备
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
srmNO = (int)Enum.Parse(typeof(srmid), comboBox4.Text);
|
}
|
|
/// <summary>发送RGV任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button6_Click(object sender, EventArgs e)
|
{
|
int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
int pallet = int.Parse(comboBox8.Text.Split('-')[0]);
|
int result = rgvOPC.SendRgvTask(rgvID, rgvID * 1111, Convert.ToInt32(textBox5.Text), Convert.ToInt32(textBox6.Text), (comboBox6.Text == "搬运" ? 1 : 2), pallet, 1);
|
if (result == 1)
|
{
|
label1.Text = rgvID + "号RGV任务发送成功";
|
label1.ForeColor = Color.Green;
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV任务发送失败";
|
label1.ForeColor = Color.Red;
|
}
|
|
}
|
|
/// <summary>自动设置任务号
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
int a = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
textBox4.Text = (a * 1111).ToString();
|
}
|
|
/// <summary>优化显示
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
/// <summary>RGV确认任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button10_Click(object sender, EventArgs e)
|
{
|
int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
bool isok = rgvOPC.SendRgvFinishConfirm(rgvID);
|
if (isok)
|
{
|
label1.Text = rgvID + "号RGV任务确认成功";
|
label1.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV任务确认失败";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
|
/// <summary>RGV解警
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button8_Click(object sender, EventArgs e)
|
{
|
int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
int result = rgvOPC.SendRgvRlsAlert(rgvID);
|
if (result == 1)
|
{
|
label1.Text = rgvID + "号RGV解警成功";
|
label1.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV解警失败";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
/// <summary>删除RGV任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button7_Click(object sender, EventArgs e)
|
{
|
int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
int result = rgvOPC.SendRgvDelete(rgvID);
|
if (result == 1)
|
{
|
label1.Text = rgvID + "号RGV删除任务成功";
|
label1.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV删除任务失败";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
/// <summary>选择RGV信息展示
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
rgvNO = (int)Enum.Parse(typeof(rgvid), comboBox7.Text);
|
}
|
/// <summary>获取RGV信息
|
///
|
/// </summary>
|
public void rgvinfo()
|
{
|
while (true)
|
{
|
try
|
{
|
Thread.Sleep(1000);
|
Rgvinfo = JsonConvert.DeserializeObject<rgvINFO>(rgvOPC.GetRgvInfo(rgvNO));
|
label33.Text = "RGV名:" + Rgvinfo.RgvName;
|
label34.Text = "心跳:" + Rgvinfo.handShake;
|
label32.Text = "模式:" + (Rgvinfo.onLine == 3 ? "自动" : "非自动");
|
label25.Text = "状态:" + Rgvinfo.state;
|
label26.Text = "系统任务号:" + Rgvinfo.taskId + " 设备任务号:" + Rgvinfo.deviceTaskId;
|
label31.Text = "是否报警:" + (Rgvinfo.ararm == 1 ? "报警状态" : "状态正常");
|
label30.Text = "是否有货:" + (Rgvinfo.loaded == 1 ? "RGV有货" : "RGV无货");
|
label27.Text = "rgv当前位置:" + Rgvinfo.pos;
|
label28.Text = "报警代码:" + Enum.GetName(typeof(ESrgvAlarm), Rgvinfo.alarmCode);
|
label53.Text = "任务是否完成:" + Rgvinfo.taskFinish;
|
label57.Text = "RGV可用:" + Rgvinfo.useful;
|
|
}
|
catch (Exception)
|
{
|
label33.Text = "RGV名:" + Rgvinfo.RgvName + "异常";
|
}
|
|
|
}
|
}
|
/// <summary>发送输送线任务
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button9_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
int pallet = int.Parse(comboBox9.Text.Split('-')[0]);
|
int result = tranOPC.SendGoodsReady(Convert.ToInt32(textBox9.Text), Convert.ToInt32(textBox8.Text), Convert.ToInt32(textBox7.Text), 1);
|
if (result == 1)
|
{
|
label40.Text = "信息提示:输送线任务发送成功";
|
label40.ForeColor = Color.Green;
|
}
|
}
|
catch (Exception)
|
{
|
label40.Text = "信息提示:输送线任务发送异常";
|
label40.ForeColor = Color.Red;
|
|
}
|
|
|
}
|
/// <summary>获取输送线信息
|
///
|
/// </summary>
|
public void traninfo()
|
{
|
while (true)
|
{
|
try
|
{
|
Thread.Sleep(1000);
|
TranInfo = JsonConvert.DeserializeObject<tranInfo>(tranOPC.GetSrmConveyorStationInfo(tranNO));
|
label49.Text = "输送线编号:" + TranInfo.stationNo;
|
label50.Text = "心跳:" + TranInfo.handShake;
|
label48.Text = "模式:" + (TranInfo.auto == true ? "自动" : "非自动");
|
label42.Text = "故障:" + TranInfo.err;
|
label43.Text = "系统任务号:" + TranInfo.taskId + " 设备任务号:" + TranInfo.deviceTaskId;
|
label47.Text = "报警号:" + Enum.GetName(typeof(ETranAlarm), TranInfo.errId);
|
label46.Text = "是否有货:" + (TranInfo.goods == true ? "有货" : "无货");
|
label45.Text = "货物重量:" + TranInfo.weihgt;
|
|
label44.Text = "外形检测:" + (tranOPC.IsPassed(tranNO) == 0 ? "到位正常" : "不正常");
|
//label44.Text = "外形检测:" + (TranInfo.shapeCheck == 3 ? "到位正常" : "不正常");
|
label55.Text = "条码:" + TranInfo.Code;
|
label56.Text = "允许下发任务:" + TranInfo.TaskSendAllow;
|
//获取入口是否有新货(测试)
|
//tranOPC.HasTranGoods();
|
//tranOPC.ClearTranGoods(61);
|
}
|
catch (Exception)
|
{
|
label33.Text = "RGV名:" + Rgvinfo.RgvName + "异常";
|
}
|
|
|
}
|
}
|
|
/// <summary>窗口关闭
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
|
{
|
Environment.Exit(0);
|
}
|
/// <summary>输送线设备选择
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void textBox10_TextChanged(object sender, EventArgs e)
|
{
|
try
|
{
|
tranNO = Convert.ToInt32(textBox10.Text);
|
}
|
catch
|
{
|
|
}
|
}
|
|
private void button11_Click(object sender, EventArgs e)
|
{
|
int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
int result = rgvOPC.SendRgvStop(rgvID);
|
if (result == 1)
|
{
|
label1.Text = rgvID + "号RGV急停成功";
|
label1.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV急停失败";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
|
private void button14_Click(object sender, EventArgs e)
|
{
|
int tranid = int.Parse(textBox10.Text);
|
int result = tranOPC.SendTranReset(tranid);
|
if (result == 1)
|
{
|
label40.Text = tranid + "号输送线解警成功";
|
label40.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label40.Text = tranid + "号输送线解警失败";
|
label40.ForeColor = Color.Red;
|
}
|
}
|
|
private void button13_Click(object sender, EventArgs e)
|
{
|
int tranid = int.Parse(textBox10.Text);
|
int result = tranOPC.SendTranDelete(tranid);
|
if (result == 1)
|
{
|
label40.Text = tranid + "号输送线删除成功";
|
label40.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label40.Text = tranid + "号输送线删除失败";
|
label40.ForeColor = Color.Red;
|
}
|
}
|
|
private void button12_Click(object sender, EventArgs e)
|
{
|
int tranid = int.Parse(textBox10.Text);
|
int result = tranOPC.SendTranStop(tranid);
|
if (result == 1)
|
{
|
label40.Text = tranid + "号输送线急停成功";
|
label40.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label40.Text = tranid + "号输送线急停失败";
|
label40.ForeColor = Color.Red;
|
}
|
}
|
|
private void button15_Click_1(object sender, EventArgs e)
|
{
|
int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
bool result = rgvOPC.ChangeUseful(rgvID);
|
if (result)
|
{
|
label1.Text = rgvID + "号RGV切换成功";
|
label1.ForeColor = Color.Lime;
|
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV切换失败";
|
label1.ForeColor = Color.Red;
|
}
|
|
}
|
|
/// <summary>
|
/// 删除关联任务
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void button16_Click(object sender, EventArgs e)
|
{
|
//int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
//int result = rgvOPC.SendRgvDeleteAll(rgvID);
|
//if (result == 1)
|
//{
|
// label1.Text = rgvID + "号RGV删除任务成功";
|
// label1.ForeColor = Color.Green;
|
|
//}
|
//else
|
//{
|
// label1.Text = rgvID + "号RGV删除任务失败";
|
// label1.ForeColor = Color.Red;
|
//}
|
|
}
|
|
private void button17_Click(object sender, EventArgs e)
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
int result = srmOPC.SendSrmDelete(id);
|
if (result == 1)
|
{
|
label9.Text = id + "号堆垛机删除任务成功";
|
label9.ForeColor = Color.Green;
|
|
}
|
else
|
{
|
label9.Text = id + "号堆垛机删除任务失败";
|
label9.ForeColor = Color.Red;
|
}
|
}
|
|
private void button18_Click(object sender, EventArgs e)
|
{
|
int tranid = int.Parse(textBox10.Text);
|
int result = tranOPC.SendTranDelete(tranid);
|
if (result == 1)
|
{
|
label40.Text = tranid + "号输送线删除任务成功";
|
label40.ForeColor = Color.Green;
|
|
}
|
else if (result == 0)
|
{
|
label40.Text = tranid + "号输送线删除任务失败";
|
label40.ForeColor = Color.Red;
|
}
|
else if (result == 2)
|
{
|
label40.Text = tranid + "号输送线删除任务失败,编号校验失败(可能其它线程访问中),请重发";
|
label40.ForeColor = Color.Red;
|
}
|
}
|
|
private void button19_Click(object sender, EventArgs e)
|
{
|
int[] srmid;
|
int[] rgvid;
|
int[] tranid;
|
int dir = 0;
|
string[] place;
|
int mainid = int.Parse(textBox11.Text);
|
string containerName = textBox11.Text.Trim();
|
if (srmOPC.DeleteMainTask(mainid, out tranid, out rgvid, out srmid, out place, out dir))
|
//if (srmOPC.DeleteMainTaskByContainerName(containerName, out tranid, out rgvid, out srmid, out place,out dir))
|
{
|
string text = "";
|
foreach (var i in place)
|
{
|
text = i + " ";
|
}
|
MessageBox.Show("拿出" + text);
|
}
|
else
|
{
|
MessageBox.Show("删除失败,未修改数据");
|
}
|
|
if (!tranOPC.UnlockTran(dir))
|
{
|
if (dir == 1)
|
{
|
MessageBox.Show("输送线解锁失败,请开至安全位后手动解锁:东");
|
}
|
else if (dir == 0)
|
{
|
MessageBox.Show("输送线解锁失败,请开至安全位后手动解锁:西");
|
}
|
}
|
}
|
|
private void button20_Click(object sender, EventArgs e)
|
{
|
int dir = 2;
|
if (cbDir.Text == "东:冲压")
|
{
|
dir = 1;
|
}
|
else if (cbDir.Text == "西:焊装")
|
{
|
dir = 0;
|
}
|
else
|
{
|
MessageBox.Show("请选择东或者西");
|
}
|
bool result = tranOPC.UnlockTran(dir);
|
if (result)
|
{
|
MessageBox.Show("解锁成功");
|
}
|
else
|
{
|
MessageBox.Show("未修改一条数据,请检查RGV是否开至安全位,可能原始数据即可用");
|
}
|
}
|
|
private void button21_Click(object sender, EventArgs e)
|
{
|
int dir = 2;
|
if (cbDir.Text == "东:冲压")
|
{
|
dir = 1;
|
}
|
else if (cbDir.Text == "西:焊装")
|
{
|
dir = 0;
|
}
|
else
|
{
|
MessageBox.Show("请选择东或者西");
|
}
|
bool result = tranOPC.UnFullTran(dir);
|
if (result)
|
{
|
MessageBox.Show("解占用成功");
|
}
|
else
|
{
|
MessageBox.Show("未修改一条数据,可能原始数据即可用");
|
}
|
}
|
|
private void button22_Click(object sender, EventArgs e)
|
{
|
int id = (int)Enum.Parse(typeof(srmid), comboBox2.Text);
|
bool open = srmOPC.UseAutoMove(id);
|
if (open)
|
{
|
button22.Text = "切换优化:开启";
|
}
|
else
|
{
|
button22.Text = "切换优化:关闭";
|
}
|
}
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
{
|
int taskid = 0;
|
bool result = int.TryParse(tbTaskId.Text.Trim(), out taskid);
|
if (result)
|
{
|
List<taskCommon> taskViewList = new List<taskCommon>();
|
using (Model edm = new Model())
|
{
|
TASK_TASK task = edm.TASK_TASK.FirstOrDefault(x => x.ID == taskid);
|
if (task.TASKTYPE == 2)
|
{
|
foreach (var i in task.SrmTask)
|
{
|
taskCommon taskCommon = new taskCommon();
|
taskCommon.id = i.ID;
|
taskCommon.device = "堆垛机";
|
taskCommon.deviceNum = i.USESRMID;
|
taskCommon.sourcePlace = i.SOURCEPLACE;
|
taskCommon.toPlace = i.TOPLACE;
|
taskCommon.isReleased = i.ISRELEASED == 1 ? "是" : "否";
|
taskCommon.hasFinished = i.HASFINISHED == 1 ? "是" : "否";
|
taskViewList.Add(taskCommon);
|
}
|
foreach (var i in task.RgvTask.OrderBy(x => x.ID))
|
{
|
taskCommon taskCommon = new taskCommon();
|
taskCommon.id = i.ID;
|
taskCommon.device = "RGV";
|
taskCommon.deviceNum = i.USERGVID;
|
taskCommon.sourcePlace = i.SOURCEPLACE.ToString();
|
taskCommon.toPlace = i.TOPLACE.ToString();
|
taskCommon.isReleased = i.ISRELEASED == 1 ? "是" : "否";
|
taskCommon.hasFinished = i.HASFINISHED == 1 ? "是" : "否";
|
taskViewList.Add(taskCommon);
|
}
|
//foreach (var i in task.TranTasks)
|
//{
|
// taskCommon taskCommon = new taskCommon();
|
// taskCommon.id = i.ID;
|
// taskCommon.device = "输送线";
|
// taskCommon.deviceNum = i.SOURCEPLACE;
|
// taskCommon.sourcePlace = i.SOURCEPLACE.ToString();
|
// taskCommon.toPlace = i.TOPLACE.ToString();
|
// taskCommon.isReleased = i.ISRELEASED == 1 ? "是" : "否";
|
// taskCommon.hasFinished = i.HASFINISHED == 1 ? "是" : "否";
|
// taskViewList.Add(taskCommon);
|
//}
|
}
|
else if (task.TASKTYPE == 1)
|
{
|
foreach (var i in task.TranTask)
|
{
|
taskCommon taskCommon = new taskCommon();
|
taskCommon.id = i.ID;
|
taskCommon.device = "输送线";
|
taskCommon.deviceNum = i.SOURCEPLACE;
|
taskCommon.sourcePlace = i.SOURCEPLACE.ToString();
|
taskCommon.toPlace = i.TOPLACE.ToString();
|
taskCommon.isReleased = i.ISRELEASED == 1 ? "是" : "否";
|
taskCommon.hasFinished = i.HASFINISHED == 1 ? "是" : "否";
|
taskViewList.Add(taskCommon);
|
}
|
foreach (var i in task.RgvTask.OrderBy(x => x.ID))
|
{
|
taskCommon taskCommon = new taskCommon();
|
taskCommon.id = i.ID;
|
taskCommon.device = "RGV";
|
taskCommon.deviceNum = i.USERGVID;
|
taskCommon.sourcePlace = i.SOURCEPLACE.ToString();
|
taskCommon.toPlace = i.TOPLACE.ToString();
|
taskCommon.isReleased = i.ISRELEASED == 1 ? "是" : "否";
|
taskCommon.hasFinished = i.HASFINISHED == 1 ? "是" : "否";
|
taskViewList.Add(taskCommon);
|
}
|
foreach (var i in task.SrmTask)
|
{
|
taskCommon taskCommon = new taskCommon();
|
taskCommon.id = i.ID;
|
taskCommon.device = "堆垛机";
|
taskCommon.deviceNum = i.USESRMID;
|
taskCommon.sourcePlace = i.SOURCEPLACE;
|
taskCommon.toPlace = i.TOPLACE;
|
taskCommon.isReleased = i.ISRELEASED == 1 ? "是" : "否";
|
taskCommon.hasFinished = i.HASFINISHED == 1 ? "是" : "否";
|
taskViewList.Add(taskCommon);
|
}
|
}
|
else if (task.TASKTYPE == 3)
|
{
|
foreach (var i in task.SrmTask)
|
{
|
taskCommon taskCommon = new taskCommon();
|
taskCommon.id = i.ID;
|
taskCommon.device = "堆垛机";
|
taskCommon.deviceNum = i.USESRMID;
|
taskCommon.sourcePlace = i.SOURCEPLACE;
|
taskCommon.toPlace = i.TOPLACE;
|
taskCommon.isReleased = i.ISRELEASED == 1 ? "是" : "否";
|
taskCommon.hasFinished = i.HASFINISHED == 1 ? "是" : "否";
|
taskViewList.Add(taskCommon);
|
}
|
|
}
|
|
dGVQuery.DataSource = taskViewList;
|
}
|
}
|
else
|
{
|
dGVQuery.DataSource = null;
|
MessageBox.Show("输入正确格式任务号");
|
}
|
}
|
|
private void button23_Click(object sender, EventArgs e)
|
{
|
int rgvID = (int)Enum.Parse(typeof(rgvid), comboBox5.Text);
|
if (!rgvOPC.IsRgvReady(rgvID))
|
{
|
label1.Text = rgvID + "号RGV设备状态不空闲,不允许重发任务";
|
label1.ForeColor = Color.Red;
|
}
|
RgvTask rgvTask = null;
|
int palletType = 0;
|
using (Model edm = new Model())
|
{
|
rgvTask = edm.RgvTask.AsNoTracking().OrderByDescending(u => u.ID).FirstOrDefault(x => x.ISRELEASED == 1 && x.HASFINISHED == 0 && x.USERGVID == rgvID);
|
if (rgvTask != null)
|
{
|
if (rgvTask.TASK_TASK.TASKSTATUS != "任务执行中")
|
{
|
label1.Text = rgvID + "号RGV没有需要重发的任务";
|
label1.ForeColor = Color.Red;
|
return;
|
}
|
try
|
{
|
palletType = rgvTask.TASK_TASK.BASE_CONTAINER.BASE_PALLET.PALLETCODE ?? 0;
|
}
|
catch
|
{
|
label1.Text = rgvID + "号器具类型转换异常";
|
label1.ForeColor = Color.Red;
|
return;
|
}
|
}
|
|
}
|
if (rgvTask != null)
|
{
|
//int result = rgvOPC.SendRgvTask(rgvID, rgvID * 1111, Convert.ToInt32(textBox5.Text), Convert.ToInt32(textBox6.Text), (comboBox6.Text == "搬运" ? 1 : 2), pallet, 1);
|
int result = rgvOPC.SendRgvTask(rgvTask.USERGVID, (rgvTask.ID % 32767) + 1, rgvTask.SOURCEPLACE, rgvTask.TOPLACE, rgvTask.TASKTYPE, palletType, (rgvTask.FASTHERTASKID % 32767) + 1);
|
|
if (result == 1)
|
{
|
label1.Text = rgvID + "号RGV任务发送成功";
|
label1.ForeColor = Color.Green;
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV任务发送失败";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
else
|
{
|
label1.Text = rgvID + "号RGV没有需要重发的任务";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
}
|
}
|