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.

174 lines
6.8 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 RFIDWrite : StepBase
{
public override bool Do()
{
try
{
RFIDApp app = new RFIDApp(httpClient);
string el_no = Context["serial_number"].ToString();
string terminal_id = Context["terminal_id"].ToString();
// 执行父类的 Do 方法并返回
//bool TAGState = Convert.ToBoolean(Context["TAGState"].ToString());
////托盘到位就写条码
//if (TAGState == false)
//{
// ShowMessage(this, "red|托盘未到位!");
//}
//else
//{
//写条码到PLC
bool WrietPLCOK = app.UpdatePLC("OPC_WriteSN", Convert.ToInt32(terminal_id), el_no);
using (StreamWriter sw = new StreamWriter(terminal_id + " Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "] ", el_no + " 写入PLC成功"));
sw.Flush();
sw.Close();
}
#region 不用循环等待写入RFID完成信号
//等待写入RFID完成信号
//while (true)
//{
// string WriteOK = app.ReadyPlc("OPC_WriteOK", Convert.ToInt32(terminal_id)).ToString().ToUpper();
// if (WriteOK.Equals("TRUE"))
// {
// ShowMessage(this, "green|PLC将条码写入RFID成功");
// break;
// }
// else
// {
// ShowMessage(this, "red|等待PLC将条码写入RFID");
// }
// Application.DoEvents();
// Thread.Sleep(1000);
//}
////发送放行信号
//bool RELASE = app.UpdatePLC("OPC_OK", Convert.ToInt32(terminal_id), "TRUE");
//if (RELASE==true)
//{
// ShowMessage(this, "green|发送放行信号成功!");
//}
//else
//{
// ShowMessage(this, "red|发送放行信号成失败!");
//}
#endregion
#region 没用代码
//List<dynamic> RFIDOperationType = app.GetRFIDOperationType(Convert.ToInt32(terminal_id), "RFID_IP");
//string perationType = "";
//if (RFIDOperationType.Count > 0)
//{
// perationType = RFIDOperationType[0]["operation_type"].ToString();
//}
//if (initializeRFIDState == true && perationType.ToUpper().ToString() == "WRITE")
//{
// // 记录日志
// using (StreamWriter sw = new StreamWriter("Error_Log_1" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
// {
// sw.WriteLine(string.Format("{0} {1}", "["
// + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
// + "] ", "1"));
// sw.Flush();
// sw.Close();
// }
// RF182C.Write(el_no);
// // 记录日志
// using (StreamWriter sw = new StreamWriter("Error_Log_1" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
// {
// sw.WriteLine(string.Format("{0} {1}", "["
// + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
// + "] ", "2"));
// sw.Flush();
// sw.Close();
// }
// Thread.Sleep(100);
// RF182C.read();
// // 记录日志
// using (StreamWriter sw = new StreamWriter("Error_Log_1" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
// {
// sw.WriteLine(string.Format("{0} {1}", "["
// + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
// + "] ", "3"));
// sw.Flush();
// sw.Close();
// }
// if (el_no != RF182C.BarCode)
// {
// // 记录日志
// using (StreamWriter sw = new StreamWriter("Error_Log_1" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
// {
// sw.WriteLine(string.Format("{0} {1}", "["
// + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
// + "] ", "4"));
// sw.Flush();
// sw.Close();
// }
// ShowMessage(this, "red|RFID写入失败请重新扫描");
// }
//}
#endregion
//}
Complate(this, new EventArgs());
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 InitializeComponent()
{
this.SuspendLayout();
//
// RFIDWrite
//
this.Name = "RFIDWrite";
this.Size = new System.Drawing.Size(391, 376);
this.Load += new System.EventHandler(this.RFIDWrite_Load);
this.ResumeLayout(false);
}
private void RFIDWrite_Load(object sender, EventArgs e)
{
// 工步执行完成后调用此方法
Complate(this, e);
}
}
}