MagFluxToolbox: - Streaming catcher implemented, first version displaying values
This commit is contained in:
@@ -649,7 +649,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
var ledTransmit = new LedTransmitProtocol(streamingPort.Value.PortName);
|
||||
|
||||
var streamingIdent = $"Slot:{Slot}/{streamingPort.Value.PortName}-Protocol:LED";
|
||||
var streamingIdent = $"Slot:{Slot}, Port:{streamingPort.Value.PortName}, Protocol:LED";
|
||||
|
||||
StreamingPort = new LedSerialPort(streamingIdent, streamingPort.Value.GetSerialPort(),
|
||||
ledTransmit.GetTransmitPortSettings());
|
||||
|
||||
@@ -87,10 +87,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
// ignored
|
||||
}
|
||||
|
||||
|
||||
|
||||
WriteRegister("GENESISFLOW_DisplayPow10", (new Byte[] { 0x00, 0x00, 0x00, 0xFA }).Reverse().ToArray());
|
||||
|
||||
@@ -104,10 +104,6 @@
|
||||
<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="..\..\WaterMeterCore\WaterMeterCore.csproj">
|
||||
<Project>{8203abb8-38e5-472e-a742-33f38b7a74a6}</Project>
|
||||
<Name>WaterMeterCore</Name>
|
||||
@@ -128,6 +124,10 @@
|
||||
<Project>{00748F11-4B49-4D8B-93C4-4A11A210CCE2}</Project>
|
||||
<Name>RequestProtocol</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Protocols\StreamingProtocol\StreamingProtocol.csproj">
|
||||
<Project>{d6b81c60-2763-4c4d-989f-90822f53b01a}</Project>
|
||||
<Name>StreamingProtocol</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -12,7 +12,7 @@ using Xylem.Common.Hardware.Interfaces.Ports.SerialPorts;
|
||||
using Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore;
|
||||
using Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore.EventArguments;
|
||||
using Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.StreamingProtocol;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.MeasurementRecords;
|
||||
using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxConfig;
|
||||
@@ -35,6 +35,16 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
public class MagFluxMeter : IMeter, IMeterEvents
|
||||
{
|
||||
#region Variables and Properties
|
||||
|
||||
/// <summary>
|
||||
/// Mark the streaming catcher as active
|
||||
/// </summary>
|
||||
private Boolean _streamingCatcherIsActive;
|
||||
|
||||
/// <summary>
|
||||
/// Streaming decoder
|
||||
/// </summary>
|
||||
private StreamingDecoder _streamingDecoder;
|
||||
|
||||
/// <summary>
|
||||
/// Enable raw record logging, if set every incoming package will be logged
|
||||
@@ -261,6 +271,11 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
/// </summary>
|
||||
public event EventHandler<RequestResponseDataEventArgs> OnRequestRecordReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Streaming record is decoded
|
||||
/// </summary>
|
||||
public event EventHandler<MagFluxFlowDataEventArgs> OnStreamingRecordDecoded;
|
||||
|
||||
/// <summary>
|
||||
/// call this if session is expired and you need an re-authorization
|
||||
/// </summary>
|
||||
@@ -300,7 +315,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e">
|
||||
/// I should be <see cref="FlowTestRecord" /> or <see cref="CalibDataEventArgs" />
|
||||
/// I should be <see cref="MagFluxRecord" />
|
||||
/// otherwise this method does nothing
|
||||
/// </param>
|
||||
private void StreamingProtocol_ApplyDecodedRecord(Object sender, BaseDataEventArgs e)
|
||||
@@ -333,9 +348,64 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
OnRequestRecordReceived?.Invoke(sender, (RequestResponseDataEventArgs)e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kick off the streaming catcher.
|
||||
/// </summary>
|
||||
public void StartStreamingCatcher()
|
||||
{
|
||||
if (_streamingCatcherIsActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_streamingDecoder = new StreamingDecoder(false);
|
||||
if (StreamingPort == null || !(StreamingPort is LedSerialPort))
|
||||
{
|
||||
throw new ApplicationException("No valid streaming port");
|
||||
}
|
||||
|
||||
SyncStreamingBuffer(SyncMarkRecord.DecodeEveryPackage);
|
||||
((LedSerialPort)StreamingPort).OnRawRecordReceived += StreamingCatcher_OnRawRecordReceived;
|
||||
LogRawData(true);
|
||||
_streamingCatcherIsActive = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cyclic execution of catcher on incoming events.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void StreamingCatcher_OnRawRecordReceived(Object sender, BasePortDataEventArgs e)
|
||||
{
|
||||
var data = (String)e.GetData();
|
||||
|
||||
if (_streamingDecoder.DecodeMsg(data))
|
||||
{
|
||||
// Fire event for listener
|
||||
OnStreamingRecordDecoded?.Invoke(this,
|
||||
new MagFluxFlowDataEventArgs{ NewData = _streamingDecoder.DataMagFlux, RawData = data });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the streaming catcher.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void StopStreamingCatcher()
|
||||
{
|
||||
if (StreamingPort == null || !(StreamingPort is LedSerialPort))
|
||||
{
|
||||
throw new ApplicationException("No valid streaming port");
|
||||
}
|
||||
LogRawData(false);
|
||||
((LedSerialPort)StreamingPort).OnRawRecordReceived -= StreamingCatcher_OnRawRecordReceived;
|
||||
SyncStreamingBuffer(SyncMarkRecord.SkipDecoding);
|
||||
_streamingCatcherIsActive = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region class handling
|
||||
#region class handling
|
||||
|
||||
/// <summary>
|
||||
/// Ctor - default
|
||||
@@ -426,7 +496,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
|
||||
#endregion
|
||||
|
||||
#region MagFlux handling
|
||||
#region MagFlux handling
|
||||
/// <summary>
|
||||
/// just internal setup. called on ctor or from vb6 setup function
|
||||
/// </summary>
|
||||
@@ -447,24 +517,24 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore
|
||||
|
||||
if (requestPort != null)
|
||||
{
|
||||
if (requestPort.Value.Type == "Xylem.Common.Hardware.Interfaces.Ports.SerialPorts.UartSerialPort")
|
||||
{
|
||||
var requestIdent = $"Slot:{Slot}, Port:{requestPort.Value.PortName}, Protocol:Request, Type:UART -";
|
||||
//if (requestPort.Value.Type == "Xylem.Common.Hardware.Interfaces.Ports.SerialPorts.UartSerialPort")
|
||||
//{
|
||||
// var requestIdent = $"Slot:{Slot}, Port:{requestPort.Value.PortName}, Protocol:Request, Type:UART -";
|
||||
|
||||
RequestProtocol = new RequestProtocol(requestIdent);
|
||||
TransmitProtocol = new UartTransmitProtocol(requestPort.Value.PortName);
|
||||
RequestProtocol.SetTransmitProtocol(TransmitProtocol);
|
||||
// RequestProtocol = new RequestProtocol(requestIdent);
|
||||
// TransmitProtocol = new UartTransmitProtocol(requestPort.Value.PortName);
|
||||
// RequestProtocol.SetTransmitProtocol(TransmitProtocol);
|
||||
|
||||
RequestPort = new UartSerialPort(requestIdent, requestPort.Value.GetSerialPort(),
|
||||
TransmitProtocol.GetTransmitPortSettings());
|
||||
}
|
||||
// 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";
|
||||
var streamingIdent = $"Slot:{Slot}, Port:{streamingPort.Value.PortName}, Protocol:LED";
|
||||
|
||||
StreamingPort = new LedSerialPort(streamingIdent, streamingPort.Value.GetSerialPort(),
|
||||
ledTransmit.GetTransmitPortSettings());
|
||||
|
||||
Reference in New Issue
Block a user