出站
This commit is contained in:
parent
47265ab5c2
commit
e7fa8b518d
@ -14,6 +14,7 @@ using RIZO.Common.Cache;
|
||||
using RIZO.Common.DynamicApiSimple.Extens;
|
||||
using RIZO.Infrastructure.WebExtensions;
|
||||
using RIZO.Mall;
|
||||
using RIZO.Service.PLCBackground.Stations;
|
||||
using RIZO.ServiceCore.Signalr;
|
||||
using RIZO.ServiceCore.SqlSugar;
|
||||
using S7.Net;
|
||||
@ -107,43 +108,9 @@ builder.Services.AddSwaggerConfig();
|
||||
builder.Services.AddLogo();
|
||||
// 添加本地化服务
|
||||
builder.Services.AddLocalization(options => options.ResourcesPath = "");
|
||||
// 配置PLC设置
|
||||
//builder.Services.Configure<List<RIZO.Model.PLC.PlcConfig>>(builder.Configuration.GetSection("PlcSettings:Stations"));
|
||||
|
||||
//// 注册PLC数据服务
|
||||
//builder.Services.AddSingleton<IPlcDataService, PlcDataService>();
|
||||
//builder.Services.AddHostedService(provider => provider.GetService<IPlcDataService>() as BackgroundService);
|
||||
|
||||
//builder.Services.Configure<List<PlcConnectionConfig>>(builder.Configuration.GetSection("PlcSettingss:Connections"));
|
||||
//builder.Services.AddSingleton<RIZO.Service.PLC.PlcService2>(sp =>
|
||||
//{
|
||||
// var configs = sp.GetRequiredService<IOptions<List<PlcConnectionConfig>>>().Value;
|
||||
// var logger = sp.GetRequiredService<ILogger<RIZO.Service.PLC.PlcService2>>();
|
||||
// var service = new RIZO.Service.PLC.PlcService2(logger);
|
||||
|
||||
// foreach (var config in configs)
|
||||
// {
|
||||
// service.AddPlc(
|
||||
// config.PlcId,
|
||||
// ParseCpuType(config.CpuType),
|
||||
// config.Ip,
|
||||
// config.Rack,
|
||||
// config.Slot
|
||||
// );
|
||||
// }
|
||||
|
||||
// // 后台启动连接
|
||||
// _ = service.ConnectAllAsync();
|
||||
// return service;
|
||||
//});
|
||||
|
||||
//// CPU类型转换辅助方法
|
||||
//static CpuType ParseCpuType(string type)
|
||||
//{
|
||||
// return Enum.Parse<CpuType>(type.Replace("-", "")); // "S71200" -> "S71200"
|
||||
//}
|
||||
// 配置服务
|
||||
// 注册PLC服务(单例模式)
|
||||
builder.Services.AddHostedService<PlcOutStationService_OP07_01>();
|
||||
builder.Services.AddHostedService<PlcIntoStationService_OP07_01>();
|
||||
|
||||
|
||||
// 在应用程序启动的最开始处调用
|
||||
|
||||
155
RIZO.Model/MES/product_trace/ProductProcessParameters.cs
Normal file
155
RIZO.Model/MES/product_trace/ProductProcessParameters.cs
Normal file
@ -0,0 +1,155 @@
|
||||
namespace RIZO.Model.MES.product_trace
|
||||
{
|
||||
/// <summary>
|
||||
/// 生产过程参数
|
||||
/// </summary>
|
||||
[SugarTable("product_process_parameters")]
|
||||
public class ProductProcessParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键ID
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工单号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "workorder", Length = 50)]
|
||||
public string Workorder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品序列号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "product_SN", Length = 50)]
|
||||
public string ProductSN { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工艺路线代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "routingCode", Length = 50)]
|
||||
public string RoutingCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工序代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "operationCode", Length = 50)]
|
||||
public string OperationCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流程代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "flowCode", Length = 50)]
|
||||
public string FlowCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生产线体代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "productlinebodyCode", Length = 50)]
|
||||
public string ProductlinebodyCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工位代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "workstationCode", Length = 50)]
|
||||
public string WorkstationCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数代码
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "parameter_code", Length = 255)]
|
||||
public string ParameterCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数名称
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "parameter_name", Length = 100)]
|
||||
public string ParameterName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PLC点位
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "plc_point", Length = 50)]
|
||||
public string PlcPoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "description", ColumnDataType = "text")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "data_type", Length = 50)]
|
||||
public string DataType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "unit", Length = 20)]
|
||||
public string Unit { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 实际值
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "actual_value", Length = 50)]
|
||||
public string ActualValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 期望值
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "expect_value", Length = 50)]
|
||||
public string ExpectValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标准值
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "standard_value", ColumnDataType = "decimal(18,4)")]
|
||||
public decimal? StandardValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最小值
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "min_value", ColumnDataType = "decimal(18,4)")]
|
||||
public decimal? MinValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大值
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "max_value", ColumnDataType = "decimal(18,4)")]
|
||||
public decimal? MaxValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结果
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "result")]
|
||||
public int? Result { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "createdby", Length = 50)]
|
||||
public string Createdby { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新人
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "updatedby", Length = 50)]
|
||||
public string Updatedby { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "created_time")]
|
||||
public DateTime? CreatedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "updated_time")]
|
||||
public DateTime? UpdatedTime { get; set; }
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,6 @@ using NLog;
|
||||
using RIZO.Model.Mes;
|
||||
using RIZO.Model.MES.product_trace;
|
||||
using RIZO.Repository;
|
||||
using RIZO.Service.MES.product_trace;
|
||||
using RIZO.Service.PLC;
|
||||
using S7.Net;
|
||||
using SqlSugar.IOC;
|
||||
@ -16,9 +15,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RIZO.Service.PLCBackground.Stations
|
||||
{
|
||||
|
||||
|
||||
public class PlcPollingService_OP07_01 : BackgroundService
|
||||
public class PlcIntoStationService_OP07_01 : BackgroundService
|
||||
{
|
||||
private static Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
private PlcConntectHepler _plcService;
|
||||
@ -26,8 +23,11 @@ namespace RIZO.Service.PLCBackground.Stations
|
||||
private readonly string _ipAddress = "192.168.10.222";
|
||||
private readonly CpuType _cpuType = CpuType.S71500;
|
||||
private string WorkstationCode;
|
||||
|
||||
|
||||
private readonly SqlSugarClient Context;
|
||||
public PlcIntoStationService_OP07_01()
|
||||
{
|
||||
Context = DbScoped.SugarScope.CopyNew();
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
@ -38,8 +38,8 @@ namespace RIZO.Service.PLCBackground.Stations
|
||||
{
|
||||
|
||||
// 获取当前的工序/工站
|
||||
WorkstationCode = await DbScoped.SugarScope.CopyNew().Queryable<PlantWorkstation>().Where(it => it.PlcIP == _ipAddress)
|
||||
.Select(it => it.WorkstationCode).FirstAsync();
|
||||
WorkstationCode = await Context.Queryable<PlantWorkstation>().Where(it => it.PlcIP == _ipAddress)
|
||||
.Select(it => it.WorkstationCode).FirstAsync();
|
||||
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
@ -60,16 +60,44 @@ namespace RIZO.Service.PLCBackground.Stations
|
||||
string productModel = await _plcService.ReadStringAsync("DB1001.DBB1000");
|
||||
string productSN = await _plcService.ReadStringAsync("DB1001.DBB1054");
|
||||
|
||||
// 获取工单
|
||||
|
||||
//获取工艺路线工序
|
||||
List<ProcessOperation> processOperations = await Context.Queryable<ProcessRouting>().LeftJoin<ProcessOperation>((r, o) => r.RoutingCode == o.FkRoutingCode)
|
||||
.Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1)
|
||||
.Select((r, o) => o).ToListAsync();
|
||||
//判断改产品是正常件还是返工件
|
||||
|
||||
|
||||
//插入入站请求ASK过站记录
|
||||
ProductPassStationRecord ASKintoStation = new ProductPassStationRecord
|
||||
{
|
||||
ProductSN = productSN,
|
||||
WorkstationCode = WorkstationCode,
|
||||
Routingcode = processOperations.First().FkRoutingCode,
|
||||
OperationCode = WorkstationCode,
|
||||
ProductionLifeStage = 1, // 1表示生产中
|
||||
PasstationType = 0, // 0表示入站请求
|
||||
PasstationDescription = "入站请求ASK",
|
||||
EffectTime = DateTime.Now,
|
||||
CreatedTime = DateTime.Now,
|
||||
|
||||
};
|
||||
await Context.Insertable(ASKintoStation).ExecuteCommandAsync();
|
||||
|
||||
//判断该产品是否允许进站
|
||||
|
||||
EntryPermissionResult result = await checkEntryPermission(productModel, productSN, WorkstationCode);
|
||||
EntryPermissionResult result = await checkEntryPermission(productModel, productSN, WorkstationCode, processOperations);
|
||||
await _plcService.WriteAsync("DB1010.DBW2000", (int)result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
await Task.Delay(_pollingInterval, stoppingToken);
|
||||
|
||||
}
|
||||
@ -95,21 +123,16 @@ namespace RIZO.Service.PLCBackground.Stations
|
||||
/// <param name="productModel">产品型号</param>
|
||||
/// <param name="productSN">产品SN</param>
|
||||
/// <returns></returns>
|
||||
private async Task<EntryPermissionResult> checkEntryPermission(string productModel, string productSN, string workstationCode)
|
||||
private async Task<EntryPermissionResult> checkEntryPermission(string productModel, string productSN, string workstationCode, List<ProcessOperation> processOperations)
|
||||
{
|
||||
// 获取工单
|
||||
|
||||
//获取工艺路线工序
|
||||
List<ProcessOperation> processOperations = await DbScoped.SugarScope.CopyNew().Queryable<ProcessRouting>().LeftJoin<ProcessOperation>((r, o) => r.RoutingCode == o.FkRoutingCode)
|
||||
.Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1)
|
||||
.Select((r, o) => o).ToListAsync();
|
||||
|
||||
EntryPermissionResult result = EntryPermissionResult.UnkownException;
|
||||
|
||||
|
||||
//2上工位无记录
|
||||
|
||||
//ProcessOperation LastOperation = processOperations.Where(operation => operation.OperationSeq < processOperations.Where(it => it.OperationCode == workstationCode).Select(it => it.OperationSeq).First()).OrderByDescending(operation => operation.OperationSeq).First();
|
||||
int LastOperationSeq=processOperations.Where(operation => operation.OperationCode == workstationCode).Select(operation => operation.LastOperationSeq??-1).First();
|
||||
int LastOperationSeq = processOperations.Where(operation => operation.OperationCode == workstationCode).Select(operation => operation.LastOperationSeq ?? -1).First();
|
||||
ProcessOperation LastOperation = processOperations.Where(it => it.OperationSeq == LastOperationSeq).First();
|
||||
bool isExistLastOperationRecord = await DbScoped.SugarScope.CopyNew().Queryable<ProductPassStationRecord>()
|
||||
.Where(it => it.ProductSN == productSN)
|
||||
@ -121,7 +144,7 @@ namespace RIZO.Service.PLCBackground.Stations
|
||||
}
|
||||
|
||||
// 3 上工位NG 入站或者出站结果 NG
|
||||
bool isExistLastOperationNG = await DbScoped.SugarScope.CopyNew().Queryable<ProductPassStationRecord>()
|
||||
bool isExistLastOperationNG = await Context.Queryable<ProductPassStationRecord>()
|
||||
.Where(it => it.ProductSN == productSN)
|
||||
.Where(it => it.OperationCode == LastOperation.OperationCode)
|
||||
.Where(it => it.PasstationType == 2 || it.PasstationType == 4)
|
||||
@ -129,37 +152,58 @@ namespace RIZO.Service.PLCBackground.Stations
|
||||
.AnyAsync();
|
||||
if (!isExistLastOperationNG)
|
||||
{
|
||||
return EntryPermissionResult.PreviousStationNG;
|
||||
result = EntryPermissionResult.PreviousStationNG;
|
||||
goto InsertPassrecord;
|
||||
}
|
||||
|
||||
|
||||
// 4 扫码产品型号错误
|
||||
bool isExistproductSN = await DbScoped.SugarScope.CopyNew().Queryable<ProductLifecycle>()
|
||||
bool isExistproductSN = await Context.Queryable<ProductLifecycle>()
|
||||
.Where(it => it.ProductSN == productSN).AnyAsync();
|
||||
bool isExistproductSNProducting = await DbScoped.SugarScope.CopyNew().Queryable<ProductLifecycle>()
|
||||
|
||||
|
||||
bool isExistproductSNProducting = await Context.Queryable<ProductLifecycle>()
|
||||
.Where(it => it.ProductSN == productSN && (it.ProductCurrentStatus != 1 && it.ProductCurrentStatus != 3)).AnyAsync();
|
||||
if (!isExistproductSN || !isExistproductSNProducting)
|
||||
{
|
||||
return EntryPermissionResult.ProductModelError;
|
||||
result = EntryPermissionResult.ProductModelError;
|
||||
goto InsertPassrecord;
|
||||
}
|
||||
//6时间超出规定无法生产
|
||||
|
||||
//查询上一站标准时间
|
||||
|
||||
//OK 准许进站
|
||||
result = EntryPermissionResult.AllowIntoStation;
|
||||
goto InsertPassrecord;
|
||||
InsertPassrecord:
|
||||
//插入入站请求Resp过站记录
|
||||
ProductPassStationRecord RespintoStation = new ProductPassStationRecord
|
||||
{
|
||||
ProductSN = productSN,
|
||||
WorkstationCode = WorkstationCode,
|
||||
Routingcode = processOperations.First().FkRoutingCode,
|
||||
OperationCode = WorkstationCode,
|
||||
ProductionLifeStage = 1, // 1表示生产中
|
||||
PasstationType = 1, // 入站完毕
|
||||
PasstationDescription = "入站完毕Resp",
|
||||
EffectTime = DateTime.Now,
|
||||
InStationTime = DateTime.Now,
|
||||
ResultCode = (int)result,
|
||||
ResultDescription = result.ToString(),
|
||||
CreatedTime = DateTime.Now,
|
||||
|
||||
};
|
||||
await Context.Insertable(RespintoStation).ExecuteCommandAsync();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return EntryPermissionResult.UnkownException;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 入站校验结果
|
||||
/// </summary>
|
||||
enum EntryPermissionResult
|
||||
{
|
||||
//1之前工位数据正常
|
||||
@ -0,0 +1,415 @@
|
||||
using MDM.Model.Plant;
|
||||
using MDM.Model.Process;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using RIZO.Model.Mes;
|
||||
using RIZO.Model.MES.product_trace;
|
||||
using RIZO.Repository;
|
||||
using RIZO.Service.PLC;
|
||||
using S7.Net;
|
||||
using SqlSugar.IOC;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RIZO.Service.PLCBackground.Stations
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// OP07_01 出站
|
||||
/// </summary>
|
||||
public class PlcOutStationService_OP07_01 : BackgroundService
|
||||
{
|
||||
private static Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
private PlcConntectHepler _plcService;
|
||||
private readonly TimeSpan _pollingInterval = TimeSpan.FromSeconds(5);
|
||||
private readonly string _ipAddress = "192.168.10.222";
|
||||
private readonly CpuType _cpuType = CpuType.S71500;
|
||||
private string WorkstationCode;
|
||||
private readonly SqlSugarClient Context;
|
||||
public PlcOutStationService_OP07_01()
|
||||
{
|
||||
Context = DbScoped.SugarScope.CopyNew();
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
_logger.Info("PLC Polling Service started");
|
||||
|
||||
// 使用工厂方法创建服务实例
|
||||
using (_plcService = new PlcConntectHepler(_ipAddress, _cpuType))
|
||||
{
|
||||
|
||||
// 获取当前的工序/工站
|
||||
WorkstationCode = await Context.Queryable<PlantWorkstation>().Where(it => it.PlcIP == _ipAddress)
|
||||
.Select(it => it.WorkstationCode).FirstAsync();
|
||||
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
//心跳检测
|
||||
await _plcService.WriteAsync("DB1010.DBW0", 1);
|
||||
|
||||
// 轮询出站站请求信号/工位保存查询请求
|
||||
int outStationAsk = await _plcService.ReadAsync<int>("DB1001.DBW2002");
|
||||
if (outStationAsk == 1)
|
||||
{
|
||||
// 处理进站请求
|
||||
_logger.Info("Processing out station request...");
|
||||
|
||||
//获取产品SN码
|
||||
string productModel = await _plcService.ReadStringAsync("DB1001.DBB1000");
|
||||
string productSN = await _plcService.ReadStringAsync("DB1001.DBB1054");
|
||||
|
||||
// 获取工单
|
||||
|
||||
//获取工艺路线工序
|
||||
List<ProcessOperation> processOperations = await Context.Queryable<ProcessRouting>().LeftJoin<ProcessOperation>((r, o) => r.RoutingCode == o.FkRoutingCode)
|
||||
.Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1)
|
||||
.Select((r, o) => o).ToListAsync();
|
||||
//判断改产品是正常件还是返工件
|
||||
|
||||
|
||||
//插入出站请求ASK过站记录
|
||||
ProductPassStationRecord ASKoutStation = new ProductPassStationRecord
|
||||
{
|
||||
ProductSN = productSN,
|
||||
WorkstationCode = WorkstationCode,
|
||||
Routingcode = processOperations.First().FkRoutingCode,
|
||||
OperationCode = WorkstationCode,
|
||||
ProductionLifeStage = 1, // 1表示生产中
|
||||
PasstationType = 2, // 0表示出站请求
|
||||
PasstationDescription = "出站请求ASK",
|
||||
EffectTime = DateTime.Now,
|
||||
CreatedTime = DateTime.Now,
|
||||
|
||||
};
|
||||
await Context.Insertable(ASKoutStation).ExecuteCommandAsync();
|
||||
|
||||
//上传工艺参数
|
||||
bool CheckOutstationResult = await UploadProcessParameters(productSN, processOperations.First().FkRoutingCode, WorkstationCode);
|
||||
|
||||
//判断该产品是否允许进站
|
||||
|
||||
OutPermissionResult result = await checkOutPermission(productModel, productSN, WorkstationCode, processOperations, CheckOutstationResult);
|
||||
await _plcService.WriteAsync("DB1010.DBW2000", (int)result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
await Task.Delay(_pollingInterval, stoppingToken);
|
||||
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_logger.Info("PLC Polling Service is stopping");
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "PLC polling error");
|
||||
await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Info("PLC Polling Service stopped");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存工艺参数上传
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> UploadProcessParameters(string productSN, string RoutingCode, string OperationCode)
|
||||
{
|
||||
bool result = true;
|
||||
List<ProductProcessParameters> productProcessParameters = new List<ProductProcessParameters>();
|
||||
//实际产量
|
||||
ProductProcessParameters ActualProductParameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "actual_product",
|
||||
ParameterName = "实际产量",
|
||||
PlcPoint = "DB1001.DBW1104",
|
||||
Description = OperationCode + "工序的" + "实际产量",
|
||||
DataType = "int",
|
||||
Unit = "个",
|
||||
ActualValue = (await _plcService.ReadAsync<int>("DB1001.DBW1104")).ToString(),
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(ActualProductParameter);
|
||||
|
||||
//合格数量
|
||||
ProductProcessParameters QualifiedProductParameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "actual_product",
|
||||
ParameterName = "合格数量",
|
||||
PlcPoint = "DB1001.DBW1108",
|
||||
Description = OperationCode + "工序的" + "合格数量",
|
||||
DataType = "int",
|
||||
Unit = "个",
|
||||
ActualValue = (await _plcService.ReadAsync<int>("DB1001.DBW1108")).ToString(),
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(QualifiedProductParameter);
|
||||
|
||||
//失败数量
|
||||
ProductProcessParameters FailureProductParameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "actual_product",
|
||||
ParameterName = "失败数量",
|
||||
PlcPoint = "DB1001.DBW1112",
|
||||
Description = OperationCode + "工序的" + "失败数量",
|
||||
DataType = "int",
|
||||
Unit = "个",
|
||||
ActualValue = (await _plcService.ReadAsync<int>("DB1001.DBW1112")).ToString(),
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(FailureProductParameter);
|
||||
|
||||
|
||||
//SN_1
|
||||
ProductProcessParameters SN_1Parameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "SN_1",
|
||||
ParameterName = "SN_1",
|
||||
PlcPoint = "DB1001.DBW1112",
|
||||
Description = OperationCode + "工序的" + "SN_1",
|
||||
DataType = "string",
|
||||
Unit = "个",
|
||||
ActualValue = await _plcService.ReadStringAsync("DB1001.DBW1112"),
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(SN_1Parameter);
|
||||
|
||||
//SN_2
|
||||
ProductProcessParameters SN_2Parameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "SN_1",
|
||||
ParameterName = "SN_1",
|
||||
PlcPoint = "DB1001.DBW2134",
|
||||
Description = OperationCode + "工序的" + "SN_2",
|
||||
DataType = "string",
|
||||
Unit = "个",
|
||||
ActualValue = await _plcService.ReadStringAsync("DB1001.DBW2134"),
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(SN_2Parameter);
|
||||
|
||||
//相机结果
|
||||
|
||||
int CameraResult = await _plcService.ReadAsync<int>("DB1001.DBW2164");
|
||||
if (CameraResult == 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
if (CameraResult == 2)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
ProductProcessParameters CameraParameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "CameraResult",
|
||||
ParameterName = "CameraResult",
|
||||
PlcPoint = "DB1001.DBW2164",
|
||||
Description = OperationCode + "工序的" + "相机结果 1 OK 2 NG",
|
||||
DataType = "int",
|
||||
Unit = "个",
|
||||
ActualValue = CameraResult.ToString(),
|
||||
ExpectValue = "1",
|
||||
Result = result ? 1 : 0,
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(CameraParameter);
|
||||
|
||||
//站位结果
|
||||
int StationPosition = await _plcService.ReadAsync<int>("DB1001.DBW2166");
|
||||
if (StationPosition == 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
if (StationPosition == 2)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
ProductProcessParameters StationPositionParameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "StationPosition",
|
||||
ParameterName = "StationPosition",
|
||||
PlcPoint = "DB1001.DBW2166",
|
||||
Description = OperationCode + "工序的" + "站位结果 1 OK 2 NG",
|
||||
DataType = "int",
|
||||
Unit = "个",
|
||||
ActualValue = StationPosition.ToString(),
|
||||
ExpectValue = "1",
|
||||
Result = result ? 1 : 0,
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(StationPositionParameter);
|
||||
|
||||
//节拍时间 real类型
|
||||
ProductProcessParameters BeatParameter = new ProductProcessParameters
|
||||
{
|
||||
ProductSN = productSN,
|
||||
RoutingCode = RoutingCode,
|
||||
OperationCode = OperationCode,
|
||||
ProductlinebodyCode = "line3",
|
||||
WorkstationCode = OperationCode,
|
||||
ParameterCode = "beat",
|
||||
ParameterName = "节拍时间",
|
||||
PlcPoint = "DB1001.DBD2168",
|
||||
Description = OperationCode + "工序的" + "节拍时间",
|
||||
DataType = "float",
|
||||
Unit = "s",
|
||||
ActualValue = (await _plcService.ReadAsync<float>("DB1001.DBD2168")).ToString(),
|
||||
CreatedTime = DateTime.Now,
|
||||
};
|
||||
productProcessParameters.Add(BeatParameter);
|
||||
|
||||
await Context.Insertable(productProcessParameters).ExecuteCommandAsync();
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 校验是否可以出站
|
||||
/// </summary>
|
||||
/// <param name="productModel">产品型号</param>
|
||||
/// <param name="productSN">产品SN</param>
|
||||
/// <returns></returns>
|
||||
private async Task<OutPermissionResult> checkOutPermission(string productModel, string productSN, string workstationCode, List<ProcessOperation> processOperations, bool CheckOutstationResult)
|
||||
{
|
||||
|
||||
OutPermissionResult result = OutPermissionResult.UnkownException;
|
||||
|
||||
if (!CheckOutstationResult)
|
||||
{
|
||||
|
||||
result = OutPermissionResult.ProcessParameterNG;
|
||||
|
||||
goto InsertPassrecord;
|
||||
}
|
||||
|
||||
|
||||
//OK 准许进站
|
||||
result = OutPermissionResult.OK;
|
||||
goto InsertPassrecord;
|
||||
InsertPassrecord:
|
||||
//插入出站请求Resp 过站记录
|
||||
ProductPassStationRecord RespintoStation = new ProductPassStationRecord
|
||||
{
|
||||
ProductSN = productSN,
|
||||
WorkstationCode = WorkstationCode,
|
||||
Routingcode = processOperations.First().FkRoutingCode,
|
||||
OperationCode = WorkstationCode,
|
||||
ProductionLifeStage = 1, // 1表示生产中
|
||||
PasstationType = 3, // 出站完毕
|
||||
PasstationDescription = "出站完毕Resp",
|
||||
EffectTime = DateTime.Now,
|
||||
OutStationTime = DateTime.Now,
|
||||
ResultCode = (int)result,
|
||||
ResultDescription = result.ToString(),
|
||||
CreatedTime = DateTime.Now,
|
||||
|
||||
};
|
||||
await Context.Insertable(RespintoStation).ExecuteCommandAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 出站校验结果
|
||||
/// </summary>
|
||||
public enum OutPermissionResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 1 OK - 成功
|
||||
/// </summary>
|
||||
OK = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 2 产品时间属性增加失败
|
||||
/// </summary>
|
||||
ProductTimeAttributeAddFailed = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 3 产品条码合并失败
|
||||
/// </summary>
|
||||
ProductBarcodeMergeFailed = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 4 产品结果上传次数超出
|
||||
/// </summary>
|
||||
ProductUploadCountExceeded = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 5 时间属性移除失败
|
||||
/// </summary>
|
||||
TimeAttributeRemoveFailed = 5,
|
||||
|
||||
/// <summary>
|
||||
/// 6 数据保存失败
|
||||
/// </summary>
|
||||
DataSaveFailed = 6,
|
||||
|
||||
/// <summary>
|
||||
/// 10 上传条码为空
|
||||
/// </summary>
|
||||
UploadBarcodeEmpty = 10,
|
||||
/// <summary>
|
||||
/// 11 未知异常
|
||||
/// </summary>
|
||||
UnkownException = 11,
|
||||
|
||||
/// <summary>
|
||||
/// 工艺参数NG
|
||||
/// </summary>
|
||||
ProcessParameterNG = 12
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user