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"); } /// /// 工位标签信息 /// public static List StationTagInfos { get; set; } /// /// 工位报警标签信息 /// public static List StationAlarmTagInfos { get; set; } /// /// 工位质量数据标签信息 /// public static List StationQualityTagInfos { get; set; } /// /// 工位交互数据标签信息 /// public static List StationCommunicatedTagInfos { get; set; } /// /// 工位信息 /// public static StationInfo StationInf { get; set; } static byte pallet; /// /// 托盘号 /// 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); } } } /// /// 保存完成标记 /// public static bool ReadDataOk { get; set; } /// /// 产品型号代码 /// public static int PieceTypeCode { get; set; } /// /// 产品信息列表 /// public static List ProductInfos { get; set; } /// /// 条码验证信息 /// public static List BarcodeInfos { get; set; } /// /// 实际托盘号 /// public static byte PalletNul_Actually { get; set; } /// /// 业务逻辑 /// public static void CycleRunTimer() { try { //读取托盘号 PalletNul_Actually = ServiceData.OpcTags.Where(p => p.TagId == StationCommunicatedTagInfos.Where(q => q.TagMarkCode == 1010).First().TagId).First().GetValue(); 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() == 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 shift = ServiceData.OpcTags.Where(p => p.TagId == StationQualityTagInfos.Where(q => q.TagMarkCode == 3010 && q.ColName == "op50_shift").First().TagId).First().GetValue(); byte op40State = ServiceData.OpcTags.Where(p => p.TagId == StationQualityTagInfos.Where(q => q.TagMarkCode == 3010 && q.ColName == "op50_state").First().TagId).First().GetValue(); //只修改一次数据 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 } } }