From 9cd4ce6672573faf000bbf099b1a8c00c080c322 Mon Sep 17 00:00:00 2001 From: quowingwang Date: Sat, 31 Jan 2026 10:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E7=AB=99=E4=B8=8B=E6=8B=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plant/PlantWorkstationController.cs | 8 +- .../IService/IPlantWorkstationService.cs | 3 +- MDM/Services/Plant/PlantWorkstationService.cs | 29 +- RIZO.Admin.WebApi/PLC/Service/PlcService.cs | 432 +++++++++++------- 4 files changed, 293 insertions(+), 179 deletions(-) diff --git a/MDM/Controllers/Plant/PlantWorkstationController.cs b/MDM/Controllers/Plant/PlantWorkstationController.cs index 0518650..0eeec9d 100644 --- a/MDM/Controllers/Plant/PlantWorkstationController.cs +++ b/MDM/Controllers/Plant/PlantWorkstationController.cs @@ -144,7 +144,13 @@ namespace MDM.Controllers.Plant return SUCCESS(response); } + //获取工站下拉 + [HttpGet("getWorkstationPulldown")] + public ApiResult GetWorkstationPulldown() + { + var response = _PlantWorkstationService.GetWorkstationPulldown(); - + return response; + } } } \ No newline at end of file diff --git a/MDM/Services/Plant/IService/IPlantWorkstationService.cs b/MDM/Services/Plant/IService/IPlantWorkstationService.cs index f47f990..801e552 100644 --- a/MDM/Services/Plant/IService/IPlantWorkstationService.cs +++ b/MDM/Services/Plant/IService/IPlantWorkstationService.cs @@ -1,5 +1,6 @@ +using Infrastructure.Model; using MDM.Model; using MDM.Model.Plant; using MDM.Model.Plant.Dto; @@ -25,6 +26,6 @@ namespace MDM.Services.IPlantService List GetWorkShop(string? site_code, string? workshop_code); List GetPlantProductlinebodies(string? site_code, string? workshop_code, string? linecode); - object GetWorkstation(); + ApiResult GetWorkstationPulldown(); } } diff --git a/MDM/Services/Plant/PlantWorkstationService.cs b/MDM/Services/Plant/PlantWorkstationService.cs index a1bfdf6..4f5f59d 100644 --- a/MDM/Services/Plant/PlantWorkstationService.cs +++ b/MDM/Services/Plant/PlantWorkstationService.cs @@ -1,14 +1,13 @@ -using System; -using SqlSugar; using Infrastructure.Attribute; - -using MDM.Services.IPlantService; - -using MDM.Service; +using Infrastructure.Model; using MDM.Model; using MDM.Model.Plant; using MDM.Model.Plant.Dto; using MDM.Repository; +using MDM.Service; +using MDM.Services.IPlantService; +using SqlSugar; +using System; namespace MDM.Services.Plant { @@ -121,5 +120,23 @@ namespace MDM.Services.Plant .ToList(); } + public ApiResult GetWorkstationPulldown() + { + try + { + return ApiResult.Success(data: Context.Queryable() + .Select(it => new + { + it.WorkstationCode, + it.WorkstationName + }) + .ToList()); + } + catch + { + return null; + } + } + } } \ No newline at end of file diff --git a/RIZO.Admin.WebApi/PLC/Service/PlcService.cs b/RIZO.Admin.WebApi/PLC/Service/PlcService.cs index e7f9f0c..5fc2751 100644 --- a/RIZO.Admin.WebApi/PLC/Service/PlcService.cs +++ b/RIZO.Admin.WebApi/PLC/Service/PlcService.cs @@ -46,15 +46,28 @@ namespace RIZO.Admin.WebApi.PLC.Service //MES返回PLC请求映射 private readonly Dictionary _mesIntReturnMap = new() { - { "设备使能", "DB1317.DBW0" }, // Int - { "工位开始查询结果", "DB1317.DBW2000" }, // Int - { "保存结果", "DB1317.DBW2002" }, // Int + { "设备使能", "DB1000.DBW0" }, // Int + { "工位开始查询结果", "DB1000.DBW2000" }, // Int + { "保存结果", "DB1000.DBW2002" }, // Int }; private readonly Dictionary _mesStringReturnMap = new() { - { "产品型号", ("DB1317.DBB1016", 14) }, // String[14] - { "订单下发", ("DB1317.DBB1032", 50) }, // String[50] + { "产品型号", ("DB1000.DBB1016", 14) }, // String[14] + { "订单下发", ("DB1000.DBB1032", 50) }, // String[50] + }; + + private readonly Dictionary _mesop058IntReturnMap = new() + { + { "设备使能", "DB300.DBW0" }, // Int + { "工位开始查询结果", "DB300.DBW2000" }, // Int + { "保存结果", "DB300.DBW2002" }, // Int + }; + + private readonly Dictionary _mesop058StringReturnMap = new() + { + { "产品型号", ("DB300.DBB1016", 14) }, // String[14] + { "订单下发", ("DB300.DBB1032", 50) }, // String[50] }; // OP020-2 专属地址映射(合盖工位,DB1001) @@ -85,12 +98,36 @@ namespace RIZO.Admin.WebApi.PLC.Service }; // OP020-3 专属地址映射(热铆工位,DB1001) + private readonly Dictionary _op020_3StringMap = new() + { + { "报警信息", ("DB1001.DBB88", 48) }, // Array[1..48] of Byte + { "产品型号", ("DB1001.DBB4060", 48) }, // String[48] + { "产品1SN", ("DB1001.DBB2300", 48) }, // String[48] + { "产品2SN", ("DB1001.DBB2350", 48) }, // String[48] + { "产品3SN", ("DB1001.DBB2400", 48) }, // String[48] + { "产品4SN", ("DB1001.DBB2450", 48) } // String[48] + }; + private readonly Dictionary _op020_3IntMap = new() { + // 基础状态 { "运行状态", "DB1001.DBW0" }, // Int - 1=空闲,2=运行中,3=故障 { "设备模式", "DB1001.DBW2" }, // Int - 1=空模式;2=手动;4=初始化;8=自动;16=CycleStop { "设备在线状态", "DB1001.DBW4" }, // Int - 1=离线,0=在线 + { "ByPass", "DB1001.DBW6" }, // Int - 1=ByPass,0=正常模式 { "生产模式", "DB1001.DBW8" }, // Int - 1=正常模式;2=清线模式;4=返工模式;8=换型模式;16=预热模式 + + // 上传请求 + { "查询请求", "DB1001.DBW2000" }, // Int - 1:请求开始,0:无请求 + { "上传请求", "DB1001.DBW2002" }, // Int - 1:请求开始,0:无请求 + + // 节拍时间 + { "节拍时间", "DB1001.DBD2988" }, // Real + + // 产品结果与产量 + { "合格数量", "DB1001.DBD4110" }, // DInt + { "失败数量", "DB1001.DBD4114" }, // DInt + { "实际数量", "DB1001.DBD4118" } // DInt }; // OP020-4 专属地址映射(pin压合&视觉检查工位,DB1001) @@ -345,130 +382,130 @@ namespace RIZO.Admin.WebApi.PLC.Service // OP070-1 专属地址映射 (点散热胶GF1500工位) OP070-2 点散热胶TC4060 OP070-3 点散热胶GF3500 private readonly Dictionary _op070_1StringMap = new() { - //{ "报警信息", ("DB1011.DBB58", 48) }, // Array[1..48] of Byte - { "订单名称", ("DB1011.DBB1000", 48) }, // String[48] - { "产品名称", ("DB1011.DBB1054", 48) }, // String[48] - { "产品型号", ("DB1011.DBB2006", 28) }, // String[28] - { "SN_1", ("DB1011.DBB2100", 28) }, // String[28] - { "SN_2", ("DB1011.DBB2134", 28) } // String[28] + //{ "报警信息", ("DB1001.DBB58", 48) }, // Array[1..48] of Byte + { "订单名称", ("DB1001.DBB1000", 48) }, // String[48] + { "产品名称", ("DB1001.DBB1054", 48) }, // String[48] + { "产品型号", ("DB1001.DBB2006", 28) }, // String[28] + { "SN_1", ("DB1001.DBB2100", 28) }, // String[28] + { "SN_2", ("DB1001.DBB2134", 28) } // String[28] }; private readonly Dictionary _op070_1IntMap = new() { - { "运行状态", "DB1011.DBW0" }, // Int - { "设备模式", "DB1011.DBW2" }, // Int - { "设备在线状态", "DB1011.DBW4" }, // Int - { "ByPass", "DB1011.DBW6" }, // Int - { "生产模式", "DB1011.DBW8" }, // Int - { "实际产量", "DB1011.DBD1104" }, // DInt - //{ "合格数量", "DB1011.DBD1108" }, // DInt - //{ "失败数量", "DB1011.DBD1112" }, // DInt - { "查询请求", "DB1011.DBW2000" }, // Int - { "保存请求", "DB1011.DBW2002" }, // Int - { "托盘号", "DB1011.DBW2004" }, // Int - { "相机结果", "DB1011.DBW2164" }, // Int - { "站位结果", "DB1011.DBW2166" }, // Int - { "节拍时间", "DB1011.DBD2168" }, // Real + { "运行状态", "DB1001.DBW0" }, // Int + { "设备模式", "DB1001.DBW2" }, // Int + { "设备在线状态", "DB1001.DBW4" }, // Int + { "ByPass", "DB1001.DBW6" }, // Int + { "生产模式", "DB1001.DBW8" }, // Int + { "实际产量", "DB1001.DBD1104" }, // DInt + //{ "合格数量", "DB1001.DBD1108" }, // DInt + //{ "失败数量", "DB1001.DBD1112" }, // DInt + { "查询请求", "DB1001.DBW2000" }, // Int + { "保存请求", "DB1001.DBW2002" }, // Int + { "托盘号", "DB1001.DBW2004" }, // Int + { "相机结果", "DB1001.DBW2164" }, // Int + { "站位结果", "DB1001.DBW2166" }, // Int + { "节拍时间", "DB1001.DBD2168" }, // Real }; // OP075 专属地址映射 PWM折弯&装配 private readonly Dictionary _op075StringMap = new() { - //{ "报警信息", ("DB1011.DBB58", 48) }, // Array[1..48] of Byte - { "订单名称", ("DB1011.DBB1000", 48) }, // String[48] - { "产品名称", ("DB1011.DBB1054", 48) }, // String[48] - { "产品型号", ("DB1011.DBB2006", 28) }, // String[28] - { "SN_1", ("DB1011.DBB2100", 28) }, // String[28] - { "SN_2", ("DB1011.DBB2192", 28) }, // String[28] - { "芯片SN", ("DB1011.DBB2222", 28) } // String[28] + //{ "报警信息", ("DB1001.DBB58", 48) }, // Array[1..48] of Byte + { "订单名称", ("DB1001.DBB1000", 48) }, // String[48] + { "产品名称", ("DB1001.DBB1054", 48) }, // String[48] + { "产品型号", ("DB1001.DBB2006", 28) }, // String[28] + { "SN_1", ("DB1001.DBB2100", 28) }, // String[28] + { "SN_2", ("DB1001.DBB2192", 28) }, // String[28] + { "芯片SN", ("DB1001.DBB2222", 28) } // String[28] }; private readonly Dictionary _op075IntMap = new() { - { "运行状态", "DB1011.DBW0" }, // Int - { "设备模式", "DB1011.DBW2" }, // Int - { "设备在线状态", "DB1011.DBW4" }, // Int - { "ByPass", "DB1011.DBW6" }, // Int - { "生产模式", "DB1011.DBW8" }, // Int - { "实际产量", "DB1011.DBD1104" }, // DInt - //{ "合格数量", "DB1011.DBD1108" }, // DInt - //{ "失败数量", "DB1011.DBD1112" }, // DInt - { "查询请求", "DB1011.DBW2000" }, // Int - { "保存请求", "DB1011.DBW2002" }, // Int - { "托盘号", "DB1011.DBW2004" }, // Int - { "站位结果", "DB1011.DBW2252" }, // Int - { "节拍时间", "DB1011.DBD2284" } // Real + { "运行状态", "DB1001.DBW0" }, // Int + { "设备模式", "DB1001.DBW2" }, // Int + { "设备在线状态", "DB1001.DBW4" }, // Int + { "ByPass", "DB1001.DBW6" }, // Int + { "生产模式", "DB1001.DBW8" }, // Int + { "实际产量", "DB1001.DBD1104" }, // DInt + //{ "合格数量", "DB1001.DBD1108" }, // DInt + //{ "失败数量", "DB1001.DBD1112" }, // DInt + { "查询请求", "DB1001.DBW2000" }, // Int + { "保存请求", "DB1001.DBW2002" }, // Int + { "托盘号", "DB1001.DBW2004" }, // Int + { "站位结果", "DB1001.DBW2252" }, // Int + { "节拍时间", "DB1001.DBD2284" } // Real }; // OP080-1 专属地址映射 PCBA组装&拧紧 private readonly Dictionary _op080_1StringMap = new() { - //{ "报警信息", ("DB1017.DBB58", 48) }, // Array[1..48] of Byte - { "订单名称", ("DB1017.DBB1000", 48) }, // String[48] - { "产品名称", ("DB1017.DBB1054", 48) }, // String[48] - { "合装位机壳_SN", ("DB1017.DBB2100", 28) }, // String[28] - { "合装位PCB_SN", ("DB1017.DBB2130", 28) }, // String[28] - { "拧紧位机壳_SN", ("DB1017.DBB2904", 28) }, // String[28] - { "拧紧位PCB_SN", ("DB1017.DBB3092", 28) }, // String[28] + //{ "报警信息", ("DB1001.DBB58", 48) }, // Array[1..48] of Byte + { "订单名称", ("DB1001.DBB1000", 48) }, // String[48] + { "产品名称", ("DB1001.DBB1054", 48) }, // String[48] + { "合装位机壳_SN", ("DB1001.DBB2100", 28) }, // String[28] + { "合装位PCB_SN", ("DB1001.DBB2130", 28) }, // String[28] + { "拧紧位机壳_SN", ("DB1001.DBB2904", 28) }, // String[28] + { "拧紧位PCB_SN", ("DB1001.DBB3092", 28) }, // String[28] }; private readonly Dictionary _op080_1IntMap = new() { - { "运行状态", "DB1017.DBW0" }, // Int - { "设备模式", "DB1017.DBW2" }, // Int - { "设备在线状态", "DB1017.DBW4" }, // Int - { "ByPass", "DB1017.DBW6" }, // Int - { "生产模式", "DB1017.DBW8" }, // Int - { "实际产量", "DB1017.DBD1104" }, // DInt - { "合格数量", "DB1017.DBD1108" }, // DInt - { "失败数量", "DB1017.DBD1112" }, // DInt - { "合装工位查询请求", "DB1017.DBW2000" }, // Int - { "合装结果保存请求", "DB1017.DBW2004" }, // Int - { "拧紧结果保存请求", "DB1017.DBW2006" }, // Int - { "合装位托盘号", "DB1017.DBW2100" }, // Int - { "拧紧位托盘号", "DB1017.DBW3152" }, // Int + { "运行状态", "DB1001.DBW0" }, // Int + { "设备模式", "DB1001.DBW2" }, // Int + { "设备在线状态", "DB1001.DBW4" }, // Int + { "ByPass", "DB1001.DBW6" }, // Int + { "生产模式", "DB1001.DBW8" }, // Int + { "实际产量", "DB1001.DBD1104" }, // DInt + { "合格数量", "DB1001.DBD1108" }, // DInt + { "失败数量", "DB1001.DBD1112" }, // DInt + { "合装工位查询请求", "DB1001.DBW2000" }, // Int + { "合装结果保存请求", "DB1001.DBW2004" }, // Int + { "拧紧结果保存请求", "DB1001.DBW2006" }, // Int + { "合装位托盘号", "DB1001.DBW2100" }, // Int + { "拧紧位托盘号", "DB1001.DBW3152" }, // Int // 2号螺钉 - { "2号螺钉_结果", "DB1017.DBW3164" }, // Int - { "2号螺钉_扭矩", "DB1017.DBD3166" }, // Real - { "2号螺钉_深度", "DB1017.DBD3170" }, // Real - { "2号螺钉_角度", "DB1017.DBD3174" }, // Real - { "2号螺钉_拧紧时间", "DB1017.DBD3178" }, // Real + { "2号螺钉_结果", "DB1001.DBW3164" }, // Int + { "2号螺钉_扭矩", "DB1001.DBD3166" }, // Real + { "2号螺钉_深度", "DB1001.DBD3170" }, // Real + { "2号螺钉_角度", "DB1001.DBD3174" }, // Real + { "2号螺钉_拧紧时间", "DB1001.DBD3178" }, // Real // 3号螺钉 - { "3号螺钉_结果", "DB1017.DBW3182" }, // Int - { "3号螺钉_扭矩", "DB1017.DBD3184" }, // Real - { "3号螺钉_深度", "DB1017.DBD3188" }, // Real - { "3号螺钉_角度", "DB1017.DBD3192" }, // Real - { "3号螺钉_拧紧时间", "DB1017.DBD3196" }, // Real + { "3号螺钉_结果", "DB1001.DBW3182" }, // Int + { "3号螺钉_扭矩", "DB1001.DBD3184" }, // Real + { "3号螺钉_深度", "DB1001.DBD3188" }, // Real + { "3号螺钉_角度", "DB1001.DBD3192" }, // Real + { "3号螺钉_拧紧时间", "DB1001.DBD3196" }, // Real // 4号螺钉 - { "4号螺钉_结果", "DB1017.DBW3200" }, // Int - { "4号螺钉_扭矩", "DB1017.DBD3202" }, // Real - { "4号螺钉_深度", "DB1017.DBD3206" }, // Real - { "4号螺钉_角度", "DB1017.DBD3210" }, // Real - { "4号螺钉_拧紧时间", "DB1017.DBD3214" }, // Real + { "4号螺钉_结果", "DB1001.DBW3200" }, // Int + { "4号螺钉_扭矩", "DB1001.DBD3202" }, // Real + { "4号螺钉_深度", "DB1001.DBD3206" }, // Real + { "4号螺钉_角度", "DB1001.DBD3210" }, // Real + { "4号螺钉_拧紧时间", "DB1001.DBD3214" }, // Real // 1号螺钉 - { "1号螺钉_结果", "DB1017.DBW3218" }, // Int - { "1号螺钉_扭矩", "DB1017.DBD3220" }, // Real - { "1号螺钉_深度", "DB1017.DBD3224" }, // Real - { "1号螺钉_角度", "DB1017.DBD3228" }, // Real - { "1号螺钉_拧紧时间", "DB1017.DBD3232" }, // Real + { "1号螺钉_结果", "DB1001.DBW3218" }, // Int + { "1号螺钉_扭矩", "DB1001.DBD3220" }, // Real + { "1号螺钉_深度", "DB1001.DBD3224" }, // Real + { "1号螺钉_角度", "DB1001.DBD3228" }, // Real + { "1号螺钉_拧紧时间", "DB1001.DBD3232" }, // Real // 5号螺钉 - { "5号螺钉_结果", "DB1017.DBW3236" }, // Int - { "5号螺钉_扭矩", "DB1017.DBD3238" }, // Real - { "5号螺钉_深度", "DB1017.DBD3242" }, // Real - { "5号螺钉_角度", "DB1017.DBD3246" }, // Real - { "5号螺钉_拧紧时间", "DB1017.DBD3250" }, // Real + { "5号螺钉_结果", "DB1001.DBW3236" }, // Int + { "5号螺钉_扭矩", "DB1001.DBD3238" }, // Real + { "5号螺钉_深度", "DB1001.DBD3242" }, // Real + { "5号螺钉_角度", "DB1001.DBD3246" }, // Real + { "5号螺钉_拧紧时间", "DB1001.DBD3250" }, // Real // 6号螺钉 - { "6号螺钉_结果", "DB1017.DBW3254" }, // Int - { "6号螺钉_扭矩", "DB1017.DBD3256" }, // Real - { "6号螺钉_深度", "DB1017.DBD3260" }, // Real - { "6号螺钉_角度", "DB1017.DBD3264" }, // Real - { "6号螺钉_拧紧时间", "DB1017.DBD3268" }, // Real + { "6号螺钉_结果", "DB1001.DBW3254" }, // Int + { "6号螺钉_扭矩", "DB1001.DBD3256" }, // Real + { "6号螺钉_深度", "DB1001.DBD3260" }, // Real + { "6号螺钉_角度", "DB1001.DBD3264" }, // Real + { "6号螺钉_拧紧时间", "DB1001.DBD3268" }, // Real // 7号螺钉 - { "7号螺钉_结果", "DB1017.DBW3272" }, // Int - { "7号螺钉_扭矩", "DB1017.DBD3274" }, // Real - { "7号螺钉_深度", "DB1017.DBD3278" }, // Real - { "7号螺钉_角度", "DB1017.DBD3282" }, // Real - { "7号螺钉_拧紧时间", "DB1017.DBD3286" }, // Real + { "7号螺钉_结果", "DB1001.DBW3272" }, // Int + { "7号螺钉_扭矩", "DB1001.DBD3274" }, // Real + { "7号螺钉_深度", "DB1001.DBD3278" }, // Real + { "7号螺钉_角度", "DB1001.DBD3282" }, // Real + { "7号螺钉_拧紧时间", "DB1001.DBD3286" }, // Real }; // OP080-2 专属地址映射(PCBA拧紧工位,DB1001) @@ -624,23 +661,23 @@ namespace RIZO.Admin.WebApi.PLC.Service private readonly Dictionary _op085IntMap = new() { // 基础状态 - { "运行状态", "DB1030.DBW0" }, // Int - 1=空闲,2=运行中,3=故障 - { "设备模式", "DB1030.DBW2" }, // Int - 1=空模式;2=手动;4=初始化;8=自动;16=CycleStop - { "设备在线状态", "DB1030.DBW4" }, // Int - 1=离线,0=在线 - { "ByPass", "DB1030.DBW6" }, // Int - 1=ByPass,0=正常模式 - { "生产模式", "DB1030.DBW8" }, // Int - 1=点检,2=返工,4=样件,5=正常 + { "运行状态", "DB1001.DBW0" }, // Int - 1=空闲,2=运行中,3=故障 + { "设备模式", "DB1001.DBW2" }, // Int - 1=空模式;2=手动;4=初始化;8=自动;16=CycleStop + { "设备在线状态", "DB1001.DBW4" }, // Int - 1=离线,0=在线 + { "ByPass", "DB1001.DBW6" }, // Int - 1=ByPass,0=正常模式 + { "生产模式", "DB1001.DBW8" }, // Int - 1=点检,2=返工,4=样件,5=正常 // 产量数据 - { "实际产量", "DB1030.DBD1104" }, // DInt - { "合格数量", "DB1030.DBD1108" }, // DInt - { "失败数量", "DB1030.DBD1112" }, // DInt + { "实际产量", "DB1001.DBD1104" }, // DInt + { "合格数量", "DB1001.DBD1108" }, // DInt + { "失败数量", "DB1001.DBD1112" }, // DInt // 操作请求 - { "保存请求", "DB1030.DBW2002" }, // Int - 1=请求开始,0=无请求 - { "线体托盘号", "DB1030.DBW2070" }, // Int + { "保存请求", "DB1001.DBW2002" }, // Int - 1=请求开始,0=无请求 + { "线体托盘号", "DB1001.DBW2070" }, // Int // 工艺参数 - { "节拍时间", "DB1030.DBD2242" } // Real + { "节拍时间", "DB1001.DBD2242" } // Real }; // OP100 专属地址映射(手动上料壳体&盖板工位,DB1001) @@ -1509,50 +1546,83 @@ namespace RIZO.Admin.WebApi.PLC.Service return null; } } - /// - /// 读取OP020-3数据(热铆工位) + /// OP020-3 数据读取(热铆工位,DB1001)- 按OP020-4风格优化 /// - private async Task ReadOP020_3DataAsync(Plc plc, string ip, string workstationCode) + private async Task ReadOP020_3DataAsync(Plc plc, string ip, string workstationCode) { - // 前置核心校验:避免无效PLC操作 + // 前置校验:PLC连接无效直接返回,与OP020-4风格保持一致 if (plc == null || !plc.IsConnected) { - Console.WriteLine($"OP020-3({ip})PLC连接无效,跳过数据读取"); return null; } try { - // 1. 真正的并行读取所有Int字段(核心效率优化) - // 步骤1:创建所有异步读取任务(仅发起请求,不等待) - var taskRunStatus = ReadPlcIntAsync(plc, _op020_3IntMap["运行状态"]); - var taskMachineModel = ReadPlcIntAsync(plc, _op020_3IntMap["设备模式"]); - var taskOnlineStatus = ReadPlcIntAsync(plc, _op020_3IntMap["设备在线状态"]); - var taskProduceModel = ReadPlcIntAsync(plc, _op020_3IntMap["生产模式"]); + // 1. 批量创建并行读取任务(字典存储,最大化并行效率,减少临时变量开销) + // 字符串读取任务(匹配_op020_3StringMap所有字段) + var stringReadTasks = new Dictionary> + { + { "产品型号", ReadPlcStringAsync(plc, _op020_3StringMap["产品型号"].Addr, _op020_3StringMap["产品型号"].Len) }, + { "产品1SN", ReadPlcStringAsync(plc, _op020_3StringMap["产品1SN"].Addr, _op020_3StringMap["产品1SN"].Len) }, + { "产品2SN", ReadPlcStringAsync(plc, _op020_3StringMap["产品2SN"].Addr, _op020_3StringMap["产品2SN"].Len) }, + { "产品3SN", ReadPlcStringAsync(plc, _op020_3StringMap["产品3SN"].Addr, _op020_3StringMap["产品3SN"].Len) }, + { "产品4SN", ReadPlcStringAsync(plc, _op020_3StringMap["产品4SN"].Addr, _op020_3StringMap["产品4SN"].Len) } + }; - // DInt任务(单独提取,避免字典开销) - var taskActualOutput = ReadPlcIntAsync(plc, _op050IntMap["实际产量"]); - var taskQualifiedQty = ReadPlcIntAsync(plc, _op050IntMap["合格数量"]); - var taskFailedQty = ReadPlcIntAsync(plc, _op050IntMap["失败数量"]); + // Int读取任务(匹配_op020_3IntMap基础状态/请求/托盘号字段) + var intReadTasks = new Dictionary> + { + { "运行状态", ReadPlcIntAsync(plc, _op020_3IntMap["运行状态"]) }, + { "设备模式", ReadPlcIntAsync(plc, _op020_3IntMap["设备模式"]) }, + { "设备在线状态", ReadPlcIntAsync(plc, _op020_3IntMap["设备在线状态"]) }, + { "ByPass", ReadPlcIntAsync(plc, _op020_3IntMap["ByPass"]) }, + { "生产模式", ReadPlcIntAsync(plc, _op020_3IntMap["生产模式"]) }, + { "查询请求", ReadPlcIntAsync(plc, _op020_3IntMap["查询请求"]) }, + { "上传请求", ReadPlcIntAsync(plc, _op020_3IntMap["上传请求"]) }, + { "托盘号", ReadPlcIntAsync(plc, _op020_3IntMap["托盘号"]) } + }; - // 步骤2:等待所有任务并行完成(耗时=最慢的单个读取任务,而非总和) - await Task.WhenAll(taskRunStatus, taskMachineModel, taskOnlineStatus, taskProduceModel, taskActualOutput, taskQualifiedQty, taskFailedQty); + // DInt/Real读取任务(产量+节拍时间,复用ReadPlcIntAsync兼容转换,与OP020-4风格一致) + var dIntRealReadTasks = new Dictionary> + { + { "节拍时间", ReadPlcIntAsync(plc, _op020_3IntMap["节拍时间"]) }, + { "合格数量", ReadPlcIntAsync(plc, _op020_3IntMap["合格数量"]) }, + { "失败数量", ReadPlcIntAsync(plc, _op020_3IntMap["失败数量"]) }, + { "实际数量", ReadPlcIntAsync(plc, _op020_3IntMap["实际数量"]) } + }; - // 步骤3:获取结果(带await确保值已返回,无需额外判空) - int runStatus = await taskRunStatus; - int machineModel = await taskMachineModel; - int onlineStatus = await taskOnlineStatus; - int produceModel = await taskProduceModel; + // 2. 并行等待所有读取任务完成(合并任务列表,单次WaitAll提升效率,添加ConfigureAwait(false)优化异步) + var allTasks = new List(); + allTasks.AddRange(stringReadTasks.Values); + allTasks.AddRange(intReadTasks.Values); + allTasks.AddRange(dIntRealReadTasks.Values); + await Task.WhenAll(allTasks).ConfigureAwait(false); - int actualOutput = await taskActualOutput; - int qualifiedQty = await taskQualifiedQty; - int failedQty = await taskFailedQty; + // 3. 提取读取结果(直接取值+空值兜底,减少await重复调用,与OP020-4风格一致) + // 字符串字段 + string productModel = stringReadTasks["产品型号"].Result ?? string.Empty; + string product1SN = stringReadTasks["产品1SN"].Result ?? string.Empty; + string product2SN = stringReadTasks["产品2SN"].Result ?? string.Empty; + string product3SN = stringReadTasks["产品3SN"].Result ?? string.Empty; + string product4SN = stringReadTasks["产品4SN"].Result ?? string.Empty; - // 2. 业务逻辑计算(优化:常量复用+减少冗余计算) - var reworkFlag = produceModel == 4 ? "1" : "0"; + // 整数字段 + int runStatus = intReadTasks["运行状态"].Result; + int machineModel = intReadTasks["设备模式"].Result; + int onlineStatus = intReadTasks["设备在线状态"].Result; + int byPass = intReadTasks["ByPass"].Result; + int produceModel = intReadTasks["生产模式"].Result; + int trayNo = intReadTasks["托盘号"].Result; - // 预定义常量减少字符串创建(高频场景累计收益) + // DInt/Real转换结果 + int cycleTime = dIntRealReadTasks["节拍时间"].Result; + int qualifiedQty = dIntRealReadTasks["合格数量"].Result; + int failedQty = dIntRealReadTasks["失败数量"].Result; + int actualOutput = dIntRealReadTasks["实际数量"].Result; + + // 4. 业务逻辑转换(极简逻辑,仅保留必要转换,与OP020-4风格对齐) + string reworkFlag = produceModel == 4 ? "1" : "0"; string produceModelDesc = produceModel switch { 1 => "正常模式", @@ -1560,53 +1630,55 @@ namespace RIZO.Admin.WebApi.PLC.Service 4 => "返工模式", 8 => "换型模式", 16 => "预热模式", - _ => $"未知({produceModel})" + _ => produceModel.ToString() }; - - string runStatusDesc = runStatus switch - { - 1 => "空闲", - 2 => "运行中", - 3 => "故障", - _ => $"未知({runStatus})" - }; - string onlineStatusDesc = onlineStatus == 1 ? "离线" : "在线"; + // OP020-3无产品结果字段,默认合格(与原有逻辑保持一致) + string qualificationFlag = "1"; - // 调试日志(优化:减少字符串拼接开销,保留核心信息) - Console.WriteLine($"OP020-3({ip})读取结果:运行状态={runStatusDesc},生产模式={produceModelDesc}"); - - // 3. 构建数据实体(优化:减少冗余操作,提前兜底) + // 5. 构建实体(精准匹配PlcProductionData字段,无冗余,补充OP020-3独有信息) return new PlcProductionData { - // 基础字段:ip外层已校验非空,无需Trim(减少字符串操作) PlcIp = ip, OccurTime = DateTime.Now, LineCode = "line2", WorkstationCode = workstationCode, - WorkstationName = "热铆", // 补充工站名称 - ActualOutQty = actualOutput.ToString(), - QualifiedQty = qualifiedQty.ToString(), - FailedQty = failedQty.ToString(), + WorkstationName = "热铆工位", // 补充工站名称,与OP020-4对齐 + ProductModel = productModel, + ProductName = string.Empty, // OP020-3无产品名字段,置空 + ProductCode = product1SN, // 主产品编码取产品1SN,与OP020-4对齐 ReworkFlag = reworkFlag, Automanual = machineModel, Runstatus = runStatus, OnlineStatus = onlineStatusDesc, ProduceModel = produceModelDesc, - - // 系统字段:固定值直接赋值 + TrayNo = trayNo.ToString(), CreatedBy = "PLC", - CreatedTime = DateTime.Now + CreatedTime = DateTime.Now, + Product1SN = product1SN, + Product2SN = product2SN, + Product3SN = product3SN, + Product4SN = product4SN, + SN1 = product1SN, + SN2 = product2SN, + ActualOutQty = actualOutput.ToString(), + QualifiedQty = qualifiedQty.ToString(), + FailedQty = failedQty.ToString(), + // 补充节拍时间和报警信息 + ProductionCycle = cycleTime, + // 合格标识 + QualificationFlag = qualificationFlag }; } - catch (Exception ex) + catch { - // 增强异常日志:包含堆栈,便于定位问题(不影响效率,提升可维护性) - Console.WriteLine($"OP020-3({ip})数据读取异常:{ex.Message}\n{ex.StackTrace}"); + // 异常直接返回null,与OP020-4风格保持一致 return null; } } + + /// /// 读取OP020-4数据(pin压合&视觉检查工位) /// @@ -5524,18 +5596,36 @@ namespace RIZO.Admin.WebApi.PLC.Service { try { - WritePlcValue(plc, _mesIntReturnMap["设备使能"], "1"); - //WritePlcValue(plc, _mesIntReturnMap["工位开始查询结果"], "1"); - WritePlcValue(plc, _mesIntReturnMap["保存结果"], saveResult); - if (prodData.ProductModel != null && prodData.ProductModel.Length > 0) + if (plcName == "OP058") { - WritePlcString(plc, _mesStringReturnMap["产品型号"].Addr, _mesStringReturnMap["产品型号"].Len, prodData.ProductModel); + 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 { - WritePlcString(plc, _mesStringReturnMap["产品型号"].Addr, _mesStringReturnMap["产品型号"].Len, prodData.ProductModel); + 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"); } - WritePlcString(plc, _mesStringReturnMap["订单下发"].Addr, _mesStringReturnMap["订单下发"].Len, "cpxhtest"); } catch (Exception ex) {