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.

149 lines
5.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Estsh.Client.Base;
namespace Estsh.Client.StepLibrary
{
public class GYRFIDWrite : StepBase
{
private System.Windows.Forms.Timer timRFID;
private System.ComponentModel.IContainer components;
private Label lblMessage;
RFIDApp app = null;
private string sn = "";
private int terminal_id = 0;
private bool writeSnStatus = false;
public GYRFIDWrite()
{
InitializeComponent();
// 有用户界面的工步在初始化时需要设置为不可见
// 开始执行此工步后再置为可见
this.Visible = false;
}
public override bool Do()
{
try
{
// 置为可见并加载到最前端
//this.Visible = true;
//this.BringToFront();
app = new RFIDApp(httpClient);
sn = Context["serial_number"].ToString();
terminal_id = Convert.ToInt32(Context["terminal_id"].ToString());
string planCode = app.validataLimit("PlanCode");
string partLoc = app.getPartLocation(sn);
if (planCode == "GY" && partLoc == "0B") //贵阳三排是双托盘托盘上的第二个产品不需要写入RFID需要特殊处理
{
Complate(this, new EventArgs());
}
else
{
timRFID.Enabled = true;
}
return base.Do();
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "] ", ex.ToString()));
sw.Flush();
sw.Close();
}
return false;
}
}
private void timRFID_Tick(object sender, EventArgs e)
{
//检测PLC RFID写入完成信号
string WriteRfidOk = app.ReadyPlc("RfidWriteOk", terminal_id);
if (WriteRfidOk == "TRUE")
{
timRFID.Enabled = false;
Complate(this, new EventArgs());
return;
}
else
{
ShowMessage(this, "green|RFID正在写入请稍等");
lblMessage.ForeColor = Color.Yellow;
}
//完成写入后不再写入,防止循环写入。
if (writeSnStatus)
{
return;
}
//检测就绪信号
string TAGState = app.ReadyPlc("OPC_TAGState", terminal_id);
if (TAGState == "TRUE")
{
//写入条码
bool WrietSN = app.UpdatePLC("WriteSN", Convert.ToInt32(terminal_id), sn);
//条码写入完成信号
bool WrietSNOK = app.UpdatePLC("WriteSNOk", Convert.ToInt32(terminal_id), "TRUE");
if (WrietSN)
{
writeSnStatus = true;
}
using (StreamWriter sw = new StreamWriter(terminal_id + " PLC_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "] ", sn + " 写入PLC成功 状态1" + WrietSN.ToString() + " 状态2" + WrietSNOK.ToString()));
sw.Flush();
sw.Close();
}
}
else
{
ShowMessage(this, "red|准备信号未就绪,请稍等!");
lblMessage.ForeColor = Color.Yellow;
}
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.lblMessage = new System.Windows.Forms.Label();
this.timRFID = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// lblMessage
//
this.lblMessage.AutoSize = true;
this.lblMessage.Font = new System.Drawing.Font("微软雅黑", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblMessage.Location = new System.Drawing.Point(214, 64);
this.lblMessage.Name = "lblMessage";
this.lblMessage.Size = new System.Drawing.Size(146, 42);
this.lblMessage.TabIndex = 0;
this.lblMessage.Text = "提示信息";
//
// timRFID
//
this.timRFID.Interval = 1000;
this.timRFID.Tick += new System.EventHandler(this.timRFID_Tick);
//
// GYRFIDWrite
//
this.Controls.Add(this.lblMessage);
this.Name = "GYRFIDWrite";
this.Size = new System.Drawing.Size(1003, 499);
this.ResumeLayout(false);
this.PerformLayout();
}
}
}