restructured WaterMeter

This commit is contained in:
Thomas Wiedebusch
2023-04-26 10:14:09 +02:00
parent 9c328a057c
commit dc16f86930
51 changed files with 3596 additions and 242 deletions
@@ -0,0 +1,261 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BA17D20E-0CEB-4B27-9772-2392BD750ED5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages</RootNamespace>
<AssemblyName>Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.xml</DocumentationFile>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'COM|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\COM\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\x86\Debug\Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'COM|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\COM\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'XP32bit|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\XP32bit\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'XP32bit|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\XP32bit\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'COM|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\COM\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'XP32bit|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\XP32bit\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'PerformTest|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\PerformTest\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'PerformTest|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\PerformTest\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'PerformTest|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\PerformTest\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '_MANUAL_CONTROL|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\_MANUAL_CONTROL\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '_MANUAL_CONTROL|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\_MANUAL_CONTROL\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\x86\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>6</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '_MANUAL_CONTROL|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\_MANUAL_CONTROL\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\Xylem.Common.Hardware.WaterMeter.Genesis.DataPackages.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\..\.shared\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="EventArguments\MagFluxFlowDataEventArgs.cs" />
<Compile Include="EventArguments\RequestResponseDataEventArgs.cs" />
<Compile Include="MeasurementRecords\MagFluxRecord.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\..\..\ServiceFwUpdate\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\NLog.4.6.7\lib\net40-client\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\CommonCore\CommonCore.csproj">
<Project>{1B02C79E-0B19-43E2-8F6B-71EF0C786C97}</Project>
<Name>CommonCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Metrology\Measurements\Measurements.csproj">
<Project>{6CCDB656-C676-4360-BABA-C4596AAD175D}</Project>
<Name>Measurements</Name>
</ProjectReference>
<ProjectReference Include="..\..\Genesis\Registers\Registers.csproj">
<Project>{F4AAF7E6-7333-4284-B735-E32DEB076C64}</Project>
<Name>Registers</Name>
</ProjectReference>
<ProjectReference Include="..\..\ProtocolCore\ProtocolCore.csproj">
<Project>{8BDD2789-96D4-43EA-AAD7-0F49D0347998}</Project>
<Name>ProtocolCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,21 @@
using System;
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.MeasurementRecords;
using Xylem.Common.Hardware.WaterMeter.ProtocolCore.EventArguments;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments
{
/// <inheritdoc />
public class MagFluxFlowDataEventArgs : BaseDataEventArgs
{
/// <summary>
/// new record from Stream
/// </summary>
public MagFluxRecord NewData;
/// <inheritdoc />
public override Object GetEventData()
{
return NewData;
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using Xylem.Common.Hardware.WaterMeter.ProtocolCore;
using Xylem.Common.Hardware.WaterMeter.ProtocolCore.EventArguments;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments
{
/// <inheritdoc />
/// <summary>
/// EventArgs for Request Responses
/// </summary>
public class RequestResponseDataEventArgs : BaseDataEventArgs
{
/// <summary>
/// Request response from meter
/// </summary>
public List<Byte> RequestResponseData;
/// <inheritdoc />
public override Object GetEventData()
{
return RequestResponseData;
}
}
}
@@ -0,0 +1,62 @@
using System;
using System.Text;
using Xylem.Common.Metrology.Measurements;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.MeasurementRecords
{
/// <inheritdoc />
/// <summary>
/// struct to hold Led record for protocol L (contains measurement record)
/// </summary>
public class MagFluxRecord : MeasurementRecord
{
/// <summary>
/// Flow rate in cubic meters per hour
/// </summary>
public Double FlowRateCmPh;
/// <summary>
/// Sensor Id of MagFlux
/// </summary>
public String SensorId;
/// <summary>
/// Serial number of MagFlux
/// </summary>
public String UniqueId;
/// <summary>
/// Status of sensor and electronics
/// </summary>
public UInt32 StatusBits;
/// <summary>
/// String delimiter to separate elements in ToString() routine
/// </summary>
private const String StringDelimiter = "; \n";
/// <summary>
/// Get result as string
/// </summary>
/// <returns></returns>
public override String ToString()
{
var sb = new StringBuilder();
sb = sb.Append($"Volume [m³]: {VolumeCm}").Append(StringDelimiter)
.Append($"CPU Time [s]: {TimeS}").Append(StringDelimiter)
.Append($"FlowRate [m³/h]: {FlowRateCmPh}").Append(StringDelimiter)
.Append($"Status: 0x{StatusBits:X8}").Append(StringDelimiter)
.Append($"UniqueId: {UniqueId}").Append(StringDelimiter)
.Append($"SensorSN: {SensorId}").Append(StringDelimiter)
.Append($"CRC: 0x{Crc:X4}").Append(StringDelimiter)
.Append($"OverflowVolume [m³]: {OverflowVolumeCm}").Append(StringDelimiter)
.Append($"OverflowTime [s]: {OverflowTimeS}").Append(StringDelimiter)
.Append($"IsValid: {IsValid}").Append(StringDelimiter)
.Append($"ReceivedTime [UTC]: {ReceivedTime}").Append(StringDelimiter)
.Append($"DecodedTime [UTC]: {DecodedTime}").Append(StringDelimiter)
.Append($"SyncMarkRecord: {SyncMarkRecord}");
return sb.ToString();
}
}
}
@@ -0,0 +1,10 @@
using System.Runtime.InteropServices;
using System.Reflection;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages")]
[assembly: AssemblyDescription("")]
[assembly: Guid("DBE76882-217A-4446-89BB-8F5E8CD8CB65")]
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net40" />
<package id="NLog" version="4.6.7" targetFramework="net40" />
</packages>
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B5DA260C-71CC-45CA-B79E-D1B376AF718C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore</RootNamespace>
<AssemblyName>Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\NLog.4.6.7\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MagFluxMeter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\..\MJK\Code\C#\modbus_master_csharp\src\modbus_master_csharp\modbus_master_csharp.csproj">
<Project>{f14940f8-3c86-4bb7-a915-b021e4b3052d}</Project>
<Name>modbus_master_csharp</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\CommonCore.Configuration\CommonCore.Configuration.csproj">
<Project>{9eb1f659-6f73-4f65-bcab-4114fd94f5fc}</Project>
<Name>CommonCore.Configuration</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\CommonCore\CommonCore.csproj">
<Project>{1b02c79e-0b19-43e2-8f6b-71ef0c786c97}</Project>
<Name>CommonCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\CommonCore\ThreadWatcher\ThreadWatcher.csproj">
<Project>{94ca71f3-c5d7-4ec6-ba47-fa8eea3c9406}</Project>
<Name>ThreadWatcher</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Metrology\Measurements\Measurements.csproj">
<Project>{6ccdb656-c676-4360-baba-c4596aad175d}</Project>
<Name>Measurements</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\SoftwareAccessHelper\SoftwareAccessHelper.csproj">
<Project>{a33e3c6d-eaae-4a20-a0ee-f9e6922fd029}</Project>
<Name>SoftwareAccessHelper</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Tools\Tools.JsonToXlsHelper\Tools.JsonToXlsHelper.csproj">
<Project>{20f137fd-c25e-42b7-a68f-58c746475897}</Project>
<Name>Tools.JsonToXlsHelper</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Utils\Logging\Logging.csproj">
<Project>{4b88b0d3-e791-4774-9521-eabeacdc420e}</Project>
<Name>Logging</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Interfaces\Ports\PortCore\PortCore.csproj">
<Project>{2e139f63-b6fe-4ea9-a098-85364fe9b26c}</Project>
<Name>PortCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Interfaces\Ports\SerialPorts\SerialPorts.csproj">
<Project>{72037e89-4f63-4b3f-beff-4138e578ce99}</Project>
<Name>SerialPorts</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Interfaces\Protocols\TransmitProtocol\TransmitProtocol.csproj">
<Project>{63e0ac5e-b7c8-4363-a2fe-be489e648ff0}</Project>
<Name>TransmitProtocol</Name>
</ProjectReference>
<ProjectReference Include="..\..\Genesis\Protocols\StreamingProtocol\StreamingProtocol.csproj">
<Project>{29617814-313e-409e-aa5d-59c78a9d4df1}</Project>
<Name>StreamingProtocol</Name>
</ProjectReference>
<ProjectReference Include="..\..\ProtocolCore\ProtocolCore.csproj">
<Project>{8BDD2789-96D4-43EA-AAD7-0F49D0347998}</Project>
<Name>ProtocolCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\WaterMeterCore\WaterMeterCore.csproj">
<Project>{8203abb8-38e5-472e-a742-33f38b7a74a6}</Project>
<Name>WaterMeterCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\WaterMeterCore\WaterMeterRegisters\WaterMeterRegisters.csproj">
<Project>{26afcf1e-1287-48b8-a506-32b1e8a0dd0e}</Project>
<Name>WaterMeterRegisters</Name>
</ProjectReference>
<ProjectReference Include="..\MagFluxConfig\MagFluxConfig.csproj">
<Project>{70398b99-b134-4bbd-968b-7399b70c3ce2}</Project>
<Name>MagFluxConfig</Name>
</ProjectReference>
<ProjectReference Include="..\Protocols\RequestProtocol\RequestProtocol.csproj">
<Project>{00748F11-4B49-4D8B-93C4-4A11A210CCE2}</Project>
<Name>RequestProtocol</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,543 @@
using System;
using NLog;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Xylem.Common.CommonCore.Consts;
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
using Xylem.Common.Hardware.Interfaces.Ports.SerialPorts;
using Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol;
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxConfig;
using Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol;
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts;
using Xylem.Common.Logic.SoftwareAccessHelper;
using Xylem.Common.Metrology.Measurements;
using Xylem.Common.Metrology.Measurements.Consts;
using Xylem.Common.Utils.Logging;
using Timer = System.Timers.Timer;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
{
/// <inheritdoc cref="IMeter" />
/// <summary>
/// MagFlux meter is the core class for the MJK MagFlux water meter.
/// One meter always is always linked to two port, one for communication and one for LED streaming.
/// </summary>
public class MagFluxMeter : IMeter, IMeterEvents
{
#region class handling
/// <summary>
/// Ctor - default
/// </summary>
/// <remarks date="2023-Apr-20" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public MagFluxMeter()
{
SetLogger();
}
/// <inheritdoc />
public void Dispose()
{
throw new NotImplementedException();
}
/// <summary>
/// Ctor
/// </summary>
/// <param name="slot">Slot number for test-bench </param>
/// <param name="requestPort"><see cref="PortConfig" /> for request Port</param>
/// <param name="streamingPort"><see cref="PortConfig" /> for streaming Port</param>
/// <param name="ignoreCorruptedData">don´t send CRC error or telegrams with error flag to caller</param>
/// <param name="password">
/// If you have a password for highest access level you need, if you don't want to access the meter
/// (just read led record) than you can leave it null
/// </param>
/// <remarks date="2023-Apr-20" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public MagFluxMeter(Int32 slot, PortConfig? requestPort, PortConfig? streamingPort,
Boolean ignoreCorruptedData = true, String password = null)
{
_logger = NLogHelper.CreateOrGetMultiLogger($"Slot:{slot}", "Slot", "Meter", "MeterBase", "MeterBase");
SetupMagFluxMeter(slot, requestPort, streamingPort, ignoreCorruptedData, password);
}
#endregion
#region variables and properties
/// <summary>
/// Represent pcb serial number
/// </summary>
public String PcbId
{
get; private set;
}
private String _currentActionText = "";
/// <summary>
/// Hold the current process name e.g. FlowTest, Preadjustemtn for logging
/// </summary>
public String CurrentActionText
{
get
{
return _currentActionText;
}
set
{
_currentActionText = value;
SetLogger();
}
}
/// <summary>
/// Add on ctor a password and it will be used for login in if no other password is set
/// </summary>
private String _password;
/// <summary>
/// request port assignment/info
/// </summary>
public IPort RequestPort
{
get; private set;
}
/// <summary>
/// request protocol assignment/info
/// </summary>
public RequestProtocol RequestProtocol;
/// <summary>
/// streaming port assignment/info
/// </summary>
public IPort StreamingPort
{
get; private set;
}
/// <summary>
/// streaming protocol assignment/info
/// </summary>
public StreamingProtocol StreamingProtocol;
/// <inheritdoc />
public String SerialNumber
{
get; set;
}
/// <inheritdoc />
public ProcessState ProcessStatus
{
get;
}
/// <inheritdoc />
public ErrorState ErrorStatus
{
get;
}
/// <inheritdoc />
public Int32 Slot
{
get; set;
}
/// <inheritdoc />
public Int32 IntermediateUpdateTimeS
{
get; set;
}
/// <summary>
/// Process configuration
/// </summary>
public ProcessConfig Configuration = new ProcessConfig();
/// <summary>
/// Transmit protocol access for underlie objects to change response timeout
/// </summary>
public ITransmitProtocol TransmitProtocol;
//initially do not signal event
private readonly AutoResetEvent _onSyncKeepSessionThread = new AutoResetEvent(false);
private Thread _keepSessionThread;
private Timer _keepSessionTimer;
private readonly CancellationTokenSource _keepSessionToken = new CancellationTokenSource();
private ILogger _logger;
private ILogger _loggerRawData;
#endregion
#region events
/// <inheritdoc />
event EventHandler IMeter.OnProcessStatusChanged
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeterEvents.OnErrorStatusChanged
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeterEvents.OnInitCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeterEvents.OnMeasurementInitCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeterEvents.OnMeasurementCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeterEvents.OnCalibInitCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeterEvents.OnCalibCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeterEvents.OnProcessStatusChanged
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeter.OnErrorStatusChanged
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeter.OnInitCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeter.OnMeasurementInitCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeter.OnMeasurementCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeter.OnCalibInitCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
event EventHandler IMeter.OnCalibCompleted
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
public event EventHandler OnDisposeCompleted;
#endregion
#region MagFlux handling
/// <summary>
/// just internal setup. called on ctor or from vb6 setup function
/// </summary>
/// <param name="slot">Slot Number for test-bench </param>
/// <param name="requestPort"><see cref="PortConfig" /> for RFID/UART/IrDA Port</param>
/// <param name="streamingPort"><see cref="PortConfig" /> for LED Port</param>
/// <param name="ignoreCorruptedData">don´t send CRC error or telegrams with error flag to caller</param>
/// <param name="password">
/// If you have a password for highest access level you need, if you don't want to access the meter
/// (just read led record) than you can leave it nullS
/// </param>
public void SetupMagFluxMeter(Int32 slot, PortConfig? requestPort, PortConfig? streamingPort,
Boolean ignoreCorruptedData = true, String password = "")
{
Slot = slot;
SetLogger();
_password = password;
if (requestPort != null)
{
String requestIdent;
if (requestPort.Value.Type == "Xylem.Common.Hardware.Interfaces.Ports.SerialPorts.UartSerialPort")
{
requestIdent = $"Slot:{Slot}, Port:{requestPort.Value.PortName}, Protocol:Request, Type:UART -";
//CRC calculation does include the CRC itself filled with 0x0000 in advance
RequestProtocol = new RequestProtocol(requestIdent);
TransmitProtocol = new UartTransmitProtocol(requestPort.Value.PortName);
RequestProtocol.SetTransmitProtocol(TransmitProtocol);
RequestPort = new UartSerialPort(requestIdent, requestPort.Value.GetSerialPort(),
TransmitProtocol.GetTransmitPortSettings());
}
}
if (streamingPort != null)
{
var ledTransmit = new LedTransmitProtocol(streamingPort.Value.PortName);
var streamingIdent = $"Slot:{Slot}/{streamingPort.Value.PortName}-Protocol:LED";
StreamingPort = new LedSerialPort(streamingIdent, streamingPort.Value.GetSerialPort(),
ledTransmit.GetTransmitPortSettings());
StreamingProtocol = new StreamingProtocol(streamingIdent, ignoreCorruptedData);
}
Configuration = new ProcessConfig(ProgramConfig.ConfigFileName);
_logger.Debug($"Slot:{Slot} - Setup done");
}
#endregion
#region logging
private void SetLogger()
{
if (_logger != null)
{
LogManager.Flush();
}
if (string.IsNullOrEmpty(CurrentActionText))
{
_logger = NLogHelper.CreateOrGetMultiLogger($"Slot:{Slot}", $"", "Meter", "MeterBase", "MeterBase");
}
else
{
var id = !string.IsNullOrEmpty(SerialNumber) ? $"SN{SerialNumber}" : $"PCB{PcbId}";
_logger = NLogHelper.CreateOrGetMultiLogger($"Slot:{Slot}_{id}_{CurrentActionText}", $"Slot", "Meter", "MeterBase", "MeterBase");
if (StreamingPort != null && StreamingPort is LedSerialPort)
{
var streamingIdent = $"LedRawData_Slot_{Slot}_{id}_{CurrentActionText}";
((LedSerialPort)StreamingPort).Ident = streamingIdent;
((LedSerialPort)StreamingPort).RefreshLogger();
if (!string.IsNullOrEmpty(SerialNumber) && CurrentActionText.Contains("PG"))
{
var pathMain = NLogHelper.GetPath(_logger);
var pathRaw = NLogHelper.GetPath(((LedSerialPort)StreamingPort).GetRawLogger());
var basePath = Path.GetDirectoryName(pathMain);
//
var testRunString = CurrentActionText.Replace("PG", "");
var lastChat = pathMain.LastIndexOf('\\');
pathMain = pathMain.Substring(lastChat + 1);
pathRaw = Path.GetFileName(pathRaw);
var tmpUrl = $"http://10.49.40.25/MeterProcessState/api/TestBench/SetMeterLogPathInfo?SerialNumber={SerialNumber}&TestRunId={testRunString}&BasePath={basePath}&MainLogName={pathMain}&LEDName={pathRaw}";
_logger.Debug($"Request Url: { tmpUrl}");
//ToDO: Update to service URl
LocalWebRequest.GetRequest(tmpUrl);
}
}
}
}
#endregion
/// <inheritdoc />
public void ConnectMeter()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData = true)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public Boolean Logout()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public Boolean Login()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public Boolean Login(String password, Boolean runImmediately = true, Boolean skipReadMeterFwAndAssignRegisters = false)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void InitMeasurement()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void StartMeasurement()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void StopMeasurement()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public MeasurementResults GetMainMeasurementResult(Double? refVolume, Double? refTimeS,
Boolean intermediateMeasurement = false)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public List<MeasurementResults> GetAllMeasurementResults(Double? refVolume, Double? refTimeS, Boolean intermediateMeasurement = false,
Int32? channel = null)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public MeasurementStates GetMeasurementState(Int32? onlyChannelNr = null)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public Boolean RequestIntermediateMeasurementState(Int32? onlyChannelNr = null)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void InitCalibration()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void StartCalibration()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void StopCalibration()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public MeasurementStates GetCalibrationState()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void BuildAndCheckCalibFactorsAllChannels(Double refVolumeCm, Double? refTimeS = null, Double reqDeviationPercent = 0,
Double maxCalibFactorTolerancePercent = 0)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void SetCalibFactorsAllChannels(Boolean justLog = false)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void SetLcdText(Boolean release, Byte[] textInHex)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void SetProcessState(DisplayCodes newState, Boolean webRequest = true)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public DisplayCodes GetLastProcessState()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void WriteLog(String text)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void LogRawData(Boolean on)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public Boolean CheckStateAfterMeasurement()
{
throw new NotImplementedException();
}
/// <inheritdoc />
public void DisposeMeter()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MagFluxCore")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Xylem")]
[assembly: AssemblyProduct("MagFluxCore")]
[assembly: AssemblyCopyright("Copyright © Xylem 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b5da260c-71cc-45ca-b79e-d1b376af718c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.6.7" targetFramework="net48" />
</packages>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Xylem")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © Xylem 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("00748f11-4b49-4d8b-93c4-4a11a210cce2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,39 @@
using System;
using modbus_master_csharp.Device;
using NLog;
using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments;
using Xylem.Common.Hardware.WaterMeter.ProtocolCore;
using Xylem.Common.Hardware.WaterMeter.ProtocolCore.EventArguments;
using Xylem.Common.Utils.Logging;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol
{
/// <summary>
/// Wrapper for MagFlux request protocol implemented in <see cref="IMagFluxRequestProtocol"/>
/// </summary>
public class RequestProtocol : BaseProtocol
{
private readonly String _ident;
private readonly ILogger _logger;
/// <inheritdoc />
public RequestProtocol(String ident) : base(ident)
{
_ident = ident;
_logger = NLogHelper.CreateOrGetMultiLogger(ident, "", "RequestProtocol", "MeterBase", "MeterBase");
}
/// <inheritdoc />
/// <inheritdoc />
public override event EventHandler<BasePortDataEventArgs> OnRecordReadyToSend;
/// <inheritdoc />
public override event EventHandler<BaseDataEventArgs> OnRecordIsDecoded;
public override void DecodeRecord(IPortDataEventArgs data)
{
throw new System.NotImplementedException();
}
}
}
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{00748F11-4B49-4D8B-93C4-4A11A210CCE2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol</RootNamespace>
<AssemblyName>Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\..\..\..\packages\NLog.4.6.7\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="RequestProtocol.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\..\..\MJK\Code\C#\modbus_master_csharp\src\modbus_master_csharp\modbus_master_csharp.csproj">
<Project>{f14940f8-3c86-4bb7-a915-b021e4b3052d}</Project>
<Name>modbus_master_csharp</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Utils\Logging\Logging.csproj">
<Project>{4B88B0D3-E791-4774-9521-EABEACDC420E}</Project>
<Name>Logging</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Interfaces\Ports\PortCore\PortCore.csproj">
<Project>{2E139F63-B6FE-4EA9-A098-85364FE9B26C}</Project>
<Name>PortCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\ProtocolCore\ProtocolCore.csproj">
<Project>{8BDD2789-96D4-43EA-AAD7-0F49D0347998}</Project>
<Name>ProtocolCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\DataPackages\DataPackages.csproj">
<Project>{BA17D20E-0CEB-4B27-9772-2392BD750ED5}</Project>
<Name>DataPackages</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.6.7" targetFramework="net48" />
</packages>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.StreamingProtocol")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Xylem")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © Xylem 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d6b81c60-2763-4c4d-989f-90822f53b01a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,193 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.MeasurementRecords;
using Xylem.Common.Utils.Crc16Ccitt;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.StreamingProtocol
{
/// <summary>
/// Data fields and definitions for GENESIS streaming protocol
/// </summary>
public class StreamingDecoder
{
private const Double MilliLitersToCmFactor = 1.0E-6;
private const Double CpuTimeToSecondsFactor = 1.0 / 0x10000;
private const Double CpuTimeOverflowS = 0x100000000 * CpuTimeToSecondsFactor;
private const Double LitersPerSecondToCmPerHourFactor = 3600.0 / 1000.0;
private const Double DefaultVolumeScaleRawPerMl = 1024.0;
private const Double DefaultVolumeFactorRawToCm = MilliLitersToCmFactor / DefaultVolumeScaleRawPerMl;
private const Double MaxGenesisAccuVolumeRaw = UInt32.MaxValue; //0x100000000; //2^32
private const Double DefaultAccuDutOverflowVolumeCm = MaxGenesisAccuVolumeRaw * DefaultVolumeFactorRawToCm;
private const Double DisplayMlSetupDutOverflowVolumeCm = 1000.0; //overflow of LCD if set to ml
private const Double TofToSecondsFactor38Bit = 1.0 / 0x4000000000; // 2^38
private const Double AmplitudeToVoltFactor = 1.0 / 0x400000 / 1000.0; // 2^22 100 0000 0000 0000 0000 0000b
private const Double PulseWidthToRelFactor = 1.0 / 0x100; // 2^8
// protocol 'l' MagFlux
private const Double MaxMagFluxVolumeRaw = UInt64.MaxValue;//0x10000000000000000; //2^64
private const Double DefaultMagFluxOverflowVolumeCm = MaxMagFluxVolumeRaw / MilliLitersToCmFactor;
/// <summary>
/// Default data for
/// </summary>
private readonly MagFluxRecord _dataMagFluxDefault = new MagFluxRecord
{
VolumeCm = 0.0,
TimeS = 0.0,
FlowRateCmPh = 0.0,
StatusBits = 0,
UniqueId = "?",
SensorId = "?",
Crc = 0xFFFF,
OverflowVolumeCm = DefaultMagFluxOverflowVolumeCm,
OverflowTimeS = CpuTimeOverflowS,
IsValid = false
};
private MagFluxRecord _dataMagFluxRec;
private readonly Boolean _ignoreCorruptedData;
/// <summary>
/// Constructor initializes all decoded members with default values
/// </summary>
public StreamingDecoder(Boolean ignoreCorruptedData = true)
{
_dataMagFluxRec = _dataMagFluxDefault;
_ignoreCorruptedData = ignoreCorruptedData;
}
/// <summary>
/// Data of MagFlux
/// </summary>
public MagFluxRecord DataMagFlux
{
get; private set;
}
/// <summary>
/// Decoding the raw message
/// </summary>
/// <param name="rawMsg">message received as one line delimited with LF</param>
/// <returns>true if decoding was successful and data has been validated</returns>
/// <remarks date="2023-Mar-09" author="T.Wiedebusch">
/// - Modified using common CRC check before branching to the protocol specific decoder.
/// </remarks>
public Boolean DecodeMsg(String rawMsg)
{
var rawRecordIsValid = false;
try
{
// save the raw message for CRC calculation before separation to fields
//_rawMsgForCrc = rawMsg;
// extract message and split it to fields
//MagFlux test string from Jan Bennett 2023-03-14_16-16-31_fromTO.log
//rawMsg = "@l 1bd911f 95b8d4 40cf9b5c 0 26004f5232500120373235 0 5863"
//DUT:Debug version, DUT:Vol FWD [mL], DUT:Time [s], DUT:Flow_LPS, DUT:StatusBitsHex, DUT:UniqueId, DUT:SensorId, DUT:CRC
//dec_AT_l, 29200671, 149.7219849, 6.487714767, 0, 4.59406E+25, 0, 22627 (0x5863)
// The received message is a string with a line delimiter.
rawMsg = rawMsg.Replace('\n', ' ');
// The raw message fields are the separated values from the received string with a blank as field separator
var rawMsgFields = rawMsg.Split(' ');
// The last element is the CRC, the CRC can be separated, calculated and validated before trying to decode the content
var rawRecordForCrc = "";
// get all fields excluding the CRC (length - 1)
for (var x = 0; x < rawMsgFields.Length - 1; x++)
{
rawRecordForCrc += rawMsgFields[x];
// add the field delimiter from raw data
rawRecordForCrc += " ";
}
// extract bytes of raw message for CRC calculation each character, CRC field is already removed
var byteArraySize = rawRecordForCrc.Length;
var byteArray = new Byte[byteArraySize];
for (var i = 0; i < byteArraySize; i++)
{
byteArray[i] = (Byte)rawRecordForCrc[i];
}
// calculate the CRC from the received data
var calculatedCrc = Crc16Ccitt.CalculateMsb1021(byteArray);
// extract received CRC
var receivedCrc = UInt16.Parse(rawMsgFields[rawMsgFields.Length - 1], NumberStyles.HexNumber);
// compare received with calculated CRC and remind valid decoding
rawRecordIsValid = calculatedCrc == receivedCrc;
switch (rawMsgFields[0])
{
case "@l":
_dataMagFluxRec.IsValid = rawRecordIsValid;
if (rawRecordIsValid || !_ignoreCorruptedData)
{
DecodeProtocolL(ref _dataMagFluxRec, rawMsgFields);
DataMagFlux = _dataMagFluxRec;
}
break;
}
}
catch (Exception)
{
// ignored
}
return rawRecordIsValid;
}
/// <summary>
/// Extracting message from string fields for protocol 'l'
/// </summary>
/// <param name="dataMagFluxRec">reference to mag flux record</param>
/// <param name="fields">fields holding the separated values for decoding</param>
/// <remarks date="2023-Mar-09" author="T.Wiedebusch">
/// - Initial.
/// </remarks>
private static void DecodeProtocolL(ref MagFluxRecord dataMagFluxRec, IList<String> fields)
{
// time stamp attachment
dataMagFluxRec.DecodedTime = DateTimeOffset.UtcNow;
// extract received CRC
dataMagFluxRec.Crc = UInt16.Parse(fields[(Int32)ProtLsubString.Crc], NumberStyles.HexNumber);
// build result values, the display volume can be positive or negative!
dataMagFluxRec.VolumeCm = UInt64.Parse(fields[(Int32)ProtLsubString.DisplayVolume],
NumberStyles.AllowHexSpecifier) * MilliLitersToCmFactor;
dataMagFluxRec.TimeS = UInt32.Parse(fields[(Int32)ProtLsubString.CpuTime],
NumberStyles.AllowHexSpecifier) * CpuTimeToSecondsFactor;
// parse the floating point value of the flow rate which is a string containing the hex value as 32 bit
var hex = UInt32.Parse(fields[(Int32)ProtLsubString.FlowRate], NumberStyles.AllowHexSpecifier);
var floatValues = BitConverter.GetBytes(hex);
dataMagFluxRec.FlowRateCmPh = BitConverter.ToSingle(floatValues, 0) *
LitersPerSecondToCmPerHourFactor;
// get status and identifiers
dataMagFluxRec.StatusBits = UInt32.Parse(fields[(Int32)ProtLsubString.StatusBits],
NumberStyles.AllowHexSpecifier);
dataMagFluxRec.UniqueId = fields[(Int32)ProtLsubString.UniqueId];
dataMagFluxRec.SensorId = fields[(Int32)ProtLsubString.SensorId];
}
/// field position in protocol 'l'
private enum ProtLsubString
{
//do not remove this needed for position in record
ProtType,
DisplayVolume,
CpuTime,
FlowRate,
StatusBits,
UniqueId,
SensorId,
Crc
}
}
}
@@ -0,0 +1,63 @@
using System;
using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments;
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments;
using Xylem.Common.Hardware.WaterMeter.ProtocolCore;
using Xylem.Common.Hardware.WaterMeter.ProtocolCore.EventArguments;
namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.StreamingProtocol
{
/// <inheritdoc />
/// <summary>
/// Layer between <see cref="StreamingDecoder" /> CRC16CCITT handler and Events
/// block trashy telegrams
/// </summary>
public class StreamingProtocol : BaseProtocol
{
/// <summary>
/// Decode data and hold results
/// </summary>
private StreamingDecoder _streamingDecode;
private readonly Boolean _ignoreCorruptedData;
/// <inheritdoc />
public override event EventHandler<BaseDataEventArgs> OnRecordIsDecoded;
/// <inheritdoc />
public override void DecodeRecord(IPortDataEventArgs dataArgs)
{
var data = (String)dataArgs.GetData();
//Data decoding
_streamingDecode = new StreamingDecoder(_ignoreCorruptedData);
_streamingDecode.DecodeMsg(data);
//Event for new data
if (_streamingDecode.DataMagFlux != null)
{
_streamingDecode.DataMagFlux.SyncMarkRecord = dataArgs.GetSyncMarkRecord();
_streamingDecode.DataMagFlux.ReceivedTime = dataArgs.GetReceivedTime();
if (_streamingDecode.DataMagFlux.IsValid)
{
OnRecordIsDecoded?.Invoke(this,
new MagFluxFlowDataEventArgs { NewData = _streamingDecode.DataMagFlux, RawData = data });
}
else if (!_ignoreCorruptedData)
{
OnRecordIsDecoded?.Invoke(this,
new MagFluxFlowDataEventArgs { NewData = _streamingDecode.DataMagFlux, RawData = data });
}
}
//toDo: handle trashy telegrams
}
/// <inheritdoc />
public StreamingProtocol(String ident, Boolean ignoreCorruptedData = true) : base(ident)
{
_ignoreCorruptedData = ignoreCorruptedData;
}
}
}
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D6B81C60-2763-4C4D-989F-90822F53B01A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.StreamingProtocol</RootNamespace>
<AssemblyName>Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.StreamingProtocol</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StreamingDecoder.cs" />
<Compile Include="StreamingProtocol.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\CommonCore\CommonCore.csproj">
<Project>{1B02C79E-0B19-43E2-8F6B-71EF0C786C97}</Project>
<Name>CommonCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Metrology\Measurements\Measurements.csproj">
<Project>{6CCDB656-C676-4360-BABA-C4596AAD175D}</Project>
<Name>Measurements</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\..\Utils\Crc16Ccitt\Crc16Ccitt.csproj">
<Project>{91DEF0C0-AA4F-40AE-8F18-CB717FDE7E7F}</Project>
<Name>Crc16Ccitt</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Interfaces\Ports\PortCore\PortCore.csproj">
<Project>{2E139F63-B6FE-4EA9-A098-85364FE9B26C}</Project>
<Name>PortCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\ProtocolCore\ProtocolCore.csproj">
<Project>{8BDD2789-96D4-43EA-AAD7-0F49D0347998}</Project>
<Name>ProtocolCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\DataPackages\DataPackages.csproj">
<Project>{BA17D20E-0CEB-4B27-9772-2392BD750ED5}</Project>
<Name>DataPackages</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>