|
|
@ -5,7 +5,6 @@ using System.ComponentModel; |
|
|
using System.Globalization; |
|
|
using System.Globalization; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.IO.Ports; |
|
|
using System.IO.Ports; |
|
|
using System.Net; |
|
|
|
|
|
using System.Text; |
|
|
using System.Text; |
|
|
|
|
|
|
|
|
namespace PanasonicPLCriver |
|
|
namespace PanasonicPLCriver |
|
|
@ -340,7 +339,8 @@ namespace PanasonicPLCriver |
|
|
} |
|
|
} |
|
|
catch (Exception e) |
|
|
catch (Exception e) |
|
|
{ |
|
|
{ |
|
|
OnClose?.Invoke(this, new ShutdownRequestEventArgs(e.Message)); |
|
|
if (OnClose != null) |
|
|
|
|
|
OnClose(this, new ShutdownRequestEventArgs(e.Message)); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -359,14 +359,16 @@ namespace PanasonicPLCriver |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception) |
|
|
{ |
|
|
{ |
|
|
OnClose?.Invoke(this, new ShutdownRequestEventArgs("读取超时")); |
|
|
if (OnClose != null) |
|
|
|
|
|
OnClose(this, new ShutdownRequestEventArgs("读取超时")); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (recv.Substring(3, 1) == "!")//返回为错误代码
|
|
|
if (recv.Substring(3, 1) == "!")//返回为错误代码
|
|
|
{ |
|
|
{ |
|
|
string err = recv.Substring(4, 2); |
|
|
string err = recv.Substring(4, 2); |
|
|
OnClose?.Invoke(this, new ShutdownRequestEventArgs(daveStrerror(err))); |
|
|
if (OnClose != null) |
|
|
|
|
|
OnClose(this, new ShutdownRequestEventArgs(daveStrerror(err))); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
string needXorStr = recv.Substring(0, recv.Length - 2);//需要进行xor校验的字符串
|
|
|
string needXorStr = recv.Substring(0, recv.Length - 2);//需要进行xor校验的字符串
|
|
|
@ -374,7 +376,8 @@ namespace PanasonicPLCriver |
|
|
string checkStr = Utility.XorCheck(needXorStr); |
|
|
string checkStr = Utility.XorCheck(needXorStr); |
|
|
if (checkStr != recvCheck) |
|
|
if (checkStr != recvCheck) |
|
|
{ |
|
|
{ |
|
|
OnClose?.Invoke(this, new ShutdownRequestEventArgs("校验失败")); |
|
|
if (OnClose != null) |
|
|
|
|
|
OnClose(this, new ShutdownRequestEventArgs("校验失败")); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
|