Commit a67b9e3b 顾剑亮

添加日志

1 个父辈 e88c2f15
此文件类型无法预览
...@@ -35,6 +35,7 @@ namespace Asa.IOModule ...@@ -35,6 +35,7 @@ namespace Asa.IOModule
private int[] _valueAO; //AO模拟量 private int[] _valueAO; //AO模拟量
private List<byte> _receive; private List<byte> _receive;
private System.Collections.Concurrent.ConcurrentQueue<byte[]> _writeDO; private System.Collections.Concurrent.ConcurrentQueue<byte[]> _writeDO;
private log4net.ILog log;
private readonly Box_Type _typeInput; //输入类型 private readonly Box_Type _typeInput; //输入类型
private readonly Box_Type _typeOutput; //输出类型 private readonly Box_Type _typeOutput; //输出类型
...@@ -63,6 +64,7 @@ namespace Asa.IOModule ...@@ -63,6 +64,7 @@ namespace Asa.IOModule
{ {
_typeInput = input; _typeInput = input;
_typeOutput = output; _typeOutput = output;
log = log4net.LogManager.GetLogger("AIOBOX");
byte n = 0; byte n = 0;
_addressInput = new byte[inputCount]; _addressInput = new byte[inputCount];
...@@ -101,6 +103,18 @@ namespace Asa.IOModule ...@@ -101,6 +103,18 @@ namespace Asa.IOModule
public string ErrInfo { get; private set; } = ""; public string ErrInfo { get; private set; } = "";
/// <summary> /// <summary>
/// 监控DI输入,索引数组
/// </summary>
public int[] MonitorDI { get; set; }
/// <summary>
/// 监控DO输出,索引数组
/// </summary>
public int[] MonitorDO { get; set; }
/// <summary>
/// 连接 /// 连接
/// </summary> /// </summary>
public void Connect() public void Connect()
...@@ -117,7 +131,7 @@ namespace Asa.IOModule ...@@ -117,7 +131,7 @@ namespace Asa.IOModule
tRecon.Start(); tRecon.Start();
tSend.Start(); tSend.Start();
tListen.Start(); tListen.Start();
log.Info("Connect");
} }
/// <summary> /// <summary>
...@@ -135,10 +149,11 @@ namespace Asa.IOModule ...@@ -135,10 +149,11 @@ namespace Asa.IOModule
_client.Shutdown(SocketShutdown.Both); _client.Shutdown(SocketShutdown.Both);
_client.Close(); _client.Close();
} }
log.Info("Close");
} }
catch (Exception ex) catch (Exception ex)
{ {
ErrInfo = ex.Message; log.Error("Close", ex);
} }
finally finally
{ {
...@@ -271,6 +286,8 @@ namespace Asa.IOModule ...@@ -271,6 +286,8 @@ namespace Asa.IOModule
{ {
try try
{ {
log.Info("call WriteDO");
byte[] data = Command(); byte[] data = Command();
byte[] buff = new byte[12]; byte[] buff = new byte[12];
Array.Copy(data, 0, buff, 0, data.Length); Array.Copy(data, 0, buff, 0, data.Length);
...@@ -283,7 +300,7 @@ namespace Asa.IOModule ...@@ -283,7 +300,7 @@ namespace Asa.IOModule
} }
catch (Exception ex) catch (Exception ex)
{ {
ErrInfo = ex.Message; log.Error("WriteDO ", ex);
return false; return false;
} }
} }
...@@ -372,16 +389,15 @@ namespace Asa.IOModule ...@@ -372,16 +389,15 @@ namespace Asa.IOModule
} }
try try
{ {
_client.Send(buff); _client.Send(buff);
log.Debug("Send: " + HexBuff(buff));
} }
catch (Exception ex) catch (Exception ex)
{ {
ErrInfo = ex.Message; log.Error("Send ", ex);
log.Info("Socket Close");
IsConn = false; IsConn = false;
} }
} }
...@@ -453,6 +469,7 @@ namespace Asa.IOModule ...@@ -453,6 +469,7 @@ namespace Asa.IOModule
byte[] cmd = new byte[len]; byte[] cmd = new byte[len];
_receive.CopyTo(0, cmd, 0, len); _receive.CopyTo(0, cmd, 0, len);
_receive.RemoveRange(0, len); _receive.RemoveRange(0, len);
log.Debug("Receive: " + HexBuff(cmd));
System.Threading.Tasks.Task.Run(() => CommandProcess(cmd)); System.Threading.Tasks.Task.Run(() => CommandProcess(cmd));
} }
} }
...@@ -460,7 +477,7 @@ namespace Asa.IOModule ...@@ -460,7 +477,7 @@ namespace Asa.IOModule
} }
catch (Exception ex) catch (Exception ex)
{ {
ErrInfo = ex.Message; log.Error("Listen ", ex);
IsConn = false; IsConn = false;
} }
} }
...@@ -472,6 +489,7 @@ namespace Asa.IOModule ...@@ -472,6 +489,7 @@ namespace Asa.IOModule
/// <param name="cmd"></param> /// <param name="cmd"></param>
private void CommandProcess(byte[] cmd) private void CommandProcess(byte[] cmd)
{ {
string str;
int idx = 0; int idx = 0;
int count = cmd[8]; int count = cmd[8];
...@@ -494,6 +512,13 @@ namespace Asa.IOModule ...@@ -494,6 +512,13 @@ namespace Asa.IOModule
} }
} }
Array.Copy(_stateDO, 0, staDO, 0, staDO.Length); Array.Copy(_stateDO, 0, staDO, 0, staDO.Length);
if (MonitorDO != null)
{
str = "MonitorDO ";
for (int i = 0; i < MonitorDO.Length; i++)
str += string.Format("[{0}]{1} ", MonitorDO[i], _stateDO[MonitorDO[i]].ToString());
log.Info(str);
}
} }
DO_Changed_Event?.Invoke(this, staDO); DO_Changed_Event?.Invoke(this, staDO);
} }
...@@ -514,6 +539,13 @@ namespace Asa.IOModule ...@@ -514,6 +539,13 @@ namespace Asa.IOModule
} }
} }
Array.Copy(_stateDI, 0, staDI, 0, staDI.Length); Array.Copy(_stateDI, 0, staDI, 0, staDI.Length);
if (MonitorDI != null)
{
str = "MonitorDI ";
for (int i = 0; i < MonitorDI.Length; i++)
str += string.Format("[{0}]{1} ", MonitorDI[i], _stateDI[MonitorDI[i]].ToString());
log.Info(str);
}
} }
DI_Changed_Event?.Invoke(this, staDI); DI_Changed_Event?.Invoke(this, staDI);
} }
...@@ -565,14 +597,12 @@ namespace Asa.IOModule ...@@ -565,14 +597,12 @@ namespace Asa.IOModule
_client.Connect(IPAddress.Parse(IP), PORT); _client.Connect(IPAddress.Parse(IP), PORT);
Thread.Sleep(100); //需要等待一会才能获取连接状态 Thread.Sleep(100); //需要等待一会才能获取连接状态
IsConn = true; IsConn = true;
ErrInfo = ""; log.Info("Socket Connect");
return;
} }
catch (Exception ex) catch (Exception ex)
{ {
IsConn = false; IsConn = false;
ErrInfo = ex.Message; log.Error("Open ", ex);
return;
} }
} }
...@@ -672,6 +702,15 @@ namespace Asa.IOModule ...@@ -672,6 +702,15 @@ namespace Asa.IOModule
return data; return data;
} }
private string HexBuff(byte[] buff)
{
string s = "";
if (buff == null) return s;
for (int i = 0; i < buff.Length; i++)
s += buff[i].ToString("X2") + " ";
return s;
}
} }
......
...@@ -53,6 +53,9 @@ ...@@ -53,6 +53,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net">
<HintPath>..\..\..\DLL\log4net.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
......
...@@ -55,6 +55,16 @@ ...@@ -55,6 +55,16 @@
错误信息 错误信息
</summary> </summary>
</member> </member>
<member name="P:Asa.IOModule.AIOBOX.MonitorDI">
<summary>
监控DI输入,索引数组
</summary>
</member>
<member name="P:Asa.IOModule.AIOBOX.MonitorDO">
<summary>
监控DO输出,索引数组
</summary>
</member>
<member name="M:Asa.IOModule.AIOBOX.Connect"> <member name="M:Asa.IOModule.AIOBOX.Connect">
<summary> <summary>
连接 连接
......
此文件类型无法预览
6b9117074f0ff97736a34c4c150b6b18b33edbb4 358d828b90f36df54ba6bbeca64bf737465fc549
...@@ -4,3 +4,6 @@ D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\bin\Debug\Asa.IOM ...@@ -4,3 +4,6 @@ D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\bin\Debug\Asa.IOM
D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\AIOBOX.csproj.CoreCompileInputs.cache D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\AIOBOX.csproj.CoreCompileInputs.cache
D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\Asa.IOModule.AIOBOX.dll D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\Asa.IOModule.AIOBOX.dll
D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\Asa.IOModule.AIOBOX.pdb D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\Asa.IOModule.AIOBOX.pdb
D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\bin\Debug\log4net.dll
D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\AIOBOX.csprojAssemblyReference.cache
D:\OneDrive - 上海挚锦科技有限公司\SMD\AIOBOX\AIOBOX\obj\Debug\AIOBOX.csproj.CopyComplete
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!