Skip to content

Commit

Permalink
v1.0.0-alpha.3 (#36)
Browse files Browse the repository at this point in the history
* Update version.

* Update SOEM submodule and adapt patch.

* Add offset in DC time calculation to keep discrepancies small.

* Update timeouts.

* Remove patch.

* Update to .NET Core 3.0.

* Update AppVeyor image.

* Fix task cancellation.

* Update versions.

* Update versions.

* Add global.json.

* Update versions.

* Disable test on Windows.

* Final polishing.

* Update SOEM dependency.
  • Loading branch information
Apollo3zehn authored Mar 4, 2020
1 parent 6faf3a1 commit 5ea922a
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 113 deletions.
9 changes: 7 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ clone_depth: 1

image:
- Ubuntu
- Visual Studio 2017
- Visual Studio 2019

environment:
ApiKey:
Expand Down Expand Up @@ -69,8 +69,13 @@ after_build:
Push-AppveyorArtifact "./artifacts/bin64/SOEM_wrapper/$env:FileName" -FileName "lib64"
}
# On Windows, WinPcap is probably missing
test_script:
- ps: dotnet test ./tests/EtherCAT.NET.Tests -c $Env:CONFIGURATION /p:BuildProjectReferences=false
- ps: |
if ($isLinux)
{
dotnet test ./tests/EtherCAT.NET.Tests -c $Env:CONFIGURATION /p:BuildProjectReferences=false
}
artifacts:
- path: ./artifacts/packages/**/*.nupkg
Expand Down
6 changes: 6 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# EtherCAT.NET

[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/apollo3zehn/ethercat.net?svg=true)](https://ci.appveyor.com/project/Apollo3zehn/ethercat-net)

> **WARNING**: The current package contains no Linux libs since AppVeyor has not yet updated to Visual Studio 2019 and .NET Core 3.0 preview 5.
[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/apollo3zehn/ethercat.net?svg=true&branch=master)](https://ci.appveyor.com/project/Apollo3zehn/ethercat-net)

A large amount of the logic of EtherCAT.NET comes from the data acquisition software [OneDAS](https://github.com/OneDAS-Group/OneDAS-Core), where the master has been extensively tested on many slaves from Beckhoff, Gantner and Anybus. Due to the effort to reduce protocol specific logic within OneDAS and to allow standalone use of the EtherCAT master, EtherCAT.NET was born.

Expand Down Expand Up @@ -165,7 +163,7 @@ A single Powershell *Core* script is used for all platforms to initialize the so

You need the following tools:

* [.NET Core 3.0 Preview 5](https://dotnet.microsoft.com/download/dotnet-core/3.0)
* [.NET Core 3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1)
* [PowerShell Core](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6)
* [build-essential](https://packages.debian.org/de/sid/build-essential)
* [g++-multilib](https://packages.debian.org/de/sid/g++-multilib)
Expand All @@ -192,7 +190,7 @@ The solution can then be built as follows:
You need the following tools:
* [.NET Core 3.0 Preview 5](https://dotnet.microsoft.com/download/dotnet-core/3.0)
* [.NET Core 3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1)
* [PowerShell Core](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-6)
* [Visual Studio 2019](https://visualstudio.microsoft.com)
* [CMake](https://cmake.org)
Expand Down
2 changes: 1 addition & 1 deletion build/Start-ArtifactDownload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ function Start-ArtifactDownload([string]$jobName, [string]$sourceFileName, [stri
}
catch
{
throw "Could not download file `"$sourceFileName`" with target file name `"$targetFilePath`"."
throw "Could not download file `"$sourceFileName`" with target file path `"$targetFilePath`"."
}
}
3 changes: 1 addition & 2 deletions build/build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
<DebugType>embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<LangVersion>latest</LangVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<NoPackageAnalysis>true</NoPackageAnalysis>
</PropertyGroup>

<PropertyGroup>
<Major Condition="$(Major) == ''">1</Major>
<Minor Condition="$(Minor) == ''">0</Minor>
<Revision Condition="$(Revision) == ''">0</Revision>
<VersionSuffix Condition="$(VersionSuffix) == ''">alpha.2</VersionSuffix>
<VersionSuffix Condition="$(VersionSuffix) == ''">alpha.3</VersionSuffix>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 1 addition & 2 deletions build/build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<Error Condition="$(Minor) == ''" Text="The Minor property must be set." />
<Error Condition="$(Revision) == ''" Text="The Revision property must be set." />
<Error Condition="$(PackageProjectUrl) == ''" Text="The PackageProjectUrl property must be set." />
<Error Condition="$(PackageLicenseExpression) == ''" Text="The PackageLicenseExpression property must be set." />

<Error Condition="$(PackageLicenseExpression) == ''" Text="The PackageLicenseExpression property must be set." />

<!-- build properties -->
<PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"allowPrerelease": false
}
}
7 changes: 0 additions & 7 deletions init_solution.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
Write-Host "Updating Git submodule."
git submodule update --init --recursive --quiet

Write-Host "Apply patch to SOEM."
$path = "$($PSScriptRoot)/native/SOEM"
Set-Location -Path $path
git apply --stat ./../0001-Tune-SOEM.patch
git apply --check ./../0001-Tune-SOEM.patch
git apply ./../0001-Tune-SOEM.patch

# x86
Write-Host "Creating native x86 project."
$path = "$($PSScriptRoot)/artifacts/bin32"
Expand Down
78 changes: 0 additions & 78 deletions native/0001-Tune-SOEM.patch

This file was deleted.

16 changes: 11 additions & 5 deletions native/SOEM_wrapper/soem_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <stdlib.h>
#include "soem_wrapper.h"

#define EC_VER2

// private
int _referenceSlave;

Expand Down Expand Up @@ -329,7 +331,7 @@ int CALLCONV GetSyncManagerType(ecx_contextt* context, uint16 slaveIndex, uint16

int CALLCONV RequestOpState(ecx_contextt* context)
{
int counter = 40;
int counter = 200;

context->slavelist[0].state = EC_STATE_OPERATIONAL;

Expand All @@ -342,15 +344,15 @@ int CALLCONV RequestOpState(ecx_contextt* context)
{
ecx_send_processdata(context);
ecx_receive_processdata(context, EC_TIMEOUTRET);
ecx_statecheck(context, 0, EC_STATE_OPERATIONAL, 50000);
ecx_statecheck(context, 0, EC_STATE_OPERATIONAL, 5 * EC_TIMEOUTSTATE);
} while (counter-- && (context->slavelist[0].state != EC_STATE_OPERATIONAL));

return context->slavelist[0].state == EC_STATE_OPERATIONAL ? 1 : -0x0601;
}

int CALLCONV CheckSafeOpState(ecx_contextt* context)
{
ecx_statecheck(context, 0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE * 4);
ecx_statecheck(context, 0, EC_STATE_SAFE_OP, EC_TIMEOUTSTATE);

return context->slavelist[0].state == EC_STATE_SAFE_OP ? 1 : -0x0501;
}
Expand Down Expand Up @@ -556,8 +558,12 @@ int CALLCONV ScanDevices(ecx_contextt* context, char* interfaceName, ec_slave_in

for (int slaveIndex = 1; slaveIndex < *context->slavecount + 1; slaveIndex++)
{
// clear watchdog trigger enable in SM2 control register
context->slavelist[slaveIndex].SM[2].SMflags &= ~0x40;
// clear watchdog trigger enable in SM control register
for (int i = 0; i < EC_MAXSM; i++)
{
if (context->slavelist[slaveIndex].SMtype[i] == 3)
context->slavelist[slaveIndex].SM[i].SMflags &= ~0x40;
}

// clear watchdog time process data register
if (!(wkc = ecx_FPWR(context->port, context->slavelist[slaveIndex].configadr, 0x420, sizeof(watchdogTime), &watchdogTime, EC_TIMEOUTRET)))
Expand Down
13 changes: 10 additions & 3 deletions sample/SampleMaster/SampleMaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.0.0-preview4-27615-11" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0-preview4.19216.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.2" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EtherCAT.NET\EtherCAT.NET.csproj" />
</ItemGroup>

<!-- workaround https://github.com/dotnet/sdk/issues/10273#issuecomment-499988244 -->
<Target Name="WorkaroundNetStandard" AfterTargets="ResolvePackageAssets">
<ItemGroup>
<TransitiveFrameworkReference Remove="NETStandard.Library" />
</ItemGroup>
</Target>

</Project>
17 changes: 16 additions & 1 deletion src/EtherCAT.NET/EcMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class EcMaster : IDisposable

// timing
private long _dcTime;
private TimeSpan _offset;

// diagnostics
private int _counter;
Expand Down Expand Up @@ -373,6 +374,12 @@ public void UpdateIO(DateTime referenceDateTime)
// the UpdateIo timer tries to fire at discrete times. The timer is allowed to be early or delayed by < (CycleTime - Offset) and the resulting DC time will be floored to nearest 10 ms.
this.UtcDateTime = _dcEpoch.AddTicks(Convert.ToInt64(_dcTime / _dateTime_To_Ns)); // for time loop control

// for compensation, if DC is not initialized with real time or not initialized at all
if (_offset == TimeSpan.Zero)
_offset = referenceDateTime - this.UtcDateTime;
else
this.UtcDateTime += _offset;

// dc drift compensation
_dcRingBuffer[_dcRingBufferIndex] = Convert.ToInt64(referenceDateTime.Ticks - this.UtcDateTime.Ticks) * _dateTime_To_Ns;
this.DcRingBufferAverage = Convert.ToInt64(_dcRingBuffer.Average());
Expand Down Expand Up @@ -465,7 +472,15 @@ protected virtual void Dispose(bool disposing)
}

_cts?.Cancel();
_watchdogTask?.Wait();

try
{
_watchdogTask?.Wait();
}
catch (Exception ex) when (ex.InnerException.GetType() == typeof(TaskCanceledException))
{
//
}

if (this.Context != IntPtr.Zero)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EtherCAT.NET/EcUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static SlaveInfo ScanDevices(IntPtr context, string interfaceName, SlaveI
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
interfaceName = $@"rpcap://\Device\NPF_{ networkInterface.Id }";
interfaceName = $@"rpcap://\Device\NPF_{networkInterface.Id}";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
interfaceName = $"{interfaceName}";
else
Expand Down
7 changes: 6 additions & 1 deletion src/EtherCAT.NET/EtherCAT.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
<Description>A high-level SOEM-based EtherCAT master with ESI support for Windows and Linux.</Description>
<PackageTags>SOEM EtherCAT PInvoke CSharp .NETStandard Windows Linux</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OneDas.Types" Version="1.0.0-alpha.2.171" />

<!-- required until OneDas.Types dependency is up to date -->
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -39,5 +44,5 @@
<CustomToolNamespace>EtherCAT</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/SOEM.PInvoke/SOEM.PInvoke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Description>A .NETStandard wrapper around the Simple Open Source EtherCAT Master (SOEM).</Description>
<PackageTags>SOEM EtherCAT PInvoke CSharp .NETStandard Windows Linux</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
15 changes: 11 additions & 4 deletions tests/EtherCAT.NET.Tests/EtherCAT.NET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.0.0-preview4-27615-11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -20,4 +20,11 @@
<ProjectReference Include="..\..\src\EtherCAT.NET\EtherCAT.NET.csproj" />
</ItemGroup>

<!-- workaround https://github.com/dotnet/sdk/issues/10273#issuecomment-499988244 -->
<Target Name="WorkaroundNetStandard" AfterTargets="ResolvePackageAssets">
<ItemGroup>
<TransitiveFrameworkReference Remove="NETStandard.Library" />
</ItemGroup>
</Target>

</Project>

0 comments on commit 5ea922a

Please sign in to comment.