Skip to content

Commit 0057ffe

Browse files
committed
发布版本:1.0.0
1 parent 16f1036 commit 0057ffe

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

logo.png

20.9 KB
Loading

src/Quick.SL651.Test/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
IPAddress = ipadress,
2020
Port = port
2121
});
22-
centralStation.TelemetryStationConnected += (sender, telemetryStation) =>
22+
centralStation.TelemetryStationConnected += (sender, e) =>
2323
{
24+
var telemetryStation = e.TelemetryStation;
2425
Console.WriteLine($"[{DateTime.Now}] 遥测站[端点:{telemetryStation.RemoteEndPoint}]已连接!遥测站地址:{telemetryStation.TelemetryStationInfo.TelemetryStationAddress_Text}");
2526
telemetryStation.Disconnected += (sender2, e) =>
2627
{

src/Quick.SL651/CentralStation.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public class CentralStation
1212
public CentralStationOptions Options { get; private set; }
1313
private TcpListener tcpListener;
1414
private CancellationTokenSource cts;
15-
public event EventHandler<TelemetryStationContext> TelemetryStationConnected;
15+
/// <summary>
16+
/// 遥测站已连接事件
17+
/// </summary>
18+
public event EventHandler<TelemetryStationConnectedEventArgs> TelemetryStationConnected;
1619
private List<TelemetryStationContext> telemetryStationList = new List<TelemetryStationContext>();
1720

1821
public CentralStation(CentralStationOptions options)
@@ -64,7 +67,14 @@ private void TelemetryStation_Disconnected(object sender, Exception e)
6467
private void TelemetryStation_Connected(object sender, EventArgs e)
6568
{
6669
var telemetryStation = (TelemetryStationContext)sender;
67-
TelemetryStationConnected?.Invoke(this, telemetryStation);
70+
var telemetryStationConnectedEventArgs = new TelemetryStationConnectedEventArgs()
71+
{
72+
TelemetryStation = telemetryStation
73+
};
74+
TelemetryStationConnected?.Invoke(this, telemetryStationConnectedEventArgs);
75+
//如果不允许连接,则断开
76+
if (!telemetryStationConnectedEventArgs.Allowed)
77+
telemetryStation.OnError(new ApplicationException(telemetryStationConnectedEventArgs.Message));
6878
}
6979

7080
public void Stop()

src/Quick.SL651/Quick.SL651.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
6+
<PackageProjectUrl>https://github.com/aaasoft/Quick.SL651</PackageProjectUrl>
7+
<RepositoryUrl>https://github.com/aaasoft/Quick.SL651</RepositoryUrl>
8+
<Copyright />
9+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10+
<Authors>scbeta</Authors>
11+
<Version>1.0.0</Version>
12+
<Company />
13+
<Description>《水文监测数据通信规约》(SL651-2014)</Description>
14+
<PackageIcon>logo.png</PackageIcon>
15+
<PackageTags>SL651</PackageTags>
616
</PropertyGroup>
717

18+
<ItemGroup>
19+
<None Include="..\..\logo.png">
20+
<Pack>True</Pack>
21+
<PackagePath>\</PackagePath>
22+
</None>
23+
</ItemGroup>
824
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Quick.SL651
8+
{
9+
public class TelemetryStationConnectedEventArgs : EventArgs
10+
{
11+
/// <summary>
12+
/// 遥测站上下文
13+
/// </summary>
14+
public TelemetryStationContext TelemetryStation { get; set; }
15+
/// <summary>
16+
/// 是否允许连接
17+
/// </summary>
18+
public bool Allowed { get; set; } = true;
19+
/// <summary>
20+
/// 当拒绝连接时返回的消息
21+
/// </summary>
22+
public string Message { get; set; }
23+
}
24+
}

src/Quick.SL651/TelemetryStationContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ internal void Start()
8080
_ = beginReadData();
8181
}
8282

83-
private void onError(Exception ex)
83+
internal void OnError(Exception ex)
8484
{
8585
stream?.Dispose();
8686
stream = null;
@@ -170,7 +170,7 @@ private async Task beginReadData()
170170
}
171171
catch (Exception ex)
172172
{
173-
onError(ex);
173+
OnError(ex);
174174
return;
175175
}
176176
_ = beginReadData();

0 commit comments

Comments
 (0)