Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/PlcInterface.Ads/IServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.IO.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PlcInterface.Ads.TwinCATAbstractions;

namespace PlcInterface.Ads;
Expand All @@ -25,7 +24,7 @@ public static IServiceCollection AddAdsPLC(this IServiceCollection serviceDescri
.AddSingletonFactory<PlcConnection, IPlcConnection<TwinCAT.Ads.IAdsConnection>, IAdsPlcConnection>()
.AddSingleton<IPlcConnection>(x => x.GetRequiredService<IAdsPlcConnection>())
.AddTransient<IAdsTypeConverter, AdsTypeConverter>()
.AddSingleton<TwinCAT.Ads.IAdsDisposableConnection, TwinCAT.Ads.AdsClient>(x => new TwinCAT.Ads.AdsClient(x.GetRequiredService<ILogger<TwinCAT.Ads.AdsClient>>()))
.AddSingleton<TwinCAT.Ads.IAdsDisposableConnection, TwinCAT.Ads.AdsClient>()
.AddSingleton<IFileSystem, FileSystem>()
.AddSingleton<ISymbolLoaderFactory, SymbolLoaderFactoryAbstraction>()
.AddSingleton<ISumSymbolFactory, SumSymbolFactory>()
Expand Down
12 changes: 6 additions & 6 deletions src/PlcInterface.Ads/PlcConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public void Disconnect()
=> DisconnectAsync().GetAwaiter().GetResult();

/// <inheritdoc/>
public Task DisconnectAsync()
=> Task.Run(() =>
{
_ = adsDisposableConnection.Disconnect();
adsDisposableConnection.ConnectionStateChanged -= AdsDisposableConnection_ConnectionStateChanged;
});
public async Task DisconnectAsync()
{
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
_ = await adsDisposableConnection.DisconnectAsync(timeoutCts.Token).ConfigureAwait(false);
adsDisposableConnection.ConnectionStateChanged -= AdsDisposableConnection_ConnectionStateChanged;
}

/// <inheritdoc/>
public void Dispose()
Expand Down
6 changes: 3 additions & 3 deletions src/PlcInterface.Ads/PlcInterface.Ads.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Beckhoff.TwinCAT.Ads" Version="6.1.203" />
<PackageReference Include="Beckhoff.TwinCAT.Ads.Reactive" Version="6.1.203" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Beckhoff.TwinCAT.Ads" Version="7.0.123" />
<PackageReference Include="Beckhoff.TwinCAT.Ads.Reactive" Version="7.0.123" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.4" />
<PackageReference Include="System.IO.Abstractions" Version="22.0.15" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace PlcInterface.Ads.TwinCATAbstractions;
/// <inheritdoc cref="SumSymbolRead"/>
internal sealed class SumSymbolReadAbstraction(IAdsConnection connection, IList<ISymbol> symbols) : ISumSymbolRead
{
private readonly SumSymbolRead backend = new(connection, symbols);
private readonly SumSymbolRead backend = new(connection, symbols, SumFallbackMode.All);

/// <inheritdoc/>
public object[] Read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace PlcInterface.Ads.TwinCATAbstractions;
/// <inheritdoc cref="SumSymbolRead"/>
internal sealed class SumSymbolWriteAbstraction(IAdsConnection connection, IList<ISymbol> symbols) : ISumSymbolWrite
{
private readonly SumSymbolWrite backend = new(connection, symbols);
private readonly SumSymbolWrite backend = new(connection, symbols, SumFallbackMode.All);

/// <inheritdoc/>
public void Write(object[] values)
Expand Down
2 changes: 1 addition & 1 deletion src/PlcInterface.Sandbox/PlcInterface.Sandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Vectron.InteractiveConsole" Version="1.0.68" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
<PackageReference Include="Beckhoff.TwinCAT.Ads.TcpRouter" Version="6.1.203" />
<PackageReference Include="Beckhoff.TwinCAT.Ads.TcpRouter" Version="7.0.123" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions src/PlcInterface.Sandbox/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using PlcInterface.Ads;
using PlcInterface.OpcUa;
using PlcInterface.Sandbox.PLCCommands;
Expand Down Expand Up @@ -58,7 +56,7 @@ private static async Task Main(string[] args)

_ = builder.Services
.AddAdsPLC()
.AddSingleton<IAmsRouter>(x => new AmsTcpIpRouter(x.GetRequiredService<ILogger<AmsTcpIpRouter>>(), x.GetRequiredService<IConfiguration>()))
.AddSingleton<IAmsRouter, AmsTcpIpRouter>()
.AddOptions<AdsPlcConnectionOptions>()
.BindConfiguration(AdsConnectionSettingsSection)
.Services
Expand Down
4 changes: 2 additions & 2 deletions test/PlcInterface.Ads.Tests/PlcConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void DisconnectCallsDisconnectOnClient()
connection.Disconnect();

// Assert
adsClientMock.Verify(x => x.Disconnect(), Times.Once);
adsClientMock.Verify(x => x.DisconnectAsync(It.IsAny<CancellationToken>()), Times.Once);
}

[TestMethod]
Expand All @@ -161,7 +161,7 @@ public async Task DisconnectCallsDisconnectOnClientAsync()
await connection.DisconnectAsync();

// Assert
adsClientMock.Verify(x => x.Disconnect(), Times.Once);
adsClientMock.Verify(x => x.DisconnectAsync(It.IsAny<CancellationToken>()), Times.Once);
}

[TestMethod]
Expand Down
Loading