using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Xml.Linq;
|
using WIDESEA_Comm.LogInfo;
|
using WIDESEA_Core.EFDbContext;
|
using WIDESEA_WCS.IRepositories;
|
using WIDESEA_WCS.Repositories;
|
using WIDESEA_WCS.WCSClient;
|
using WIDESEA_WMS.IRepositories;
|
using WIDESEA_WMS.Repositories;
|
using static WIDESEA_Comm.Wheel_trace;
|
using static WIDESEA_WCS.GantryDB;
|
|
namespace WIDESEA_WCS
|
{
|
public class info_interaction
|
{
|
|
/// <summary>
|
/// 车轮参数交互
|
/// </summary>
|
/// <param name="client"></param>
|
public static void wheeldata(PLCClient client)
|
{
|
VOLContext context = new VOLContext();
|
Idt_geometry_dataRepository geometry_DataRepository = new dt_geometry_dataRepository(context);
|
var groups = client.itemGroups.Where(x => x.opratortype == "wheeldata").OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList();
|
foreach (var key in groups)
|
{
|
try
|
{
|
DBItemGroup group = key.FirstOrDefault(x => x.name == "oi_on");
|
if (group != null)
|
{
|
var oi_on = DBExtension.Read(group, client);
|
if (Convert.ToByte(oi_on) == 1)
|
{
|
var o_wp_type = DBExtension.Read(key.FirstOrDefault(x => x.name == "o_wp_type"), client);
|
var geometry = geometry_DataRepository.Find(x => x.TypeId == Convert.ToInt32(o_wp_type)).FirstOrDefault();
|
if (geometry == null)
|
{
|
client.Write(key.FirstOrDefault(x => x.name == "i_status").dbAddress, (byte)2);//状态
|
client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//申请复位
|
throw new Exception($"{key.Key}未找到类型{o_wp_type}的车轮参数\n写入辊道信息:i_status:2,oi_on:0");
|
}
|
else
|
{
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_a").dbAddress, (float)geometry.a);//车轮参数a
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_b").dbAddress, (float)geometry.b);//车轮参数b
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_c").dbAddress, (float)geometry.c);//车轮参数c
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_d").dbAddress, (float)geometry.d);//车轮参数d
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_e").dbAddress, (float)geometry.e);//车轮参数e
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_f").dbAddress, (float)geometry.f);//车轮参数f
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_g").dbAddress, (float)geometry.g);//车轮参数g
|
client.Write(key.FirstOrDefault(x => x.name == "i_parameter_h").dbAddress, (float)geometry.h);//车轮参数h
|
client.Write(key.FirstOrDefault(x => x.name == "i_status").dbAddress, (byte)1);//状态
|
client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//申请复位
|
#region 日志记录
|
WriteLog.Write_Log(key.Key + "辊道", "申请查询车轮信息", "", $"读取辊道信息:\n轮型ID:{o_wp_type}\n\n写入辊道信息:\ni_status:1" + $"\n" +
|
$"a:{(float)geometry.a}\n" +
|
$"b:{(float)geometry.b}\n" +
|
$"c:{(float)geometry.c}\n" +
|
$"d:{(float)geometry.d}\n" +
|
$"e:{(float)geometry.e}\n" +
|
$"f:{(float)geometry.f}\n" +
|
$"g:{(float)geometry.g}\n" +
|
$"h:{(float)geometry.h}\n" +
|
$"oi_on:0");
|
#endregion
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Write_Log(key.Key + "辊道", "申请查询车轮信息", "", ex.Message);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 扫码枪
|
/// </summary>
|
/// <param name="client"></param>
|
public static void scan(PLCClient client)
|
{
|
VOLContext context = new VOLContext();
|
Idt_geometry_dataRepository geometry_DataRepository = new dt_geometry_dataRepository(context);
|
IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
|
var groups = client.itemGroups.Where(x => x.opratortype == "scan").OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList();
|
foreach (var key in groups)
|
{
|
try
|
{
|
DBItemGroup group = key.FirstOrDefault(x => x.name == "oi_on");
|
if (group != null)
|
{
|
var oi_on = DBExtension.Read(group, client);
|
if (Convert.ToByte(oi_on) == 1)
|
{
|
var o_wp_type = DBExtension.Read(key.FirstOrDefault(x => x.name == "o_wp_type"), client);
|
var o_wp_id = DBExtension.Read(key.FirstOrDefault(x => x.name == "o_wp_id"), client);
|
var geometry = geometry_DataRepository.Find(x => x.TypeId == Convert.ToInt32(o_wp_type)).FirstOrDefault();
|
if (geometry == null)
|
{
|
client.Write(key.FirstOrDefault(x => x.name == "i_status").dbAddress, (byte)2);//状态
|
client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//申请复位
|
throw new Exception($"{key.Key}未找到类型{o_wp_type}的车轮参数\n写入辊道信息:i_status:2,oi_on:0");
|
}
|
var Work = workinfoRepository.Find(x => x.SN == o_wp_id && (key.Key.Contains("4单元") ? x.processCode == "28" : x.processCode == "17")).OrderByDescending(x => x.CreateTime).FirstOrDefault();
|
if (Work == null)
|
{
|
client.Write(key.FirstOrDefault(x => x.name == "i_status").dbAddress, (byte)3);//状态
|
client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//申请复位
|
throw new Exception($"{key.Key}未找到SN:{o_wp_id}的工单信息\n写入辊道信息:i_status:3,oi_on:0");
|
}
|
client.Write(key.FirstOrDefault(x => x.name == "i_status").dbAddress, (byte)1);//状态
|
client.Write(key.FirstOrDefault(x => x.name == "i_direction").dbAddress, (byte)2);//去向默认写2
|
client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//申请复位
|
WriteLog.Write_Log(key.Key + "辊道", "扫码枪", "", "写入辊道信息:\ni_status:1,i_direction:2,oi_on:0");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Write_Log(key.Key + "辊道", "扫码枪", "", ex.Message);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 贴标机交互
|
/// </summary>
|
/// <param name="client"></param>
|
public static void labeller(PLCClient client)
|
{
|
VOLContext context = new VOLContext();
|
Idt_geometry_dataRepository geometry_DataRepository = new dt_geometry_dataRepository(context);
|
IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
|
var groups = client.itemGroups.Where(x => x.opratortype == "labeller").OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList();
|
foreach (var key in groups)
|
{
|
try
|
{
|
DBItemGroup group = key.FirstOrDefault(x => x.name == "oi_on");
|
if (group != null)
|
{
|
var oi_on = DBExtension.Read(group, client);
|
if (Convert.ToByte(oi_on) == 1)
|
{
|
var o_wp_id = DBExtension.Read(key.FirstOrDefault(x => x.name == "o_wp_id"), client);
|
if (!string.IsNullOrEmpty(o_wp_id.ToString()))
|
{
|
var Work = workinfoRepository.Find(x => x.SN == o_wp_id && (key.Key.Contains("4单元") ? x.processCode == "28" : x.processCode == "17")).OrderByDescending(x => x.CreateTime).FirstOrDefault();
|
if (Work == null)
|
{
|
client.Write(key.FirstOrDefault(x => x.name == "i_status").dbAddress, (byte)2);//状态
|
client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//申请复位
|
throw new Exception($"{key.Key}未找到SN:{o_wp_id}的工单信息\n写入辊道信息:i_status:2,oi_on:0");
|
}
|
client.Write(key.FirstOrDefault(x => x.name == "i_job_id").dbAddress, Encoding.UTF8.GetBytes(Work.jobID));//工单编号
|
client.Write(key.FirstOrDefault(x => x.name == "i_heat_id").dbAddress, Encoding.UTF8.GetBytes(Work.heatID));//炉代号
|
client.Write(key.FirstOrDefault(x => x.name == "i_billet_id").dbAddress, Encoding.UTF8.GetBytes(Work.billetID.ToString()));//钢坯号
|
client.Write(key.FirstOrDefault(x => x.name == "i_batch_id").dbAddress, Encoding.UTF8.GetBytes(Work.heatBatchID));//热处理批次
|
client.Write(key.FirstOrDefault(x => x.name == "i_drawing_id").dbAddress, Encoding.UTF8.GetBytes(Work.drawingNo));//图号
|
client.Write(key.FirstOrDefault(x => x.name == "i_status").dbAddress, (byte)1);//状态
|
client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//申请复位
|
WriteLog.Write_Log(key.Key + "辊道", "贴标机", "SN号:" + o_wp_id.ToString(),
|
$"写入辊道信息:\n" +
|
$"i_job_id:{Work.jobID}\n" +
|
$"i_heat_id:{Work.heatID}\n" +
|
$"i_billet_id:{Work.billetID}\n" +
|
$"i_batch_id:{Work.heatBatchID}\n" +
|
$"i_drawing_id:{Work.drawingNo}\n" +
|
$"i_status:{(byte)1}\n" +
|
$"oi_on:{(byte)0}");
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteLog.Write_Log(key.Key + "辊道", "贴标机", "", ex.Message);
|
}
|
}
|
}
|
}
|
}
|