From a765da90e5ee63e04d2d8460a5ad1ebd0e8eb4db Mon Sep 17 00:00:00 2001 From: huanghongfeng <huanghongfeng@hnkhzn.com> Date: 星期一, 15 七月 2024 21:43:59 +0800 Subject: [PATCH] 工单处理 --- 代码管理/PCS/WCS_Server/WIDESEA_WCS/WCSClient/DBExtension.cs | 95 ++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 76 insertions(+), 19 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/DBExtension.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/DBExtension.cs" index 753da87..6da6b16 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/DBExtension.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/WCSClient/DBExtension.cs" @@ -1,6 +1,8 @@ -锘縰sing System; +锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using WIDESEA_Entity.DomainModels; @@ -18,43 +20,98 @@ /// <exception cref="Exception"></exception> public static object Read(dt_plcinfodetail detail, PLCClient client) { - - if (detail.plcdetail_valtype == typeof(int).Name.ToLower())//4瀛楄妭,鏈夌鍙风被鍨� + + if (detail.plcdetail_valtype == typeof(int).Name.ToLower())//4瀛楄妭,鏈夌鍙风被鍨� + { + return (client.Read<int>(detail.plcdetail_db + "." + detail.plcdetail_value)); + } + else if (detail.plcdetail_valtype == typeof(uint).Name.ToLower())//4瀛楄妭,鏃犵鍙风被鍨� + { + return (client.Read<uint>(detail.plcdetail_db + "." + detail.plcdetail_value)); + } + else if (detail.plcdetail_valtype == typeof(short).Name.ToLower())//2瀛楄妭,鏈夌鍙风被鍨�,鏈�甯哥敤 + { + return (client.Read<short>(detail.plcdetail_db + "." + detail.plcdetail_value)); + } + else if (detail.plcdetail_valtype == typeof(ushort).Name.ToLower())//2瀛楄妭,鏃犵鍙风被鍨� + { + return (client.Read<ushort>(detail.plcdetail_db + "." + detail.plcdetail_value)); + } + else if (detail.plcdetail_valtype == typeof(float).Name.ToLower())//娴偣鍨� + { + return (client.Read<float>(detail.plcdetail_db + "." + detail.plcdetail_value)); + } + else if (detail.plcdetail_valtype == typeof(bool).Name.ToLower()) + { + return (client.Read<bool>(detail.plcdetail_db + "." + detail.plcdetail_value)); + } + else if (detail.plcdetail_valtype == typeof(byte).Name.ToLower())//瀛楄妭 + { + return (client.Read<byte>(detail.plcdetail_db + "." + detail.plcdetail_value)); + } + else if (detail.plcdetail_valtype == typeof(string).Name.ToLower())//瀛楃涓� + { + return (client.Read<string>(detail.plcdetail_db + "." + detail.plcdetail_value, detail.plcdetail_len.GetValueOrDefault())); + } + else + { + throw new Exception($"銆恵detail.plcdetail_remark}銆�,DB鍦板潃{detail.plcdetail_db + "." + detail.plcdetail_value},鏈畾涔夋暟鎹被鍨媨detail.plcdetail_valtype}"); + } + } + + /// <summary> + /// + /// </summary> + /// <param name="detail"></param> + /// <param name="client"></param> + /// <param name="value"></param> + /// <returns></returns> + public static object Read(DBItemGroup itemGroup, PLCClient client) + { + //PLCClient client = PLCClient.Clients.Where(x => x.PLCName == itemGroup.name).FirstOrDefault(); + if (client == null) + { + throw new Exception($"鏈壘鍒皗itemGroup.name}杩炴帴瀵硅薄"); + } + else + { + if (itemGroup.dataType == typeof(int).Name.ToLower())//4瀛楄妭,鏈夌鍙风被鍨� { - return (client.Read<int>(detail.plcdetail_db+"."+detail.plcdetail_value)); + return (client.Read<int>(itemGroup.dbAddress)); } - else if (detail.plcdetail_valtype == typeof(uint).Name.ToLower())//4瀛楄妭,鏃犵鍙风被鍨� + else if (itemGroup.dataType == typeof(uint).Name.ToLower())//4瀛楄妭,鏃犵鍙风被鍨� { - return (client.Read<uint>(detail.plcdetail_db + "." + detail.plcdetail_value)); + return (client.Read<uint>(itemGroup.dbAddress)); } - else if (detail.plcdetail_valtype == typeof(short).Name.ToLower())//2瀛楄妭,鏈夌鍙风被鍨�,鏈�甯哥敤 + else if (itemGroup.dataType == typeof(short).Name.ToLower())//2瀛楄妭,鏈夌鍙风被鍨�,鏈�甯哥敤 { - return (client.Read<short>(detail.plcdetail_db + "." + detail.plcdetail_value)); + return (client.Read<short>(itemGroup.dbAddress)); } - else if (detail.plcdetail_valtype == typeof(ushort).Name.ToLower())//2瀛楄妭,鏃犵鍙风被鍨� + else if (itemGroup.dataType == typeof(ushort).Name.ToLower())//2瀛楄妭,鏃犵鍙风被鍨� { - return (client.Read<ushort>(detail.plcdetail_db + "." + detail.plcdetail_value)); + return (client.Read<ushort>(itemGroup.dbAddress)); } - else if (detail.plcdetail_valtype == typeof(float).Name.ToLower())//娴偣鍨� + else if (itemGroup.dataType == typeof(float).Name.ToLower())//娴偣鍨� { - return (client.Read<float>(detail.plcdetail_db + "." + detail.plcdetail_value)); + return (client.Read<float>(itemGroup.dbAddress)); } - else if (detail.plcdetail_valtype == typeof(bool).Name.ToLower()) + else if (itemGroup.dataType == typeof(bool).Name.ToLower()) { - return (client.Read<bool>(detail.plcdetail_db + "." + detail.plcdetail_value)); + return (client.Read<bool>(itemGroup.dbAddress)); } - else if (detail.plcdetail_valtype == typeof(byte).Name.ToLower())//瀛楄妭 + else if (itemGroup.dataType == typeof(byte).Name.ToLower())//瀛楄妭 { - return (client.Read<byte>(detail.plcdetail_db + "." + detail.plcdetail_value)); + return (client.Read<byte>(itemGroup.dbAddress)); } - else if (detail.plcdetail_valtype == typeof(string).Name.ToLower())//瀛楃涓� + else if (itemGroup.dataType == typeof(string).Name.ToLower())//瀛楃涓� { - return (client.Read<string>(detail.plcdetail_db + "." + detail.plcdetail_value, detail.plcdetail_len.GetValueOrDefault())); + return (client.Read<string>(itemGroup.dbAddress, itemGroup.dataLen.GetValueOrDefault())); } else { - throw new Exception($"銆恵detail.plcdetail_remark}銆�,DB鍦板潃{detail.plcdetail_db + "." + detail.plcdetail_value},鏈畾涔夋暟鎹被鍨媨detail.plcdetail_valtype}"); + throw new Exception($"銆恵itemGroup.name}銆�,DB鍦板潃{itemGroup.dbAddress},鏈畾涔夋暟鎹被鍨媨itemGroup.dataType}"); } + } } } } -- Gitblit v1.9.3