Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
37dabc4
#5: Update Twin-ADS Lib to V5.
stegm Feb 11, 2022
3439cf1
#5: Fix bugs.
stegm Feb 11, 2022
a17326f
#5: Add micro benchmark for marshalling comparison.
stegm Feb 15, 2022
5c2eb3f
#5: Add extension method for getting managed type.
stegm Feb 15, 2022
78e135e
#646: Try to fix mocking of skipped unit test.
stegm Feb 15, 2022
14a94eb
#646: TODOs entfernt.
stegm Feb 15, 2022
f98e0b8
#5: New version.
stegm Feb 15, 2022
af72530
#5: Add new option to use cyclic events for commands.
stegm Feb 15, 2022
b3aec23
#5: Fix try/catch statement.
stegm Feb 15, 2022
e20f36d
#5: Fix almost all warnings.
stegm Feb 15, 2022
0a85843
#5: REfactor PlcAdsStateReader.
stegm Feb 15, 2022
0556252
#5: Fix unit test.
stegm Feb 15, 2022
e6bad6c
#5: Set connection to null after notifications.
stegm Feb 16, 2022
f403234
#5: Add logging to AdsClient. Provide logging in case of missing samp…
stegm Feb 18, 2022
500ec88
#5: Rewrite heartbeat for better diagnosis and less false-alarms.
stegm Feb 18, 2022
877d90c
Add support for netstandard2.0 because of Beckhoff.TwinCAT.Ads v5
bqstony Feb 19, 2022
0e62a54
fix PlcStateHeartBeatGenerator tests, now all tests running again.
bqstony Feb 19, 2022
24fc7de
fix hdf5 dependet tests for .net6
bqstony Feb 19, 2022
b5fa10d
Mbc.Pcs.Net.Alarm.Service for net6.0-windows target
bqstony Feb 19, 2022
4840cb9
add note
bqstony Feb 19, 2022
8acae71
#5: MaxDelay Factor for notifications.
stegm Feb 21, 2022
4d010ad
#7 - Update Beckhoff.TwinCAT.Ads to latest version 6.0.286
bqstony Sep 11, 2023
d43505e
Remove Nlog Dependency and use MS Extension ILogger (Mbc.Pcs.Net.Alar…
bqstony Sep 18, 2023
d273075
update Beckhoff.TwinCAT.Ads lib to 6.1.154
bqstony Jan 30, 2024
06e8b8a
Update Castle.Core to 5.1.1
bqstony Jan 31, 2024
8e7813f
Update test frameworks to latest version, we have dependency to caste…
bqstony Jan 31, 2024
b058265
Update Mbc.Pcs.Net.Test FluentAssertions to latest version
bqstony Jan 31, 2024
2213e93
add .net8.0, we still use BinaryFormatter
bqstony Jan 31, 2024
52ccef3
Support conversion of TwinCAT.PlcOpen.TIME and TwinCAT.PlcOpen.DATE t…
bqstony Feb 28, 2024
8cc4328
handle the differnt culture of the build host
bqstony Feb 29, 2024
dcbe35c
disable instable unittest
bqstony Apr 3, 2024
467ffc5
Fix CodeAnalysis.ruleset path and disable NU1702 warnings
antoninmercay Apr 11, 2024
60e06f1
disable bad unit-test that does not work always on devops
bqstony May 6, 2024
980f18b
Update Beckhoff.TwinCAT.Ads to 6.1.231 and remove Ensure.That package…
bqstony May 29, 2024
02d43ee
Validate Connection to target device in PlcAdsConnectionProvider when…
bqstony May 29, 2024
17583cd
align package versions to all libraries
bqstony Jun 1, 2024
38e1a65
remove .net 6.0 and update packages
bqstony Jun 1, 2024
e922035
remove stylecop, compile warnings to zero
bqstony Jun 1, 2024
f595c59
Seperate HDF5 Mbc.Pcs.Net.DataRecorder in own Project to reduce depen…
bqstony Jun 1, 2024
45ee8ba
Remove Mbc.AsyncUtils nuget dependency
bqstony Jun 1, 2024
96dcd4c
Remove Mbc.Common nuget dependency
bqstony Jun 2, 2024
07e95e9
add code coverage
bqstony Nov 30, 2024
e6fd240
update dependency and remove vulnerability
bqstony Dec 6, 2024
3d40ee3
Add support for TwinCAT DataTypeCategory Array and Alias of Primitive…
bqstony Feb 5, 2025
a60b292
MBC.Pcs.Net.Alarm.Service uses Mbc.Common.Interface not enymore (was …
bqstony Apr 6, 2025
b31912a
Update Documentation and overview
bqstony Apr 6, 2025
626ecbf
update all package versions to 5.0.0.0, because of breaking changes a…
bqstony Apr 9, 2025
6f01b6d
update Beckhoff.TwinCAT.Ads to 6.1.332
bqstony Apr 9, 2025
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
6 changes: 4 additions & 2 deletions NET/AdsMapperCli/AdsMapperCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<StartupObject>AdsMapperCli.Program</StartupObject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.*" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.*" />
<PackageReference Include="System.Text.Json" Version="8.*" />
</ItemGroup>

<ItemGroup>
Expand Down
51 changes: 26 additions & 25 deletions NET/AdsMapperCli/DestinationDataObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@ namespace AdsMapperCli
/* PLC Struct:
TYPE ST_Test :
STRUCT
bBoolValue1 : BOOL := TRUE;
nByteValue1 : BYTE := 255;
nSbyteValue1 : BYTE := 127;
nUshortValue1 : UINT := 65535;
nShortValue1 : INT := 32767;
nUintValue1 : UDINT := 4294967295;
nIntValue1 : DINT := 2147483647;
fFloatValue1 : REAL := -1.11;
fDoubleValue1 : LREAL := 1.11;
fDoubleValue2 : LREAL := 2.22;
fDoubleValue3 : LREAL := 3.33;
fDoubleValue4MappedName : LREAL := 4.44;
tPlcTimeValue1 : TIME := T#1H33M44S555MS;
dPlcDateValue1 : DATE := D#2021-08-30;
dtPlcDateTimeValue1 : DATE_AND_TIME := DT#2021-08-30-11:12:13;
aIntArrayValue : ARRAY[0..2] OF DINT := [1, 2, 3];
eEnumStateValue : E_State := E_State.eRunning;
sPlcVersion : STRING(10) := '21.08.30.0';
sUtf7String : STRING(6) := 'ÄÖö@Ü7';
wsUnicodeString : WSTRING(6) := "ÄÖö@Ü8";
bBoolValue1 : BOOL := TRUE;
nByteValue1 : BYTE := 255;
nSbyteValue1 : BYTE := 127;
nUshortValue1 : UINT := 65535;
nShortValue1 : INT := 32767;
nUintValue1 : UDINT := 4294967295;
nIntValue1 : DINT := 2147483647;
fFloatValue1 : REAL := -1.11;
fDoubleValue1 : LREAL := 1.11;
fDoubleValue2 : LREAL := 2.22;
fDoubleValue3 : LREAL := 3.33;
fDoubleValue4MappedName : LREAL := 4.44;
tPlcTimeValue1 : TIME := T#1H33M44S555MS;
dPlcDateValue1 : DATE := D#2021-08-30;
dtPlcDateTimeValue1 : DATE_AND_TIME := DT#2021-08-30-11:12:13;
aIntArrayValue : ARRAY[0..2] OF DINT := [1, 2, 3];
eEnumStateValue : E_State := E_State.eRunning;
sPlcVersion : STRING(10) := '21.08.30.0';
sUtf7String : STRING(6) := 'ÄÖö@Ü7';
wsUnicodeString : WSTRING(6) := "ÄÖö@Ü8";
END_STRUCT
END_TYPE

{attribute 'qualified_only'}
{attribute 'strict'}
TYPE E_State :
(
eNone := 0,
eStartup := 1,
eRunning := 2,
eStop := 3
eNone := 0,
eStartup := 1,
eRunning := 2,
eStop := 3
);
END_TYPE
*/
Expand Down Expand Up @@ -78,9 +78,10 @@ public class DestinationDataObject : IPlcState
public string Utf7String { get; set; }
public string UnicodeString { get; set; }

//public Motor MotorObject { get; set; }
// public Motor MotorObject { get; set; }
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Only for tests")]
public class Motor
{
public double ActualSpeed { get; set; }
Expand Down
56 changes: 31 additions & 25 deletions NET/AdsMapperCli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,68 @@
using Mbc.Ads.Mapper;
using Mbc.Pcs.Net.Connection;
using Mbc.Pcs.Net.State;
using NLog;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;

namespace AdsMapperCli
{
public static class Program
{
private static readonly ILogger _logger = LogManager.GetCurrentClassLogger();
private static PlcAdsConnectionService _adsConnectionService;
private static PlcAdsStateReader<DestinationDataObject> _plcAdsTestPlaceStatus;
private static ILogger Logger;
private static PlcAdsConnectionService adsConnectionService;
private static PlcAdsStateReader<DestinationDataObject> plcAdsTestPlaceStatus;

public static void Main(string[] args)
{
SetupNLog();
try
{
string amsnetid = "172.28.85.92.1.1";
_logger.Info("Setup & Connect to TwinCat on {0}", amsnetid);
_adsConnectionService = new PlcAdsConnectionService(amsnetid, 851);
_adsConnectionService.ConnectionStateChanged += OnConnectionStateChanged;
string amsnetid = "204.35.225.246.1.1";
Logger.LogInformation("Setup & Connect to TwinCat on {0}", amsnetid);
adsConnectionService = new PlcAdsConnectionService(amsnetid, 851);
adsConnectionService.ConnectionStateChanged += OnConnectionStateChanged;

var testPlaceStatusConfig = new PlcAdsStateReaderConfig<DestinationDataObject>
{
VariablePath = $"PCS_Status.stTest",
VariablePath = $"GVL.stTest",
AdsMapperConfiguration = new AdsMapperConfiguration<DestinationDataObject>(
cfg => cfg.ForAllSourceMember(opt => opt.RemovePrefix("f", "n", "b", "a", "e", "t", "d", "dt", "s", "ws"))),
CycleTime = TimeSpan.FromMilliseconds(2),
MaxDelay = TimeSpan.FromMilliseconds(500),
};

// Setup state Reader
_plcAdsTestPlaceStatus = new PlcAdsStateReader<DestinationDataObject>(_adsConnectionService, testPlaceStatusConfig);
_plcAdsTestPlaceStatus.StatesChanged += OnPlcStatesChange;
plcAdsTestPlaceStatus = new PlcAdsStateReader<DestinationDataObject>(adsConnectionService, testPlaceStatusConfig, Logger);
plcAdsTestPlaceStatus.StatesChanged += OnPlcStatesChange;

// RocknRoll
_adsConnectionService.Start();
adsConnectionService.Start();

// Wait for termination
var keepRunning = true;
Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
Console.CancelKeyPress += (sender, e) =>
{
e.Cancel = true;
keepRunning = false;
};

while (keepRunning) { }
while (keepRunning)
Copy link

Copilot AI Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The infinite loop used for termination is busy waiting without any delay, which may lead to high CPU usage. Consider adding a small delay (e.g., Thread.Sleep(10)) inside the loop.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das finde ich super wenn es das einzige Makel ist das du gefunden hast :)

{
// endless
}

_logger.Info("stopping output");
_plcAdsTestPlaceStatus.StopSampling();
Logger.LogInformation("stopping output");
plcAdsTestPlaceStatus.StopSampling();
}
catch (Exception ex)
{
_logger.Info(ex, "houston we have a problem: {0}", ex.Message);
Logger.LogInformation(ex, "houston we have a problem: {0}", ex.Message);
}
finally
{
_plcAdsTestPlaceStatus?.Dispose();
_adsConnectionService?.Dispose();
plcAdsTestPlaceStatus?.Dispose();
adsConnectionService?.Dispose();
}
}

Expand All @@ -68,22 +72,24 @@ private static void SetupNLog()
// Targets where to log to: Console
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
// Rules for mapping loggers to targets
config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
config.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, logconsole);
// Apply config
NLog.LogManager.Configuration = config;

Logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger("AdsMapperCli");
}

private static void OnConnectionStateChanged(object sender, PlcConnectionChangeArgs e)
{
if (e.Connected)
{
_logger.Info("Connected to TwinCat");
_plcAdsTestPlaceStatus.StartSampling();
Logger.LogInformation("Connected to TwinCat");
plcAdsTestPlaceStatus.StartSampling();
}
else
{
Console.WriteLine("Disconnected to TwinCat");
_plcAdsTestPlaceStatus.StopSampling();
plcAdsTestPlaceStatus.StopSampling();
}
}

Expand All @@ -92,8 +98,8 @@ private static void OnPlcStatesChange(object source, PlcMultiStateChangedEventAr
var config = new System.Text.Json.JsonSerializerOptions() { WriteIndented = true, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
config.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter());

_logger.Info("New State");
_logger.Info(System.Text.Json.JsonSerializer.Serialize(testPlaceStatusEvent.State, config));
Logger.LogInformation("New State");
Logger.LogInformation(System.Text.Json.JsonSerializer.Serialize(testPlaceStatusEvent.State, config));
}
}
}
14 changes: 7 additions & 7 deletions NET/Build/Mbc.CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="16.0">
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="17.0">
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
<Name Resource="MinimumRecommendedRules_Name" />
<Description Resource="MinimumRecommendedRules_Description" />
</Localization>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp" RuleNamespace="Microsoft.CodeAnalysis.CSharp">
<Rule Id="CS1591" Action="None" />
<Rule Id="CS1591" Action="Hidden" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
<Rule Id="CA1028" Action="None" />
Expand All @@ -20,11 +20,11 @@
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1101" Action="Hidden" />
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1121" Action="None" />
<Rule Id="SA1124" Action="None" />
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1200" Action="Hidden" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1208" Action="None" />
Expand All @@ -35,14 +35,14 @@
<Rule Id="SA1515" Action="None" />
<Rule Id="SA1516" Action="None" />
<Rule Id="SA1591" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1600" Action="Hidden" />
<Rule Id="SA1601" Action="None" />
<Rule Id="SA1602" Action="None" />
<Rule Id="SA1611" Action="None" />
<Rule Id="SA1615" Action="None" />
<Rule Id="SA1623" Action="None" />
<Rule Id="SA1629" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1629" Action="Hidden" />
<Rule Id="SA1633" Action="Hidden" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1652" Action="None" />
</Rules>
Expand Down
16 changes: 11 additions & 5 deletions NET/Build/Mbc.Pcs.Net.TwinCat.EventLog.nuspec
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Mbc.Pcs.Net.TwinCat.EventLog</id>
<version>1.0.0</version>
<version>1.0.2</version>
<authors>mbc engineering</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectUrl>https://github.com/mbc-engineering/net-pcs</projectUrl>
<description>unofficial assemblies from type libraries for TwinCat Alarm and Event alias TcEventLoggerLib and TcEventLogProxyLib</description>
<dependencies>
<group targetFramework=".NETFramework4.6.1" />
<!-- Version 7.0 for Windows 7 is the default value-->
<group targetFramework="net6.0-windows7.0" />
<group targetFramework="net8.0-windows7.0" />
</dependencies>
</metadata>
<files>
<file src="..\libs\Interop.TCEVENTLOGGERLib.dll" target="lib\net461\Interop.TCEVENTLOGGERLib.dll" />
<file src="..\libs\Interop.TcEventLogProxyLib.dll" target="lib\net461\Interop.TcEventLogProxyLib.dll" />
<file src="..\Libs\Interop.TCEVENTLOGGERLib.dll" target="lib\net461\Interop.TCEVENTLOGGERLib.dll" />
<file src="..\Libs\Interop.TcEventLogProxyLib.dll" target="lib\net461\Interop.TcEventLogProxyLib.dll" />
<file src="..\Libs\Interop.TCEVENTLOGGERLib.dll" target="lib\net6.0-windows7.0\Interop.TCEVENTLOGGERLib.dll" />
<file src="..\Libs\Interop.TcEventLogProxyLib.dll" target="lib\net6.0-windows7.0\Interop.TcEventLogProxyLib.dll" />
<file src="..\Libs\Interop.TCEVENTLOGGERLib.dll" target="lib\net8.0-windows7.0\Interop.TCEVENTLOGGERLib.dll" />
<file src="..\Libs\Interop.TcEventLogProxyLib.dll" target="lib\net8.0-windows7.0\Interop.TcEventLogProxyLib.dll" />
</files>
</package>
13 changes: 0 additions & 13 deletions NET/Build/stylecop.json

This file was deleted.

2 changes: 1 addition & 1 deletion NET/CallAds/CallAds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Beckhoff.TwinCAT.Ads">
<Version>4.3.11</Version>
<Version>5.0.528</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Loading