diff --git a/RIZO.Admin.WebApi/PLC/Service/PlcService.cs b/RIZO.Admin.WebApi/PLC/Service/PlcService.cs index 0bb2461..01a60e2 100644 --- a/RIZO.Admin.WebApi/PLC/Service/PlcService.cs +++ b/RIZO.Admin.WebApi/PLC/Service/PlcService.cs @@ -41,8 +41,8 @@ namespace RIZO.Admin.WebApi.PLC.Service // OP070-1 专属地址映射 private readonly Dictionary _op070_1StringMap = new() { - { "报警信息", ("DB1001.DBB58", 48) }, // Array[1..48] of Byte - //{ "产品型号", ("DB1001.DBB1000", 48) }, // String[48] + //{ "报警信息", ("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] @@ -68,7 +68,76 @@ namespace RIZO.Admin.WebApi.PLC.Service }; // OP080-1 专属地址映射 + private readonly Dictionary _op080_1StringMap = new() + { + //{ "报警信息", ("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() + { + { "运行状态", "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.DBW2004" }, // Int + { "合装位托盘号", "DB1001.DBW2100" }, // Int + { "拧紧位托盘号", "DB1001.DBW3152" }, // Int + // 2号螺钉 + { "2号螺钉_结果", "DB1001.DBW3164" }, // Int + { "2号螺钉_扭矩", "DB1001.DBD3166" }, // Real + { "2号螺钉_深度", "DB1001.DBD3170" }, // Real + { "2号螺钉_角度", "DB1001.DBD3174" }, // Real + { "2号螺钉_拧紧时间", "DB1001.DBD3178" }, // Real + // 3号螺钉 + { "3号螺钉_结果", "DB1001.DBW3182" }, // Int + { "3号螺钉_扭矩", "DB1001.DBD3184" }, // Real + { "3号螺钉_深度", "DB1001.DBD3188" }, // Real + { "3号螺钉_角度", "DB1001.DBD3192" }, // Real + { "3号螺钉_拧紧时间", "DB1001.DBD3196" }, // Real + // 4号螺钉 + { "4号螺钉_结果", "DB1001.DBW3200" }, // Int + { "4号螺钉_扭矩", "DB1001.DBD3202" }, // Real + { "4号螺钉_深度", "DB1001.DBD3206" }, // Real + { "4号螺钉_角度", "DB1001.DBD3210" }, // Real + { "4号螺钉_拧紧时间", "DB1001.DBD3214" }, // Real + // 1号螺钉 + { "1号螺钉_结果", "DB1001.DBW3218" }, // Int + { "1号螺钉_扭矩", "DB1001.DBD3220" }, // Real + { "1号螺钉_深度", "DB1001.DBD3224" }, // Real + { "1号螺钉_角度", "DB1001.DBD3228" }, // Real + { "1号螺钉_拧紧时间", "DB1001.DBD3232" }, // Real + // 5号螺钉 + { "5号螺钉_结果", "DB1001.DBW3236" }, // Int + { "5号螺钉_扭矩", "DB1001.DBD3238" }, // Real + { "5号螺钉_深度", "DB1001.DBD3242" }, // Real + { "5号螺钉_角度", "DB1001.DBD3246" }, // Real + { "5号螺钉_拧紧时间", "DB1001.DBD3250" }, // Real + // 6号螺钉 + { "6号螺钉_结果", "DB1001.DBW3254" }, // Int + { "6号螺钉_扭矩", "DB1001.DBD3256" }, // Real + { "6号螺钉_深度", "DB1001.DBD3260" }, // Real + { "6号螺钉_角度", "DB1001.DBD3264" }, // Real + { "6号螺钉_拧紧时间", "DB1001.DBD3268" }, // Real + // 7号螺钉 + { "7号螺钉_结果", "DB1001.DBW3272" }, // Int + { "7号螺钉_扭矩", "DB1001.DBD3274" }, // Real + { "7号螺钉_深度", "DB1001.DBD3278" }, // Real + { "7号螺钉_角度", "DB1001.DBD3282" }, // Real + { "7号螺钉_拧紧时间", "DB1001.DBD3286" }, // Real + }; #endregion /// @@ -393,80 +462,9 @@ namespace RIZO.Admin.WebApi.PLC.Service } } - #region 工位专属读取方法(扩展友好,逻辑隔离) + #region 工位专属读取方法 /// - /// OP070-1专属数据读取(精简版:高效+易读) - /// - //private async Task ReadOP070_1DataAsync(Plc plc, string ip) - //{ - // // 1. 批量并行读取字符串字段 - // // 合并并行读取 - // var (strFields, intFields) = await Task.Run(async () => ( - // // 字符串字段 - // ( - // await ReadPlcStringAsync(plc, _op070_1StringMap["报警信息"].Addr, _op070_1StringMap["报警信息"].Len), - // await ReadPlcStringAsync(plc, _op070_1StringMap["产品名称"].Addr, _op070_1StringMap["产品名称"].Len), - // await ReadPlcStringAsync(plc, _op070_1StringMap["产品型号"].Addr, _op070_1StringMap["产品型号"].Len), - // await ReadPlcStringAsync(plc, _op070_1StringMap["SN_1"].Addr, _op070_1StringMap["SN_1"].Len), - // await ReadPlcStringAsync(plc, _op070_1StringMap["SN_2"].Addr, _op070_1StringMap["SN_2"].Len) - // ), - // // 整数字段 - // ( - // await ReadPlcIntAsync(plc, _op070_1IntMap["运行状态"]), - // await ReadPlcIntAsync(plc, _op070_1IntMap["设备模式"]), - // await ReadPlcIntAsync(plc, _op070_1IntMap["设备在线状态"]), - // await ReadPlcIntAsync(plc, _op070_1IntMap["ByPass"]), - // await ReadPlcIntAsync(plc, _op070_1IntMap["生产模式"]), - // await ReadPlcIntAsync(plc, _op070_1IntMap["托盘号"]), - // await ReadPlcIntAsync(plc, _op070_1IntMap["站位结果"]) - // ) - // )); - - // // 2.解构字段(保持原有逻辑) - // var (alarmMsg, productName, product_model, sn1, product_code) = strFields; - // var (runStatus, machineModel, onlineStatus, byPass, produceModel, trayNo, stationResult) = intFields; - - // // 3. 写入保存请求(极简异常防护,不影响主流程) - // try { WritePlcValue(plc, _op070_1IntMap["保存请求"], "1"); } - // catch (Exception ex) { Console.WriteLine($"OP070-1({ip})写保存请求失败:{ex.Message}"); } - - // // 4. 极简条件计算(一行搞定,易读高效) - // var reworkFlag = produceModel == 4 ? "1" : "0"; // 返工标志 - // string produceModelDesc = produceModel switch // 生产模式映射 - // { - // 1 => "正常模式", - // 2 => "清线模式", - // 4 => "返工模式", - // 8 => "换型模式", - // 16 => "预热模式", - // _ => $"未知({produceModel})" - // }; - - // // 5. 构建数据实体(极简空值兜底,逻辑清晰) - // return new PlcProductionData - // { - // //加一个产品型号 - // PlcIp = ip.Trim(), - // OccurTime = DateTime.Now, - // LineCode = "line2", - // WorkstationCode = "OP070-1", - // ProductModel = product_model ?? "", - // ProductName = productName ?? "", - // ProductCode = product_code, - // QualificationFlag = stationResult.ToString(), - // ReworkFlag = reworkFlag, - // AutoManual = machineModel, - // RunStatus = runStatus, - // OnlineStatus = onlineStatus.ToString(), - // TrayNo = trayNo.ToString(), - // ProduceModel = produceModelDesc, - // CreatedBy = "PLC", - // CreatedTime = DateTime.Now - // }; - //} - - /// - /// 优化版OP070-1数据读取(集成增强型PLC读写方法) + /// OP070-1数据读取 /// private async Task ReadOP070_1DataAsync(Plc plc, string ip,string workstationCode) { @@ -474,9 +472,9 @@ namespace RIZO.Admin.WebApi.PLC.Service var (strFields, intFields, realFields) = await Task.Run(async () => ( // 字符串字段(增强空值和异常处理) ( - await ReadPlcStringAsync(plc, _op070_1StringMap["报警信息"].Addr, _op070_1StringMap["报警信息"].Len), + //await ReadPlcStringAsync(plc, _op070_1StringMap["报警信息"].Addr, _op070_1StringMap["报警信息"].Len), await ReadPlcStringAsync(plc, _op070_1StringMap["产品名称"].Addr, _op070_1StringMap["产品名称"].Len), - //await ReadPlcStringAsync(plc, _op070_1StringMap["产品型号"].Addr, _op070_1StringMap["产品型号"].Len), + await ReadPlcStringAsync(plc, _op070_1StringMap["订单名称"].Addr, _op070_1StringMap["订单名称"].Len), await ReadPlcStringAsync(plc, _op070_1StringMap["产品型号"].Addr, _op070_1StringMap["产品型号"].Len), await ReadPlcStringAsync(plc, _op070_1StringMap["SN_1"].Addr, _op070_1StringMap["SN_1"].Len), await ReadPlcStringAsync(plc, _op070_1StringMap["SN_2"].Addr, _op070_1StringMap["SN_2"].Len) @@ -507,7 +505,7 @@ namespace RIZO.Admin.WebApi.PLC.Service )); // 2. 解构字段(保持原有逻辑,空值兜底) - var (alarmMsg, productName, productModel, sn1, sn2) = strFields; + var (productName,orderName, productModel, sn1, sn2) = strFields; var (runStatus, machineModel, onlineStatus, byPass, produceModel, queryReq, saveReq, trayNo, cameraResult, stationResult) = intFields; //var (actualOutput, qualifiedQty, failedQty) = dintFields; float cycleTime = realFields; @@ -534,7 +532,7 @@ namespace RIZO.Admin.WebApi.PLC.Service string cameraResultDesc = cameraResult switch { 1 => "OK", 2 => "NG", _ => $"未知({cameraResult})" }; // 调试日志:输出关键读取结果 - Console.WriteLine($"OP070-1({ip})读取结果:产品型号={productModel},运行状态={runStatusDesc}"); + Console.WriteLine($"OP070-1({ip})读取结果:产品型号={productModel},运行状态={runStatusDesc},订单名称={orderName}"); // 5. 构建数据实体(增强空值处理) return new PlcProductionData