using 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;
namespace WIDESEA_WCS.WCSClient
{
public class DBExtension
{
///
///
///
/// 设备信息地址
///
///
///
public static object Read(dt_plcinfodetail detail, PLCClient client)
{
if (detail.plcdetail_valtype == typeof(int).Name.ToLower())//4字节,有符号类型
{
return (client.Read(detail.plcdetail_db + "." + detail.plcdetail_value));
}
else if (detail.plcdetail_valtype == typeof(uint).Name.ToLower())//4字节,无符号类型
{
return (client.Read(detail.plcdetail_db + "." + detail.plcdetail_value));
}
else if (detail.plcdetail_valtype == typeof(short).Name.ToLower())//2字节,有符号类型,最常用
{
return (client.Read(detail.plcdetail_db + "." + detail.plcdetail_value));
}
else if (detail.plcdetail_valtype == typeof(ushort).Name.ToLower())//2字节,无符号类型
{
return (client.Read(detail.plcdetail_db + "." + detail.plcdetail_value));
}
else if (detail.plcdetail_valtype == typeof(float).Name.ToLower())//浮点型
{
return (client.Read(detail.plcdetail_db + "." + detail.plcdetail_value));
}
else if (detail.plcdetail_valtype == typeof(bool).Name.ToLower())
{
return (client.Read(detail.plcdetail_db + "." + detail.plcdetail_value));
}
else if (detail.plcdetail_valtype == typeof(byte).Name.ToLower())//字节
{
return (client.Read(detail.plcdetail_db + "." + detail.plcdetail_value));
}
else if (detail.plcdetail_valtype == typeof(string).Name.ToLower())//字符串
{
return (client.Read(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}");
}
}
///
///
///
///
///
///
///
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(itemGroup.dbAddress));
}
else if (itemGroup.dataType == typeof(uint).Name.ToLower())//4字节,无符号类型
{
return (client.Read(itemGroup.dbAddress));
}
else if (itemGroup.dataType == typeof(short).Name.ToLower())//2字节,有符号类型,最常用
{
return (client.Read(itemGroup.dbAddress));
}
else if (itemGroup.dataType == typeof(ushort).Name.ToLower())//2字节,无符号类型
{
return (client.Read(itemGroup.dbAddress));
}
else if (itemGroup.dataType == typeof(float).Name.ToLower())//浮点型
{
return (client.Read(itemGroup.dbAddress));
}
else if (itemGroup.dataType == typeof(bool).Name.ToLower())
{
return (client.Read(itemGroup.dbAddress));
}
else if (itemGroup.dataType == typeof(byte).Name.ToLower())//字节
{
return (client.Read(itemGroup.dbAddress));
}
else if (itemGroup.dataType == typeof(string).Name.ToLower())//字符串
{
return (client.Read(itemGroup.dbAddress, itemGroup.dataLen.GetValueOrDefault()));
}
else
{
throw new Exception($"【{itemGroup.name}】,DB地址{itemGroup.dbAddress},未定义数据类型{itemGroup.dataType}");
}
}
}
}
}