72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using HslCommunication;
|
|
using HslCommunication.Profinet.Siemens;
|
|
using PlcTool.Siemens.Entity;
|
|
|
|
namespace PlcTool.Siemens;
|
|
|
|
/// <summary>
|
|
/// 数据转换类
|
|
/// </summary>
|
|
public static class DataConvert
|
|
{
|
|
|
|
/// <summary>
|
|
/// 将string转化为西门子PLC类型
|
|
/// 不满足条件的转化为1200
|
|
/// 支持的string:
|
|
/// 1500
|
|
/// 1200
|
|
/// 300
|
|
/// 400
|
|
/// 200
|
|
/// 200s
|
|
/// </summary>
|
|
/// <param name="plcKandStr"></param>
|
|
/// <returns></returns>
|
|
public static SiemensPLCS ToPlcKind(this string? plcKandStr)
|
|
{
|
|
return plcKandStr switch
|
|
{
|
|
"1500" => SiemensPLCS.S1500,
|
|
"1200" => SiemensPLCS.S1200,
|
|
"400" => SiemensPLCS.S400,
|
|
"300" => SiemensPLCS.S300,
|
|
"200s" => SiemensPLCS.S200Smart,
|
|
"200" => SiemensPLCS.S200,
|
|
_ => SiemensPLCS.S1200,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// PLC读写固定返回类
|
|
/// 返回一个新的类,
|
|
/// </summary>
|
|
/// <param name="operateResult"></param>
|
|
/// <returns></returns>
|
|
public static SemS7Result ToSemS7Result(this OperateResult operateResult)
|
|
{
|
|
return new SemS7Result()
|
|
{
|
|
Success = operateResult.IsSuccess,
|
|
ErrCode = operateResult.ErrorCode,
|
|
Message = operateResult.Message
|
|
};
|
|
}
|
|
/// <summary>
|
|
/// PLC读写固定返回类
|
|
/// 返回一个新的类,
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="operateResult"></param>
|
|
/// <returns></returns>
|
|
public static SemS7Result<T> ToSemS7Result<T>(this OperateResult<T> operateResult)
|
|
{
|
|
return new SemS7Result<T>()
|
|
{
|
|
Success = operateResult.IsSuccess,
|
|
ErrCode = operateResult.ErrorCode,
|
|
Message = operateResult.Message,
|
|
Value = operateResult.Content
|
|
};
|
|
}
|
|
} |