You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

209 lines
6.2 KiB

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_OP50
{
static Function_OP50()
{
// BarcodeInfos = BarcodeInfo.Query(p => p.StationCode == "OP50");
}
/// <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; }
static byte pallet;
/// <summary>
/// 托盘号
/// </summary>
public static byte PalletNum
{
get
{
return pallet;
}
set
{
pallet = value;
var deploy_Datas = Deploy_Data.Query().Where(p => p.tuopan_id == PalletNum && p.process_state == 1);
if (deploy_Datas.Count() > 0)
{
PieceTypeCode = Convert.ToInt32(deploy_Datas.First().product_id);
}
}
}
/// <summary>
/// 保存完成标记
/// </summary>
public static bool ReadDataOk { get; set; }
/// <summary>
/// 产品型号代码
/// </summary>
public static int PieceTypeCode { get; set; }
/// <summary>
/// 产品信息列表
/// </summary>
public static List<ProductInfo> ProductInfos { get; set; }
/// <summary>
/// 条码验证信息
/// </summary>
public static List<BarcodeInfo> BarcodeInfos { get; set; }
/// <summary>
/// 实际托盘号
/// </summary>
public static byte PalletNul_Actually { get; set; }
/// <summary>
/// 业务逻辑
/// </summary>
public static void CycleRunTimer()
{
try
{
//读取托盘号
PalletNul_Actually = ServiceData.OpcTags.Where(p => p.TagId == StationCommunicatedTagInfos.Where(q => q.TagMarkCode == 1010).First().TagId).First().GetValue<byte>();
if (PalletNul_Actually != 0)
{
if (PalletNum != PalletNul_Actually)
{
//ProductInfos = ProductInfo.QueryAll();
//托盘号保持
PalletNum = PalletNul_Actually;
}
}
else
{
}
if (ServiceData.OpcTags.Where(p => p.TagId == StationCommunicatedTagInfos.Where(q => q.TagMarkCode == 1050).First().TagId).First().GetValue<byte>() == 1)
{
//收到允许保存 保存质量数据
if (!ReadDataOk)
{
//读取质量数据.
float prossure = ServiceData.OpcTags.Where(p => p.TagId == StationQualityTagInfos.Where(q => q.TagMarkCode == 3010 && q.ColName == "op50_pressure").First().TagId).First().GetValue<float>();
float shift = ServiceData.OpcTags.Where(p => p.TagId == StationQualityTagInfos.Where(q => q.TagMarkCode == 3010 && q.ColName == "op50_shift").First().TagId).First().GetValue<float>();
byte op40State = ServiceData.OpcTags.Where(p => p.TagId == StationQualityTagInfos.Where(q => q.TagMarkCode == 3010 && q.ColName == "op50_state").First().TagId).First().GetValue<byte>();
//只修改一次数据
Deploy_Data.Update(p => new Deploy_Data() { op50_time = DateTime.Now, op50_pressure = Convert.ToDouble(prossure.ToString()), op50_shift = Convert.ToDouble(shift.ToString()), op50_state = op40State }, p => p.tuopan_id == PalletNum && p.process_state == 1);
//回写保存完成
ServiceData.PlcServer.Write(StationCommunicatedTagInfos.Where(p => p.TagMarkCode == 1060).First().TagAddr, 1);
ReadDataOk = true;
}
}
else
{
ReadDataOk = false;
}
}
catch (Exception ex)
{
LogHelper.WriteLog(LogHelper.GetMethodInfo(), ex);
}
}
//OP50 扫描条码
public static void BarCode(string stationCode, string barCode)
{
if (stationCode != "OP50") return;
if (ProductInfos.Where(p => p.product_id == PieceTypeCode).First().skeleton_able == 0) return;
#region
//存在托盘号 允许扫描
if (PalletNul_Actually > 0)
{
//查询需要验证的条码
//根据托盘号查询产品型号信息
if (barCode.Contains(ProductInfos.Where(p => p.product_id == PieceTypeCode).First().skeleton_rule))
{
var deploy_Datas = Deploy_Data.Query().Where(p => p.tuopan_id == PalletNum && p.process_state == 1);
//更新条码及扫描时间
string sql = $"update Deploy_Data set skeleton_pid ='{barCode}',skeleton_time='{DateTime.Now}' where id = {deploy_Datas.First().id}";
SqlSugarAdo.ExecuteCommand(sql);
ServiceData.PlcServer.Write(StationCommunicatedTagInfos.Where(p => p.TagMarkCode == 1020).First().TagAddr, 1);
}
}
#endregion
}
}
}