This commit is contained in:
parallelbgls
2017-10-21 09:42:08 +08:00
2 changed files with 16 additions and 1 deletions

View File

@@ -860,13 +860,26 @@ namespace Modbus.Net.Siemens
{0xEF, "Layer 2 specific error"}
};
private static readonly Dictionary<int, string> ProtocalErrorDetailDictionary = new Dictionary<int, string>
{
{0x8304, "Resource not available,\r\n there are no more resources available for application associations to be established" },
{0x8104, "Context is not supported:\r\n -Error in PDU structure\r\n -Unknown service" },
{0x8404, "Fatal error detected.\r\n Service or function aborted" },
{0x8500, "PDU size error"}
};
/// <summary>
/// 构造函数
/// </summary>
/// <param name="errCls">错误分类</param>
/// <param name="errCod">错误码</param>
public SiemensProtocalErrorException(int errCls, int errCod)
: base(ProtocalErrorDictionary[errCls] + " : " + errCod)
: base((ProtocalErrorDictionary.ContainsKey(errCls)
? ProtocalErrorDictionary[errCls]
: "Unknown error") + " \r\n " +
(ProtocalErrorDetailDictionary.ContainsKey(errCls * 256 + errCod)
? ProtocalErrorDetailDictionary[errCls * 256 + errCod]
: "Unknown error detail"))
{
ErrorClass = errCls;
ErrorCode = errCod;

View File

@@ -43,6 +43,8 @@ namespace Modbus.Net.Siemens
case 0xf0:
switch (content[8])
{
case 0x01:
case 0x02:
case 0x03:
if (content[17] == 0x00 && content[18] == 0x00) return true;
throw new SiemensProtocalErrorException(content[17], content[18]);