using HslCommunication;
using HslCommunication.Profinet.Siemens;
using PlcTool.Siemens.Entity;
namespace PlcTool.Siemens;
///
/// 数据转换类
///
public static class DataConvert
{
///
/// 将string转化为西门子PLC类型
/// 不满足条件的转化为1200
/// 支持的string:
/// 1500
/// 1200
/// 300
/// 400
/// 200
/// 200s
///
///
///
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,
};
}
///
/// PLC读写固定返回类
/// 返回一个新的类,
///
///
///
public static SemS7Result ToSemS7Result(this OperateResult operateResult)
{
return new SemS7Result()
{
Success = operateResult.IsSuccess,
ErrCode = operateResult.ErrorCode,
Message = operateResult.Message
};
}
///
/// PLC读写固定返回类
/// 返回一个新的类,
///
///
///
///
public static SemS7Result ToSemS7Result(this OperateResult operateResult)
{
return new SemS7Result()
{
Success = operateResult.IsSuccess,
ErrCode = operateResult.ErrorCode,
Message = operateResult.Message,
Value = operateResult.Content
};
}
}