分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-01-31 50fd5cc9cfad08714c4daa6d481c5293ff2ae6b1
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/WCSClient/DBExtension.cs
@@ -1,4 +1,5 @@
using System;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -18,43 +19,62 @@
        /// <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;
            }
        }
    }
}