#region << 版 本 注 释 >>
/*----------------------------------------------------------------
* 命名空间:WIDESEAWCS_Communicator
* 创建者:胡童庆
* 创建时间:2024/8/2 16:13:36
* 版本:V1.0.0
* 描述:西门子PLC的数据类型
*
* ----------------------------------------------------------------
* 修改人:
* 修改时间:
* 版本:V1.0.1
* 修改说明:
*
*----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace WIDESEAWCS_Communicator
{
///
/// 西门子PLC的数据类型
///
public class SiemensDBDataType
{
#region
///
/// 32位有符号整型
///
public const string DataType_DInt = "dint";
///
/// 布尔
///
public const string DataType_Bool = "bool";
///
/// 字符串
///
public const string DataType_String = "string";
///
/// 16位有符号整型
///
public const string DataType_Int = "int";
///
/// 字节
///
public const string DataType_Byte = "byte";
///
/// 32位无符号整型
///
public const string DataType_DW = "dw";
///
/// 16位无符号整型
///
public const string DataType_W = "w";
///
/// 浮点型
///
public const string DataType_Float = "float";
///
/// 字符
///
public const string DataType_Char = "char";
#endregion
///
/// 根据西门子PLC的数据类型获取对应C#的类型编号枚举
///
/// 西门子PLC的数据类型
/// 返回对应C#的类型编号枚举
///
public static TypeCode GetTypeCode(string dataType)
{
return dataType.ToLower() switch
{
DataType_DInt => TypeCode.Int32,
DataType_DW => TypeCode.UInt32,
DataType_Int => TypeCode.Int16,
DataType_W => TypeCode.UInt16,
DataType_Float => TypeCode.Single,
DataType_Bool => TypeCode.Boolean,
DataType_Byte => TypeCode.Byte,
DataType_String => TypeCode.String,
DataType_Char => TypeCode.Char,
_ => throw new CommunicationException($"数据类型错误:【{dataType}】", CommunicationErrorType.TypeError),
};
}
}
}