| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Entity.DomainModels; |
| | |
| | | /// <param name="client"></param> |
| | | /// <param name="value"></param> |
| | | /// <returns></returns> |
| | | public static object Write(dt_plcinfodetail detail, PLCClient client, object value) |
| | | public static object Read(DBItemGroup itemGroup, PLCClient client) |
| | | { |
| | | try |
| | | //PLCClient client = PLCClient.Clients.Where(x => x.PLCName == itemGroup.name).FirstOrDefault(); |
| | | if (client == null) |
| | | { |
| | | return (client.Write(detail.plcdetail_db + "." + detail.plcdetail_value, value)); |
| | | throw new Exception($"æªæ¾å°{itemGroup.name}è¿æ¥å¯¹è±¡"); |
| | | } |
| | | catch (Exception ex) |
| | | else |
| | | { |
| | | throw; |
| | | if (itemGroup.dataType == typeof(int).Name.ToLower())//4åè,æç¬¦å·ç±»å |
| | | { |
| | | return (client.Read<int>(itemGroup.dbAddress)); |
| | | } |
| | | else if (itemGroup.dataType == typeof(uint).Name.ToLower())//4åè,æ 符å·ç±»å |
| | | { |
| | | return (client.Read<uint>(itemGroup.dbAddress)); |
| | | } |
| | | else if (itemGroup.dataType == typeof(short).Name.ToLower())//2åè,æç¬¦å·ç±»å,æå¸¸ç¨ |
| | | { |
| | | return (client.Read<short>(itemGroup.dbAddress)); |
| | | } |
| | | else if (itemGroup.dataType == typeof(ushort).Name.ToLower())//2åè,æ 符å·ç±»å |
| | | { |
| | | return (client.Read<ushort>(itemGroup.dbAddress)); |
| | | } |
| | | else if (itemGroup.dataType == typeof(float).Name.ToLower())//æµ®ç¹å |
| | | { |
| | | return (client.Read<float>(itemGroup.dbAddress)); |
| | | } |
| | | else if (itemGroup.dataType == typeof(bool).Name.ToLower()) |
| | | { |
| | | return (client.Read<bool>(itemGroup.dbAddress)); |
| | | } |
| | | else if (itemGroup.dataType == typeof(byte).Name.ToLower())//åè |
| | | { |
| | | return (client.Read<byte>(itemGroup.dbAddress)); |
| | | } |
| | | else if (itemGroup.dataType == typeof(string).Name.ToLower())//å符串 |
| | | { |
| | | return (client.Read<string>(itemGroup.dbAddress, itemGroup.dataLen.GetValueOrDefault())); |
| | | } |
| | | else |
| | | { |
| | | throw new Exception($"ã{itemGroup.name}ã,DBå°å{itemGroup.dbAddress},æªå®ä¹æ°æ®ç±»å{itemGroup.dataType}"); |
| | | } |
| | | } |
| | | } |
| | | } |