| | |
| | | using System; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | |
| | | /// <exception cref="Exception"></exception> |
| | | public static object Read(dt_plcinfodetail detail, PLCClient client) |
| | | { |
| | | |
| | | 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}"); |
| | | } |
| | | |
| | | 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 Write(dt_plcinfodetail detail, PLCClient client, object value) |
| | | { |
| | | try |
| | | { |
| | | return (client.Write(detail.plcdetail_db + "." + detail.plcdetail_value, value)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw; |
| | | } |
| | | } |
| | | } |
| | | } |