PLC数采现场调试
This commit is contained in:
parent
3b292ba334
commit
bf6a7f11b6
@ -46,28 +46,56 @@ namespace RIZO.Admin.WebApi.PLC.Service
|
||||
//MES返回PLC请求映射
|
||||
private readonly Dictionary<string, string> _mesIntReturnMap = new()
|
||||
{
|
||||
{ "设备使能", "DB1317.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1037.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1317.DBW2002" }, // Int
|
||||
{ "设备使能", "DB1000.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1000.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1000.DBW2002" }, // Int
|
||||
};
|
||||
|
||||
private readonly Dictionary<string, (string Addr, int Len)> _mesStringReturnMap = new()
|
||||
private readonly Dictionary<string, string> _mesop20_3IntReturnMap = new()
|
||||
{
|
||||
{ "产品型号", ("DB1317.DBB1016", 14) }, // String[14]
|
||||
{ "订单下发", ("DB1317.DBB1032", 50) }, // String[50]
|
||||
{ "设备使能", "DB1000.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1000.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1000.DBW2012" }, // Int
|
||||
};
|
||||
|
||||
private readonly Dictionary<string, string> _mesop058IntReturnMap = new()
|
||||
private readonly Dictionary<string, string> _mesop20_4IntReturnMap = new()
|
||||
{
|
||||
{ "设备使能", "DB1000.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1000.DBW2000" }, // Int
|
||||
{ "1#产品结束保存结果", "DB1000.DBW2002" }, // Int
|
||||
{ "2#产品结束保存结果", "DB1000.DBW2004" }, // Int
|
||||
{ "3#产品结束保存结果", "DB1000.DBW2006" }, // Int
|
||||
{ "4#产品结束保存结果", "DB1000.DBW2008" }, // Int
|
||||
};
|
||||
private readonly Dictionary<string, string> _mesop50IntReturnMap = new()
|
||||
{
|
||||
{ "设备使能", "DB300.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB300.DBW2000" }, // Int
|
||||
{ "保存结果", "DB300.DBW2002" }, // Int
|
||||
{ "1#产品结束保存结果", "DB300.DBW48" }, // Int
|
||||
{ "2#产品结束保存结果", "DB300.DBW204" }, // Int
|
||||
{ "3#产品结束保存结果", "DB300.DBW360" }, // Int
|
||||
{ "4#产品结束保存结果", "DB300.DBW516" }, // Int
|
||||
};
|
||||
|
||||
private readonly Dictionary<string, (string Addr, int Len)> _mesop058StringReturnMap = new()
|
||||
private readonly Dictionary<string, string> _mesop058IntReturnMap = new()
|
||||
{
|
||||
{ "产品型号", ("DB300.DBB1016", 14) }, // String[14]
|
||||
{ "订单下发", ("DB300.DBB1032", 50) }, // String[50]
|
||||
{ "设备使能", "DB1003.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1003.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1003.DBW2002" }, // Int
|
||||
};
|
||||
private readonly Dictionary<string, string> _mesop075IntReturnMap = new()
|
||||
{
|
||||
{ "设备使能", "DB1000.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1000.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1000.DBW2004" }, // Int
|
||||
};
|
||||
private readonly Dictionary<string, string> _mesop080_1IntReturnMap = new()
|
||||
{
|
||||
{ "设备使能", "DB1000.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1000.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1000.DBW2006" }, // Int
|
||||
};
|
||||
private readonly Dictionary<string, string> _mesop100IntReturnMap = new()
|
||||
{
|
||||
{ "设备使能", "DB1000.DBW0" }, // Int
|
||||
{ "工位开始查询结果", "DB1000.DBW2000" }, // Int
|
||||
{ "保存结果", "DB1000.DBW2008" }, // Int
|
||||
};
|
||||
|
||||
// OP020-2 专属地址映射(合盖工位,DB1001)
|
||||
@ -5615,35 +5643,23 @@ namespace RIZO.Admin.WebApi.PLC.Service
|
||||
{
|
||||
try
|
||||
{
|
||||
if (plcName == "OP058")
|
||||
var targetMap = plcName switch
|
||||
{
|
||||
WritePlcValue(plc, _mesop058IntReturnMap["设备使能"], "1");
|
||||
//WritePlcValue(plc, _mesIntReturnMap["工位开始查询结果"], "1");
|
||||
WritePlcValue(plc, _mesop058IntReturnMap["保存结果"], saveResult);
|
||||
if (prodData.ProductModel != null && prodData.ProductModel.Length > 0)
|
||||
{
|
||||
WritePlcString(plc, _mesop058StringReturnMap["产品型号"].Addr, _mesop058StringReturnMap["产品型号"].Len, prodData.ProductModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
WritePlcString(plc, _mesop058StringReturnMap["产品型号"].Addr, _mesop058StringReturnMap["产品型号"].Len, prodData.ProductModel);
|
||||
}
|
||||
WritePlcString(plc, _mesop058StringReturnMap["订单下发"].Addr, _mesop058StringReturnMap["订单下发"].Len, "cpxhtest");
|
||||
}
|
||||
else
|
||||
"OP20-3" => _mesop20_3IntReturnMap,
|
||||
"OP20-4" => _mesop20_4IntReturnMap,
|
||||
"OP50-1" => _mesop20_4IntReturnMap,
|
||||
//"OP050" => _mesop050IntReturnMap,//四个保存结果
|
||||
"OP058" => _mesop058IntReturnMap,
|
||||
"OP075" => _mesop075IntReturnMap,
|
||||
"OP080-1" => _mesop080_1IntReturnMap,
|
||||
"OP100" => _mesop100IntReturnMap,
|
||||
"OP110-2" => _mesop080_1IntReturnMap,
|
||||
_ => _mesIntReturnMap
|
||||
};
|
||||
if (targetMap != null)
|
||||
{
|
||||
WritePlcValue(plc, _mesIntReturnMap["设备使能"], "1");
|
||||
//WritePlcValue(plc, _mesIntReturnMap["工位开始查询结果"], "1");
|
||||
WritePlcValue(plc, _mesIntReturnMap["保存结果"], saveResult);
|
||||
if (prodData.ProductModel != null && prodData.ProductModel.Length > 0)
|
||||
{
|
||||
WritePlcString(plc, _mesStringReturnMap["产品型号"].Addr, _mesStringReturnMap["产品型号"].Len, prodData.ProductModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
WritePlcString(plc, _mesStringReturnMap["产品型号"].Addr, _mesStringReturnMap["产品型号"].Len, prodData.ProductModel);
|
||||
}
|
||||
WritePlcString(plc, _mesStringReturnMap["订单下发"].Addr, _mesStringReturnMap["订单下发"].Len, "cpxhtest");
|
||||
WritePlcValue(plc, targetMap["设备使能"], "1");
|
||||
WritePlcValue(plc, targetMap["保存结果"], saveResult);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -41,7 +41,7 @@ builder.Services.Configure<PlcPollingSettings>(builder.Configuration.GetSection(
|
||||
builder.Services.AddSingleton<PlcService>();
|
||||
builder.Services.AddScoped<IPlcProductionDataService, PlcProductionDataService>();
|
||||
// 新增:注册PLC后台监听服务(项目启动自动执行)
|
||||
//builder.Services.AddHostedService<PlcHostedService>();
|
||||
builder.Services.AddHostedService<PlcHostedService>();
|
||||
// ==========================
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
@ -112,7 +112,8 @@ builder.Services.AddLocalization(options => options.ResourcesPath = "");
|
||||
|
||||
//PLC进站后台服务注册
|
||||
//builder.Services.AddHostedService<PlcOutStationService_OP07_01>();
|
||||
//builder.Services.AddHostedService<PlcIntoStationService_OP70_01>();
|
||||
//builder.Services.AddHostedService<PlcIntoStationService_OP102>();
|
||||
builder.Services.AddHostedService<PlcIntoStationService_OP100>();
|
||||
|
||||
//螺丝枪服务注册
|
||||
//builder.Services.AddHostedService<PF6ScrewGunService>();
|
||||
|
||||
@ -416,16 +416,16 @@
|
||||
},
|
||||
{
|
||||
"Id": 17,
|
||||
"isEnble": false,
|
||||
"isEnble": true,
|
||||
"WorkStationCode": "OP100",
|
||||
"WorkStationName": "OP100 手动上料壳体&盖板",
|
||||
"PlcType": "S71500",
|
||||
"IpAddress": "192.168.11.101",
|
||||
"IpAddress": "192.168.11.171",
|
||||
"IntoStation": {
|
||||
"Heartbeat": "DB1000.DBW0", // 心跳地址
|
||||
"IntoStationAsk": "DB1001.DBW2000", // 进站请求地址
|
||||
"ProductModel": "DB1001.DBB1000",
|
||||
"ProductSN": "DB1001.DBB1054",
|
||||
"ProductSN": "DB1001.DBB2100",
|
||||
"IntoStationResp": "DB1000.DBW2000" // 进站回复结果地址
|
||||
}
|
||||
},
|
||||
@ -446,7 +446,7 @@
|
||||
},
|
||||
{
|
||||
"Id": 19,
|
||||
"isEnble": false,
|
||||
"isEnble": true,
|
||||
"WorkStationCode": "OP1012",
|
||||
"WorkStationName": "OP1012 Ring terminal装配",
|
||||
"PlcType": "S71500",
|
||||
@ -485,7 +485,7 @@
|
||||
"Heartbeat": "DB1010.DBW0", // 心跳地址
|
||||
"IntoStationAsk": "DB1001.DBW2000", // 进站请求地址
|
||||
"ProductModel": "DB1001.DBB1000",
|
||||
"ProductSN": "DB1001.DBB1054",
|
||||
"ProductSN": "DB1001.DBB2100",
|
||||
"IntoStationResp": "DB1010.DBW2000" // 进站回复结果地址
|
||||
}
|
||||
},
|
||||
|
||||
@ -25,6 +25,7 @@ namespace RIZO.Service.PLC
|
||||
_cpuType = cpuType;
|
||||
_rack = rack;
|
||||
_slot = slot;
|
||||
ConnectAsync();
|
||||
}
|
||||
|
||||
private async Task ConnectAsync(CancellationToken cancellationToken = default)
|
||||
|
||||
@ -65,8 +65,6 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
using (_plcService = new PlcConntectHepler(plcSetting.IpAddress, cpuType))
|
||||
{
|
||||
|
||||
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
|
||||
{
|
||||
@ -117,12 +115,12 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
EntryPermissionResult result = await checkEntryPermission(productModel, productSN, WorkstationCode, processOperations);
|
||||
// "DB1010.DBW2000"
|
||||
// await _plcService.WriteAsync(plcSetting.intoStation.IntoStationResp, (short)result);
|
||||
await _plcService.WriteAsync2(plcSetting.intoStation.IntoStationResp, result);
|
||||
await _plcService.WriteAsync2(plcSetting.intoStation.IntoStationResp,(int) result);
|
||||
}
|
||||
await Task.Delay(_pollingInterval, stoppingToken);
|
||||
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
_logger.Info("PLC Polling Service is stopping");
|
||||
break;
|
||||
@ -184,15 +182,18 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
/// <returns></returns>
|
||||
protected virtual async Task<EntryPermissionResult> checkEntryPermission(string productModel, string productSN, string workstationCode, List<ProcessOperation> processOperations)
|
||||
{
|
||||
|
||||
workstationCode = workstationCode.Trim();
|
||||
EntryPermissionResult result = EntryPermissionResult.UnkownException;
|
||||
|
||||
//2上工位无记录
|
||||
|
||||
//ProcessOperation LastOperation1 = processOperations.Where(operation => operation.OperationSeq < processOperations.Where(it => it.OperationCode == workstationCode).Select(it => it.OperationSeq).First()).OrderByDescending(operation => operation.OperationSeq).First();
|
||||
var LastOperationSeqObject = processOperations
|
||||
.Where(operation => operation.OperationCode == workstationCode)
|
||||
.FirstOrDefault();
|
||||
//var LastOperationSeqObject = processOperations
|
||||
// .Where(operation => operation.OperationCode == workstationCode)
|
||||
// .FirstOrDefault();
|
||||
var LastOperationSeqObject = processOperations?.Where(operation =>
|
||||
string.Equals(operation.OperationCode, workstationCode, StringComparison.OrdinalIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
if (LastOperationSeqObject.LastOperationSeq == 0)
|
||||
{
|
||||
return EntryPermissionResult.NoRecordAtPreviousStation;
|
||||
@ -204,7 +205,7 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
.Replace("\r", "") // 移除回车符
|
||||
.Replace("\n", "") // 可选:移除换行符
|
||||
.Trim(); // 移除首尾空格
|
||||
|
||||
productSN = productSN.Replace("\r", "").Replace("\n", "").Trim();
|
||||
// 3. 构建并执行真正的异步查询(补充执行方法,使 await 生效)
|
||||
var ExistLastOperationRecord = await DbScoped.SugarScope.CopyNew()
|
||||
.Queryable<ProductPassStationRecord>()
|
||||
|
||||
@ -24,7 +24,7 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
/// <summary>
|
||||
/// OP点散热胶GF1500
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(PlcIntoStationService_OP100), ServiceLifetime = LifeTime.BackgroundService)]
|
||||
//[AppService(ServiceType = typeof(PlcIntoStationService_OP100), ServiceLifetime = LifeTime.BackgroundService)]
|
||||
public class PlcIntoStationService_OP100 : PlcIntoStationService_Common
|
||||
{
|
||||
public PlcIntoStationService_OP100(IOptions<OptionsSetting> options) : base(options)
|
||||
|
||||
@ -24,7 +24,7 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
/// <summary>
|
||||
/// OP点散热胶GF1500
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(PlcIntoStationService_OP102), ServiceLifetime = LifeTime.BackgroundService)]
|
||||
// [AppService(ServiceType = typeof(PlcIntoStationService_OP102), ServiceLifetime = LifeTime.BackgroundService)]
|
||||
public class PlcIntoStationService_OP102 : PlcIntoStationService_Common
|
||||
{
|
||||
public PlcIntoStationService_OP102(IOptions<OptionsSetting> options) : base(options)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user