PLC进站请求BUG 修改
This commit is contained in:
parent
6d6d8c6e09
commit
e8116783c8
@ -112,7 +112,7 @@ builder.Services.AddLocalization(options => options.ResourcesPath = "");
|
|||||||
|
|
||||||
//builder.Services.AddHostedService<PlcOutStationService_OP07_01>();
|
//builder.Services.AddHostedService<PlcOutStationService_OP07_01>();
|
||||||
//builder.Services.AddHostedService<PlcIntoStationService_OP70_01>();
|
//builder.Services.AddHostedService<PlcIntoStationService_OP70_01>();
|
||||||
|
builder.Services.AddHostedService<PlcIntoStationService_OP80_01>();
|
||||||
|
|
||||||
// 在应用程序启动的最开始处调用
|
// 在应用程序启动的最开始处调用
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|||||||
@ -129,6 +129,39 @@ namespace RIZO.Service.PLC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task WriteAsync2(string address, object value, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await _semaphore.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 1. 确保PLC连接正常
|
||||||
|
if (_plc == null || !_plc.IsConnected)
|
||||||
|
{
|
||||||
|
await ConnectAsync(cancellationToken);
|
||||||
|
if (_plc == null || !_plc.IsConnected)
|
||||||
|
throw new InvalidOperationException("PLC未连接");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 核心修复:DBW地址强制转short(适配16位字类型)
|
||||||
|
object writeValue = value;
|
||||||
|
if (address.Contains("DBW", StringComparison.OrdinalIgnoreCase) && value is int intVal)
|
||||||
|
{
|
||||||
|
writeValue = (short)intVal; // 写入1时自动转为short,匹配DBW类型
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 移除Task.Run,直接同步写入(避免异步调度导致失效)
|
||||||
|
_plc.Write(address, writeValue);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Write error: {ex.Message}");
|
||||||
|
throw; // 抛出异常,让上层感知写入失败(关键:不吞异常)
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_semaphore.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private T ConvertResult<T>(object result)
|
private T ConvertResult<T>(object result)
|
||||||
|
|||||||
@ -58,31 +58,42 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
|||||||
await _plcService.WriteAsync("DB1020.DBW0", 1);
|
await _plcService.WriteAsync("DB1020.DBW0", 1);
|
||||||
|
|
||||||
// 轮询进站请求信号/工位开始查询请求
|
// 轮询进站请求信号/工位开始查询请求
|
||||||
int intoStationAsk = await _plcService.ReadAsync<int>("DB1001.DBW2000");
|
int intoStationAsk = await _plcService.ReadAsync<int>("DB1017.DBW2000");
|
||||||
if (intoStationAsk == 1)
|
if (intoStationAsk == 1)
|
||||||
{
|
{
|
||||||
// 处理进站请求
|
// 处理进站请求
|
||||||
_logger.Info("Processing into station request...");
|
_logger.Info("Processing into station request...");
|
||||||
|
|
||||||
//获取产品SN码
|
//获取产品SN码
|
||||||
string productModel = await _plcService.ReadStringAsync("DB1001.DBB1000");
|
string productModel = await _plcService.ReadStringAsync("DB1017.DBB1000");
|
||||||
string productSN = await _plcService.ReadStringAsync("DB1001.DBB1054");
|
string productSN = await _plcService.ReadStringAsync("DB1017.DBB1054");
|
||||||
|
int ReWorkFlag = await _plcService.ReadAsync<int>("DB1017.DBW8");
|
||||||
|
//判断改产品是正常件还是返工件
|
||||||
|
if (ReWorkFlag == 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 获取工单
|
// 获取工单
|
||||||
|
|
||||||
//获取工艺路线工序
|
//获取工艺路线工序
|
||||||
List<ProcessOperation> processOperations = await Context.Queryable<ProcessRouting>().LeftJoin<ProcessOperation>((r, o) => r.RoutingCode == o.FkRoutingCode)
|
List<ProcessOperation> processOperations = await Context.Queryable<ProcessRouting>().LeftJoin<ProcessOperation>((r, o) => r.RoutingCode == o.FkRoutingCode)
|
||||||
.Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1)
|
.Where((r, o) => r.FkProductMaterialCode == productModel && r.Status == 1)
|
||||||
.Select((r, o) => o).ToListAsync();
|
.Select((r, o) => o).ToListAsync();
|
||||||
//判断改产品是正常件还是返工件
|
var routingcode = string.Empty;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
routingcode = processOperations.First().FkRoutingCode;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
if (routingcode == null || routingcode.Length == 0)
|
||||||
|
return;
|
||||||
//插入入站请求ASK过站记录
|
//插入入站请求ASK过站记录
|
||||||
ProductPassStationRecord ASKintoStation = new ProductPassStationRecord
|
ProductPassStationRecord ASKintoStation = new ProductPassStationRecord
|
||||||
{
|
{
|
||||||
ProductSN = productSN,
|
ProductSN = productSN,
|
||||||
WorkstationCode = WorkstationCode,
|
WorkstationCode = WorkstationCode,
|
||||||
Routingcode = processOperations.First().FkRoutingCode,
|
Routingcode = routingcode,
|
||||||
OperationCode = WorkstationCode,
|
OperationCode = WorkstationCode,
|
||||||
ProductionLifeStage = 1, // 1表示生产中
|
ProductionLifeStage = 1, // 1表示生产中
|
||||||
PasstationType = 0, // 0表示入站请求
|
PasstationType = 0, // 0表示入站请求
|
||||||
@ -93,7 +104,10 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
|||||||
await Context.Insertable(ASKintoStation).ExecuteCommandAsync();
|
await Context.Insertable(ASKintoStation).ExecuteCommandAsync();
|
||||||
//判断该产品是否允许进站
|
//判断该产品是否允许进站
|
||||||
EntryPermissionResult result = await checkEntryPermission(productModel, productSN, WorkstationCode, processOperations);
|
EntryPermissionResult result = await checkEntryPermission(productModel, productSN, WorkstationCode, processOperations);
|
||||||
await _plcService.WriteAsync("DB1020.DBW2000", (int)result);
|
//进站请求结果
|
||||||
|
await _plcService.WriteAsync2("DB1317.DBW2000", (int)result);
|
||||||
|
//设别使能1
|
||||||
|
await _plcService.WriteAsync2("DB1317.DBW0", 1);
|
||||||
}
|
}
|
||||||
await Task.Delay(_pollingInterval, stoppingToken);
|
await Task.Delay(_pollingInterval, stoppingToken);
|
||||||
|
|
||||||
@ -122,10 +136,10 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<EntryPermissionResult> checkEntryPermission(string productModel, string productSN, string workstationCode, List<ProcessOperation> processOperations)
|
private async Task<EntryPermissionResult> checkEntryPermission(string productModel, string productSN, string workstationCode, List<ProcessOperation> processOperations)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
EntryPermissionResult result = EntryPermissionResult.UnkownException;
|
EntryPermissionResult result = EntryPermissionResult.UnkownException;
|
||||||
|
|
||||||
|
|
||||||
//2上工位无记录
|
//2上工位无记录
|
||||||
|
|
||||||
//ProcessOperation LastOperation = processOperations.Where(operation => operation.OperationSeq < processOperations.Where(it => it.OperationCode == workstationCode).Select(it => it.OperationSeq).First()).OrderByDescending(operation => operation.OperationSeq).First();
|
//ProcessOperation LastOperation = processOperations.Where(operation => operation.OperationSeq < processOperations.Where(it => it.OperationCode == workstationCode).Select(it => it.OperationSeq).First()).OrderByDescending(operation => operation.OperationSeq).First();
|
||||||
@ -232,9 +246,14 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
|||||||
|
|
||||||
};
|
};
|
||||||
await Context.Insertable(RespintoStation).ExecuteCommandAsync();
|
await Context.Insertable(RespintoStation).ExecuteCommandAsync();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return EntryPermissionResult.PreviousStationDataAbnormal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user