22 lines
789 B
C#
22 lines
789 B
C#
using HslCommunication;
|
|
using XP.Hardware.Plc.Exceptions;
|
|
|
|
namespace XP.Hardware.PLC.Helpers
|
|
{
|
|
/// <summary>
|
|
/// PLC 辅助类,提供数据类型转换和地址解析辅助方法 | PLC helper class, provides data type conversion and address parsing helper methods
|
|
/// </summary>
|
|
public static class PlcHelper
|
|
{
|
|
/// <summary>
|
|
/// 检查操作结果,抛出统一异常 | Check operation result and throw unified exception
|
|
/// </summary>
|
|
/// <param name="result">操作结果 | Operation result</param>
|
|
public static void CheckSuccess(OperateResult result)
|
|
{
|
|
if (!result.IsSuccess)
|
|
throw new PlcException($"PLC操作失败: {result.Message} (Code: {result.ErrorCode})");
|
|
}
|
|
}
|
|
}
|