diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs index 80de99d0..e4194ce3 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs @@ -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()); diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore/_GenesisMeterMeasurement.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore/_GenesisMeterMeasurement.cs index cc33b4bf..a3c2e99b 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisCore/_GenesisMeterMeasurement.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore/_GenesisMeterMeasurement.cs @@ -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()); diff --git a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxCore.csproj b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxCore.csproj index da814e42..b3dae395 100644 --- a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxCore.csproj +++ b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxCore.csproj @@ -104,10 +104,6 @@ {63e0ac5e-b7c8-4363-a2fe-be489e648ff0} TransmitProtocol - - {29617814-313e-409e-aa5d-59c78a9d4df1} - StreamingProtocol - {8203abb8-38e5-472e-a742-33f38b7a74a6} WaterMeterCore @@ -128,6 +124,10 @@ {00748F11-4B49-4D8B-93C4-4A11A210CCE2} RequestProtocol + + {d6b81c60-2763-4c4d-989f-90822f53b01a} + StreamingProtocol + diff --git a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs index 2bedec84..032d85bb 100644 --- a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs +++ b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs @@ -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 + + /// + /// Mark the streaming catcher as active + /// + private Boolean _streamingCatcherIsActive; + + /// + /// Streaming decoder + /// + private StreamingDecoder _streamingDecoder; /// /// Enable raw record logging, if set every incoming package will be logged @@ -261,6 +271,11 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// public event EventHandler OnRequestRecordReceived; + /// + /// Streaming record is decoded + /// + public event EventHandler OnStreamingRecordDecoded; + /// /// call this if session is expired and you need an re-authorization /// @@ -300,7 +315,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// /// /// - /// I should be or + /// I should be /// otherwise this method does nothing /// private void StreamingProtocol_ApplyDecodedRecord(Object sender, BaseDataEventArgs e) @@ -333,9 +348,64 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore OnRequestRecordReceived?.Invoke(sender, (RequestResponseDataEventArgs)e); } } + + /// + /// Kick off the streaming catcher. + /// + 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; + } + + /// + /// Cyclic execution of catcher on incoming events. + /// + /// + /// + 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 }); + } + } + + /// + /// Stop the streaming catcher. + /// + /// + 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 /// /// Ctor - default @@ -426,7 +496,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore #endregion - #region MagFlux handling + #region MagFlux handling /// /// just internal setup. called on ctor or from vb6 setup function /// @@ -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()); diff --git a/Common/Ui/GenesisToolBox/FrmStreamingQuality.cs b/Common/Ui/GenesisToolBox/FrmStreamingQuality.cs index 49a6c2b0..1c354d91 100644 --- a/Common/Ui/GenesisToolBox/FrmStreamingQuality.cs +++ b/Common/Ui/GenesisToolBox/FrmStreamingQuality.cs @@ -12,7 +12,6 @@ using Newtonsoft.Json; using NLog; using Xylem.Common.CommonCore.Consts; using Xylem.Common.Hardware.Interfaces.Ports.PortCore; -using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig; using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore; using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts; using Xylem.Common.Hardware.WaterMeter.Genesis.Registers; diff --git a/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs b/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs index 5b33dc25..3d0a79f2 100644 --- a/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs +++ b/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs @@ -30,7 +30,7 @@ { this.components = new System.ComponentModel.Container(); this.grpSetup = new System.Windows.Forms.GroupBox(); - this.tbxPcbId = new System.Windows.Forms.TextBox(); + this.tbxSensorNo = new System.Windows.Forms.TextBox(); this.btnConnect = new System.Windows.Forms.Button(); this.lblConnectPcb = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); @@ -49,14 +49,8 @@ this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.picLogo = new System.Windows.Forms.PictureBox(); this.grpBoxInfo = new System.Windows.Forms.GroupBox(); - this.label1 = new System.Windows.Forms.Label(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.textBox2 = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.textBox4 = new System.Windows.Forms.TextBox(); - this.textBox5 = new System.Windows.Forms.TextBox(); - this.textBox6 = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); + this.tbxVolume = new System.Windows.Forms.TextBox(); + this.tbxFlowRate = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.label11 = new System.Windows.Forms.Label(); this.grpSetup.SuspendLayout(); @@ -67,7 +61,7 @@ // // grpSetup // - this.grpSetup.Controls.Add(this.tbxPcbId); + this.grpSetup.Controls.Add(this.tbxSensorNo); this.grpSetup.Controls.Add(this.btnConnect); this.grpSetup.Controls.Add(this.lblConnectPcb); this.grpSetup.Controls.Add(this.label2); @@ -79,13 +73,13 @@ this.grpSetup.TabStop = false; this.grpSetup.Text = "Setup"; // - // tbxPcbId + // tbxSensorNo // - this.tbxPcbId.Location = new System.Drawing.Point(128, 59); - this.tbxPcbId.Name = "tbxPcbId"; - this.tbxPcbId.ReadOnly = true; - this.tbxPcbId.Size = new System.Drawing.Size(68, 20); - this.tbxPcbId.TabIndex = 32; + this.tbxSensorNo.Location = new System.Drawing.Point(128, 59); + this.tbxSensorNo.Name = "tbxSensorNo"; + this.tbxSensorNo.ReadOnly = true; + this.tbxSensorNo.Size = new System.Drawing.Size(68, 20); + this.tbxSensorNo.TabIndex = 32; // // btnConnect // @@ -254,14 +248,8 @@ // // grpBoxInfo // - this.grpBoxInfo.Controls.Add(this.label1); - this.grpBoxInfo.Controls.Add(this.textBox1); - this.grpBoxInfo.Controls.Add(this.textBox2); - this.grpBoxInfo.Controls.Add(this.label3); - this.grpBoxInfo.Controls.Add(this.textBox4); - this.grpBoxInfo.Controls.Add(this.textBox5); - this.grpBoxInfo.Controls.Add(this.textBox6); - this.grpBoxInfo.Controls.Add(this.label4); + this.grpBoxInfo.Controls.Add(this.tbxVolume); + this.grpBoxInfo.Controls.Add(this.tbxFlowRate); this.grpBoxInfo.Controls.Add(this.label7); this.grpBoxInfo.Controls.Add(this.label11); this.grpBoxInfo.Location = new System.Drawing.Point(9, 109); @@ -269,92 +257,41 @@ this.grpBoxInfo.Size = new System.Drawing.Size(348, 228); this.grpBoxInfo.TabIndex = 37; this.grpBoxInfo.TabStop = false; - this.grpBoxInfo.Text = "Info"; + this.grpBoxInfo.Text = "Measurements"; // - // label1 + // tbxVolume // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(6, 146); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(116, 13); - this.label1.TabIndex = 36; - this.label1.Text = "Radio frequency[MHz]:"; + this.tbxVolume.Location = new System.Drawing.Point(124, 22); + this.tbxVolume.Name = "tbxVolume"; + this.tbxVolume.ReadOnly = true; + this.tbxVolume.Size = new System.Drawing.Size(68, 20); + this.tbxVolume.TabIndex = 31; // - // textBox1 + // tbxFlowRate // - this.textBox1.Location = new System.Drawing.Point(124, 142); - this.textBox1.Name = "textBox1"; - this.textBox1.ReadOnly = true; - this.textBox1.Size = new System.Drawing.Size(68, 20); - this.textBox1.TabIndex = 35; - // - // textBox2 - // - this.textBox2.Location = new System.Drawing.Point(124, 112); - this.textBox2.Name = "textBox2"; - this.textBox2.ReadOnly = true; - this.textBox2.Size = new System.Drawing.Size(68, 20); - this.textBox2.TabIndex = 34; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(6, 116); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(44, 13); - this.label3.TabIndex = 33; - this.label3.Text = "Region:"; - // - // textBox4 - // - this.textBox4.Location = new System.Drawing.Point(124, 22); - this.textBox4.Name = "textBox4"; - this.textBox4.ReadOnly = true; - this.textBox4.Size = new System.Drawing.Size(68, 20); - this.textBox4.TabIndex = 31; - // - // textBox5 - // - this.textBox5.Location = new System.Drawing.Point(124, 82); - this.textBox5.Name = "textBox5"; - this.textBox5.ReadOnly = true; - this.textBox5.Size = new System.Drawing.Size(68, 20); - this.textBox5.TabIndex = 30; - // - // textBox6 - // - this.textBox6.Location = new System.Drawing.Point(124, 52); - this.textBox6.Name = "textBox6"; - this.textBox6.ReadOnly = true; - this.textBox6.Size = new System.Drawing.Size(68, 20); - this.textBox6.TabIndex = 29; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(6, 86); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(60, 13); - this.label4.TabIndex = 28; - this.label4.Text = "Meter Size:"; + this.tbxFlowRate.Location = new System.Drawing.Point(124, 52); + this.tbxFlowRate.Name = "tbxFlowRate"; + this.tbxFlowRate.ReadOnly = true; + this.tbxFlowRate.Size = new System.Drawing.Size(68, 20); + this.tbxFlowRate.TabIndex = 29; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(6, 56); this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(86, 13); + this.label7.Size = new System.Drawing.Size(92, 13); this.label7.TabIndex = 27; - this.label7.Text = "Meter LUT CRC:"; + this.label7.Text = "Flow Rate [cm/h]:"; // // label11 // this.label11.AutoSize = true; this.label11.Location = new System.Drawing.Point(6, 26); this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(57, 13); + this.label11.Size = new System.Drawing.Size(68, 13); this.label11.TabIndex = 25; - this.label11.Text = "Meter FW:"; + this.label11.Text = "Volume [cm]:"; // // FrmTest // @@ -411,18 +348,12 @@ private System.Windows.Forms.Label lblWaitingForMeterResponse; private System.Windows.Forms.Label label9; private System.Windows.Forms.Label lblUpdateTime; - private System.Windows.Forms.TextBox tbxPcbId; + private System.Windows.Forms.TextBox tbxSensorNo; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox picLogo; private System.Windows.Forms.GroupBox grpBoxInfo; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.TextBox textBox2; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.TextBox textBox4; - private System.Windows.Forms.TextBox textBox5; - private System.Windows.Forms.TextBox textBox6; - private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox tbxVolume; + private System.Windows.Forms.TextBox tbxFlowRate; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label11; } diff --git a/Common/Ui/MagFluxToolBox/FrmTest.cs b/Common/Ui/MagFluxToolBox/FrmTest.cs index d58b618c..49085eff 100644 --- a/Common/Ui/MagFluxToolBox/FrmTest.cs +++ b/Common/Ui/MagFluxToolBox/FrmTest.cs @@ -5,6 +5,8 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments; +using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments; using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore; using Xylem.Common.Hardware.WaterMeter.WaterMeterCore; using Xylem.Common.Utils.ProcessExec.EventArguments; @@ -75,7 +77,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox lblWaitingForMeterResponse.Visible = false; btnConnect.Enabled = true; SetControlDownloadsLocked(); - tbxPcbId.Visible = false; + tbxSensorNo.Visible = false; } private void FrmTest_Load(Object sender, EventArgs e) @@ -91,7 +93,9 @@ namespace Xylem.Common.Ui.MagFluxToolBox private void FrmTest_FormClosing(Object sender, FormClosingEventArgs e) { + _magFluxMeter.OnStreamingRecordDecoded -= StreamingCatcher_OnStreamingRecordDecoded; _magFluxMeter?.Logout(); + _magFluxMeter?.StopStreamingCatcher(); _meterBatch?.RemoveAllMeters(); _meterBatch?.Dispose(); @@ -127,6 +131,24 @@ namespace Xylem.Common.Ui.MagFluxToolBox #endregion #region BoardControls + + /// + /// Cyclic execution of catcher on incoming events. + /// + /// + /// + private void StreamingCatcher_OnStreamingRecordDecoded(Object sender, MagFluxFlowDataEventArgs e) + { + Invoke(new Action(() => + { + tbxSensorNo.Text = e.NewData.SensorId; + tbxVolume.Text = $@"{e.NewData.VolumeCm:F3}"; + tbxFlowRate.Text = $@"{e.NewData.FlowRateCmPh:F3}"; + })); + + } + + private void Connect() { try @@ -159,6 +181,8 @@ namespace Xylem.Common.Ui.MagFluxToolBox _magFluxMeter.Configuration.UseRegisterWatchService = false; _magFluxMeter.Configuration.UseMinMaxCheck = false; + _magFluxMeter.OnStreamingRecordDecoded += StreamingCatcher_OnStreamingRecordDecoded; + _meterBatch.MetersLogin(); //if (!_magFluxMeter.IsLoggedOn) @@ -194,6 +218,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox lblConnectPcb.ForeColor = Color.Green; CheckUpdateEnabled(); + _magFluxMeter.StartStreamingCatcher(); _magFluxMeter.Logout(); LogInstalledMeterFw(); })); diff --git a/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj b/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj index 73b66b00..81a89206 100644 --- a/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj +++ b/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj @@ -129,6 +129,10 @@ {72037e89-4f63-4b3f-beff-4138e578ce99} SerialPorts + + {BA17D20E-0CEB-4B27-9772-2392BD750ED5} + DataPackages + {70398b99-b134-4bbd-968b-7399b70c3ce2} MagFluxConfig @@ -141,6 +145,10 @@ {8203abb8-38e5-472e-a742-33f38b7a74a6} WaterMeterCore + + {6CCDB656-C676-4360-BABA-C4596AAD175D} + Measurements + {a33e3c6d-eaae-4a20-a0ee-f9e6922fd029} SoftwareAccessHelper