using Leit.FrameWork.Log;
|
|
using Leit.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Leit.StationFunction
|
|
{
|
|
public static class Function_OP25
|
|
{
|
|
/// <summary>
|
|
/// 工位标签信息
|
|
/// </summary>
|
|
public static List<StationTagInfo> StationTagInfos { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// 工位报警标签信息
|
|
/// </summary>
|
|
public static List<StationTagInfo> StationAlarmTagInfos { get; set; }
|
|
|
|
/// <summary>
|
|
/// 工位质量数据标签信息
|
|
/// </summary>
|
|
public static List<StationTagInfo> StationQualityTagInfos { get; set; }
|
|
|
|
/// <summary>
|
|
/// 工位交互数据标签信息
|
|
/// </summary>
|
|
public static List<StationTagInfo> StationCommunicatedTagInfos { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// 工位信息
|
|
/// </summary>
|
|
public static StationInfo StationInf { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// 物料条码
|
|
/// </summary>
|
|
public static string PieceCode { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// 保存数据到数据库完成
|
|
/// </summary>
|
|
public static bool ReadDataOk { get; set; }
|
|
|
|
/// <summary>
|
|
/// 质量数据Id
|
|
/// </summary>
|
|
public static long QualityId { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// 业务逻辑
|
|
/// </summary>
|
|
public static void CycleRunTimer()
|
|
{
|
|
try
|
|
{
|
|
if (ServiceData.OpcTags.Where(p => p.TagId == StationCommunicatedTagInfos.Where(q => q.TagMarkCode == 1020).First().TagId).First().GetValue<byte>() == 0)
|
|
{
|
|
|
|
ReadDataOk = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//无允许保存信号 所有靠网结果为1 自动保存数据
|
|
|
|
if (!ReadDataOk)
|
|
{
|
|
if(PieceCode==null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
//填充质量数据
|
|
string sql = "update ProductQuality_Electric set ";
|
|
|
|
foreach (var item in StationQualityTagInfos)
|
|
{
|
|
byte KwValue = ServiceData.OpcTags.Where(p => p.TagId == item.TagId).First().GetValue<byte>();
|
|
|
|
if (KwValue != 1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
sql = sql + item.ColName + "=" + ServiceData.OpcTags.Where(p => p.TagId == item.TagId).First().GetValue<byte>();
|
|
|
|
|
|
|
|
sql = sql + ",";
|
|
}
|
|
|
|
sql = sql.Remove(sql.Length - 1, 1);
|
|
sql = sql + $",CheckTime='{DateTime.Now}',OperateTime='{DateTime.Now}' where Id={QualityId}";
|
|
|
|
|
|
ServiceData.GetWorkLog(StationInf.StationCode, ServiceData.GetCodeLineNum(1).ToString(), "保存质量数据", sql);
|
|
if (SqlSugarAdo.ExecuteCommand(sql) > 0)
|
|
{
|
|
ReadDataOk = true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
LogHelper.WriteLog(LogHelper.GetMethodInfo(), ex);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扫描条码事件触发的方法
|
|
/// </summary>
|
|
/// <param name="stationCode"></param>
|
|
/// <param name="barCode"></param>
|
|
public static void BarCode(string stationCode, string barCode)
|
|
{
|
|
|
|
try
|
|
{
|
|
if (stationCode != "OP25") return;
|
|
|
|
// 验证条码 并写入扫描完成 根据条码查询质量数据 根据质量数据查询基础信息
|
|
ServiceData.GetWorkLog(StationInf.StationCode, ServiceData.GetCodeLineNum(1).ToString(), "扫描条码", barCode);
|
|
|
|
|
|
PieceCode = barCode;
|
|
|
|
QualityId = ProductQuality_Electric.Query(p => p.PieceCode == barCode && p.ProductTypeCode == 3).ToList().First().Id;
|
|
ServiceData.PlcServer.Write(StationCommunicatedTagInfos.Where(p => p.TagMarkCode == 1020).First().TagAddr, Convert.ToByte(1));
|
|
ServiceData.GetWorkLog(StationInf.StationCode, ServiceData.GetCodeLineNum(1).ToString(), "扫描完成", 1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(LogHelper.GetMethodInfo(), ex);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|