This commit is contained in:
郭睿 2024-12-09 15:31:24 +08:00
parent d52d3829bb
commit 73263a3ebd

View File

@ -148,7 +148,6 @@ namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
{ {
await SendCustomMessageAsync(ctx, address, 0, 4, 0);//发送版本信息请求 await SendCustomMessageAsync(ctx, address, 0, 4, 0);//发送版本信息请求
} }
UpdateConnectionContext(address, ctx);
await UpdateCommunicationStateCountAsync(address, ctx); await UpdateCommunicationStateCountAsync(address, ctx);
} }
catch (Exception ex) catch (Exception ex)
@ -158,23 +157,20 @@ namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
}); });
} }
private void UpdateConnectionContext(byte address, IChannelHandlerContext ctx)
{
_connections[address] = ctx;
}
private async Task UpdateCommunicationStateCountAsync(byte address, IChannelHandlerContext ctx) private async Task UpdateCommunicationStateCountAsync(byte address, IChannelHandlerContext ctx)
{ {
if (_connections.TryGetValue(address, out _)) if (!_connections.ContainsKey(address))
{ {
//_communicationStateCounts[address]++; await SendInitMsgToDeviceAsync(ctx, address);
//已经存在的装置地址 _connections.TryAdd(address, ctx);
} }
else else
{ {
//新加入的装置的地址 _connections[address] =ctx;
await SendInitMsgToDeviceAsync(ctx, address);
} }
} }
private async Task SendInitMsgToDeviceAsync(IChannelHandlerContext ctx, byte address) private async Task SendInitMsgToDeviceAsync(IChannelHandlerContext ctx, byte address)