diff --git a/Common/Docu/SoftwareDesign/Quick Reference GenesisToolBox FW-Update.docx b/Common/Docu/SoftwareDesign/Quick Reference GenesisToolBox FW-Update.docx index a4177a53..9d04fc5d 100644 Binary files a/Common/Docu/SoftwareDesign/Quick Reference GenesisToolBox FW-Update.docx and b/Common/Docu/SoftwareDesign/Quick Reference GenesisToolBox FW-Update.docx differ diff --git a/Common/Docu/SoftwareDesign/Quick Reference GenesisToolBox LowLevelTools.docx b/Common/Docu/SoftwareDesign/Quick Reference GenesisToolBox LowLevelTools.docx new file mode 100644 index 00000000..636f3624 Binary files /dev/null and b/Common/Docu/SoftwareDesign/Quick Reference GenesisToolBox LowLevelTools.docx differ diff --git a/Common/Hardware/Interfaces/Protocols/ProtocolCore/BaseProtocol.cs b/Common/Hardware/Interfaces/Protocols/ProtocolCore/BaseProtocol.cs index 97b7d8c2..5933a481 100644 --- a/Common/Hardware/Interfaces/Protocols/ProtocolCore/BaseProtocol.cs +++ b/Common/Hardware/Interfaces/Protocols/ProtocolCore/BaseProtocol.cs @@ -56,7 +56,7 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore /// /// - Initial /// - public void Dispose() + public virtual void Dispose() { //Cancel receive tokens _decodingToken.Cancel(); diff --git a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs index 032d85bb..020de730 100644 --- a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs +++ b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs @@ -69,6 +69,42 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// public Boolean QualityWatchMode; + /// + /// Represent FW version + /// + public String FwVersion + { + get; + private set; + } = "?"; + + /// + /// Represent meter size in mm + /// + public Int32 MeterSize_mm + { + get; + private set; + } + + /// + /// Represent FW version + /// + public String FwBuildDate + { + get; + private set; + } = "?"; + + /// + /// Represent FW GIT hash + /// + public String FwGitHash + { + get; + private set; + } = "?"; + /// /// Represent pcb serial number /// @@ -189,6 +225,12 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore } } + public Boolean IsLoggedOn + { + private set; + get; + } + /// public ErrorState ErrorStatus { @@ -221,11 +263,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore //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 @@ -359,7 +399,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore return; } _streamingDecoder = new StreamingDecoder(false); - if (StreamingPort == null || !(StreamingPort is LedSerialPort)) + if (!(StreamingPort is LedSerialPort)) { throw new ApplicationException("No valid streaming port"); } @@ -415,7 +455,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// public MagFluxMeter() { - SetLogger(); } /// @@ -423,6 +462,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore { _logger.Trace($"Slot:{Slot} - Start to dispose"); + StreamingProtocol.OnRecordIsDecoded -= StreamingProtocol_ApplyDecodedRecord; + RequestProtocol.OnRecordIsDecoded -= RequestProtocol_ApplyDecodedRecord; + LogRawData(false); LogManager.Flush(); //isPart of Logout @@ -512,22 +554,24 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore Boolean ignoreCorruptedData = true, String password = "") { Slot = slot; - SetLogger(); + //SetLogger(); _password = password; 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()); - //} + // request port is needed to assign the port name from file, else it is not used + // as the IMagFluxRequestProtocol implements the port handling and communication + RequestPort = new UartSerialPort(requestIdent, requestPort.Value.GetSerialPort(), + TransmitProtocol.GetTransmitPortSettings()); + } } if (streamingPort != null) @@ -541,6 +585,8 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore StreamingProtocol = new StreamingProtocol(streamingIdent, ignoreCorruptedData); } Configuration = new ProcessConfig(ProgramConfig.ConfigFileName); + + SetLogger(); _logger.Debug($"Slot:{Slot} - Setup done"); } @@ -552,9 +598,16 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore { if (RequestPort != null && RequestPort.GetPortName() != BaseSerialPort.PortNotAssigned) { - LinkPortToProtocol(RequestPort, RequestProtocol); - _logger.Trace($"Slot:{Slot} - RequestPort and RequestProtocol linked"); - RequestProtocol.OnRecordIsDecoded += RequestProtocol_ApplyDecodedRecord; + if (RequestProtocol.Connect(RequestPort.GetPortName())) + { + _logger.Trace($"Slot:{Slot} - RequestPort and RequestProtocol linked"); + RequestProtocol.OnRecordIsDecoded += RequestProtocol_ApplyDecodedRecord; + RequestProtocol.CloseConnection(); + } + else + { + _logger.Trace($"Slot:{Slot} - RequestPort Connection failed"); + } } if (StreamingPort != null && StreamingPort.GetPortName() != BaseSerialPort.PortNotAssigned) { @@ -571,7 +624,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// /// On should one once added in runtime /// - public void LinkPortToProtocol(IPort port, IProtocol protocol) + private void LinkPortToProtocol(IPort port, IProtocol protocol) { //for streaming mode only if (port == null) @@ -607,7 +660,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// /// /// - public void SyncStreamingBuffer(SyncMarkRecord markRecord) + private void SyncStreamingBuffer(SyncMarkRecord markRecord) { if (StreamingPort == null) { @@ -641,13 +694,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// /// /// - public void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData, Boolean useRequest, Boolean useStreaming) + private void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData, Boolean useRequest, Boolean useStreaming) { - Slot = slot; - SetLogger(); - - var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(MagFlux), ProgramConfig.SerialConfigFileName); if (!File.Exists(configFile)) @@ -668,7 +717,6 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore throw new ApplicationException($"Slot:{slot} - File " + $"{ProgramConfig.SerialConfigFileName} does not contain valid configuration"); } - _logger.Debug($"Slot:{slot} - Configuration loaded"); if (!useRequest) { SetupMagFluxMeter(slot, null, slotConfig.Streaming, ignoreCorruptedData); @@ -681,18 +729,49 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore { SetupMagFluxMeter(slot, slotConfig.Request, slotConfig.Streaming, ignoreCorruptedData); } + SetLogger(); + _logger.Debug($"Slot:{slot} - Configuration loaded"); } /// public Boolean Logout() { + RequestProtocol.CloseConnection(); + IsLoggedOn = false; return true; } /// public Boolean Login() { - return true; + if (!RequestProtocol.Connect(RequestPort.GetPortName())) return IsLoggedOn; + + IsLoggedOn = true; + if (RequestProtocol.GetFwVersion(out var fwVersion)) + { + FwVersion = fwVersion; + } + if (RequestProtocol.GetFwBuildDate(out var fwBuildDate)) + { + FwBuildDate = fwBuildDate; + } + if (RequestProtocol.GetMeterSize_mm(out var meterSize_mm)) + { + MeterSize_mm = meterSize_mm; + } + if (RequestProtocol.GetFwGitHash(out var gitHash)) + { + FwGitHash = gitHash; + } + if (RequestProtocol.GetSensorSerialNo(out var serialNumber)) + { + SerialNumber = serialNumber; + } + if (RequestProtocol.GetUniqueId(out var pcbId)) + { + PcbId = pcbId; + } + return IsLoggedOn; } /// @@ -716,7 +795,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore } else { - WriteLog($"wait for measurement is starting"); + WriteLog("Wait on measurement start"); } ProcessStatus = ProcessState.WaitForMeasurement; } @@ -994,13 +1073,23 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore if (string.IsNullOrEmpty(CurrentActionText)) { _logger = NLogHelper.CreateOrGetMultiLogger($"Slot:{Slot}", $"", "Meter", "MeterBase", "MeterBase"); - + if (RequestProtocol != null) + { + var path = NLogHelper.GetPath(_logger); + RequestProtocol.SetLogLocation(path); + } } else { var id = !string.IsNullOrEmpty(SerialNumber) ? $"SN{SerialNumber}" : $"PCB{PcbId}"; _logger = NLogHelper.CreateOrGetMultiLogger($"Slot:{Slot}_{id}_{CurrentActionText}", $"Slot", "Meter", "MeterBase", "MeterBase"); + if (RequestProtocol != null) + { + var path = NLogHelper.GetPath(_logger); + RequestProtocol.SetLogLocation(path); + } + if (StreamingPort != null && StreamingPort is LedSerialPort) { var streamingIdent = $"LedRawData_Slot_{Slot}_{id}_{CurrentActionText}"; diff --git a/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs b/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs index 231ee51f..53445606 100644 --- a/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs +++ b/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs @@ -1,5 +1,5 @@ using System; -using modbus_master_csharp.Device; +using XYLEM.Device; using NLog; using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments; using Xylem.Common.Hardware.Interfaces.Protocols.ProtocolCore; @@ -16,14 +16,24 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol { private readonly String _ident; private readonly ILogger _logger; + private IMagFluxRequestProtocol _magFluxProtocol; /// public RequestProtocol(String ident) : base(ident) { _ident = ident; + _magFluxProtocol = new MagFlux6200(); _logger = NLogHelper.CreateOrGetMultiLogger(ident, "", "RequestProtocol", "MeterBase", "MeterBase"); } + /// > + public override void Dispose() + { + _magFluxProtocol?.CloseConnection(); + _magFluxProtocol = null; + base.Dispose(); + } + /// public override event EventHandler OnRecordReadyToSend; @@ -34,5 +44,151 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol { throw new System.NotImplementedException(); } + + /// + /// Wrapper to connect mag flux + /// + /// + /// + /// + /// - Initial + /// + public Boolean Connect(String portName) + { + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.Connect(portName); + return retVal; + } + /// + /// Wrapper to set the log location for MagFlux direct raw output + /// + /// + /// + /// + /// - Initial + /// + public Boolean SetLogLocation(String path) + { + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.SetLogLocation(path); + return retVal; + } + /// + /// Wrapper to connect mag flux + /// + /// + /// + /// - Initial + /// + public Boolean CloseConnection() + { + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.CloseConnection(); + return retVal; + } + /// + /// Wrapper to connect mag flux + /// + /// + /// + /// - Initial + /// + public Boolean IsConnected() + { + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.IsConnected(); + return retVal; + } + /// + /// Wrapper to get FW version + /// + /// + /// + /// + /// - Initial + /// + public Boolean GetFwVersion(out String fwVersion) + { + fwVersion = "?"; + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.GetFirmwareVersion(out fwVersion); + return retVal; + } + + /// + /// Wrapper to get FW GIT hash + /// + /// + /// + /// + /// - Initial + /// + public Boolean GetFwGitHash(out String fwGitHash) + { + fwGitHash = "?"; + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.GetFwGitHash(out fwGitHash); + return retVal; + } + /// + /// Wrapper to get FW Build Date + /// + /// + /// + /// + /// - Initial + /// + public Boolean GetFwBuildDate(out String fwBuildDate) + { + fwBuildDate = "?"; + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.GetFwBuildDate(out fwBuildDate); + return retVal; + } + /// + /// Wrapper to get the sensor serial number + /// + /// + /// + /// + /// - Initial + /// + public Boolean GetSensorSerialNo(out String serialNumber) + { + serialNumber = "?"; + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.GetSensorSerialNo(out serialNumber); + return retVal; + } + /// + /// Wrapper to get unique id referenced as PCBID + /// + /// + /// + /// + /// - Initial + /// + public Boolean GetUniqueId(out String pcbId) + { + pcbId = "?"; + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.GetUniqueId(out pcbId); + return retVal; + } + /// + /// Wrapper to get meter size in mm + /// + /// + /// + /// + /// - Initial + /// + public Boolean GetMeterSize_mm(out Int32 meterSize) + { + meterSize = 0; + if (_magFluxProtocol == null) return false; + var retVal = _magFluxProtocol.GetDn_mm(out meterSize); + return retVal; + } } } diff --git a/Common/Ui/MagFluxToolBox/FrmSetup.cs b/Common/Ui/MagFluxToolBox/FrmSetup.cs index 5a3c268c..c93fa3f4 100644 --- a/Common/Ui/MagFluxToolBox/FrmSetup.cs +++ b/Common/Ui/MagFluxToolBox/FrmSetup.cs @@ -11,7 +11,6 @@ using System.Xml.Linq; using Xylem.Common.CommonCore.Consts; using Xylem.Common.Hardware.Interfaces.Ports.PortCore; using Xylem.Common.Hardware.Interfaces.Ports.SerialPorts; -using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxConfig; using Xylem.Common.Utils.Logging; namespace Xylem.Common.Ui.MagFluxToolBox diff --git a/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs b/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs index 3d0a79f2..5aeca67a 100644 --- a/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs +++ b/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs @@ -30,11 +30,11 @@ { this.components = new System.ComponentModel.Container(); this.grpSetup = new System.Windows.Forms.GroupBox(); - 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(); this.cbComSlot = new System.Windows.Forms.ComboBox(); + this.lblSensorNo = new System.Windows.Forms.Label(); + this.tbxSensorNo = new System.Windows.Forms.TextBox(); this.lblWaitingForMeterResponse = new System.Windows.Forms.Label(); this.lblOverall = new System.Windows.Forms.Label(); this.barSingleProgressUpdate = new System.Windows.Forms.ProgressBar(); @@ -48,42 +48,48 @@ this.lblUpdateTime = new System.Windows.Forms.Label(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.picLogo = new System.Windows.Forms.PictureBox(); - this.grpBoxInfo = new System.Windows.Forms.GroupBox(); + this.grpMeasurements = new System.Windows.Forms.GroupBox(); 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.tbxUniqueId = new System.Windows.Forms.TextBox(); + this.lblUniqueId = new System.Windows.Forms.Label(); + this.grpInfo = new System.Windows.Forms.GroupBox(); + this.lblSensorId = new System.Windows.Forms.Label(); + this.tbxStatus = new System.Windows.Forms.TextBox(); + this.lblStatus = new System.Windows.Forms.Label(); + this.lblFwVersion = new System.Windows.Forms.Label(); + this.tbxFwVersion = new System.Windows.Forms.TextBox(); + this.lblFwBuildDate = new System.Windows.Forms.Label(); + this.tbxFwBuildDate = new System.Windows.Forms.TextBox(); + this.lblFwGitHash = new System.Windows.Forms.Label(); + this.tbxFwGitHash = new System.Windows.Forms.TextBox(); + this.lblMeterSize = new System.Windows.Forms.Label(); + this.tbxMeterSize = new System.Windows.Forms.TextBox(); this.grpSetup.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picLogo)).BeginInit(); - this.grpBoxInfo.SuspendLayout(); + this.grpMeasurements.SuspendLayout(); + this.grpInfo.SuspendLayout(); this.SuspendLayout(); // // grpSetup // - this.grpSetup.Controls.Add(this.tbxSensorNo); this.grpSetup.Controls.Add(this.btnConnect); - this.grpSetup.Controls.Add(this.lblConnectPcb); this.grpSetup.Controls.Add(this.label2); this.grpSetup.Controls.Add(this.cbComSlot); - this.grpSetup.Location = new System.Drawing.Point(100, 5); + this.grpSetup.Controls.Add(this.lblSensorNo); + this.grpSetup.Location = new System.Drawing.Point(100, -1); this.grpSetup.Name = "grpSetup"; - this.grpSetup.Size = new System.Drawing.Size(257, 100); + this.grpSetup.Size = new System.Drawing.Size(214, 102); this.grpSetup.TabIndex = 24; this.grpSetup.TabStop = false; this.grpSetup.Text = "Setup"; // - // tbxSensorNo - // - 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 // - this.btnConnect.Location = new System.Drawing.Point(128, 24); + this.btnConnect.Location = new System.Drawing.Point(86, 71); this.btnConnect.Name = "btnConnect"; this.btnConnect.Size = new System.Drawing.Size(116, 25); this.btnConnect.TabIndex = 24; @@ -91,19 +97,10 @@ this.btnConnect.UseVisualStyleBackColor = true; this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click); // - // lblConnectPcb - // - this.lblConnectPcb.AutoSize = true; - this.lblConnectPcb.Location = new System.Drawing.Point(10, 62); - this.lblConnectPcb.Name = "lblConnectPcb"; - this.lblConnectPcb.Size = new System.Drawing.Size(33, 13); - this.lblConnectPcb.TabIndex = 23; - this.lblConnectPcb.Text = "NOT "; - // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(10, 30); + this.label2.Location = new System.Drawing.Point(9, 77); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(28, 13); this.label2.TabIndex = 20; @@ -133,13 +130,30 @@ "18", "19", "20"}); - this.cbComSlot.Location = new System.Drawing.Point(44, 27); + this.cbComSlot.Location = new System.Drawing.Point(43, 73); this.cbComSlot.Name = "cbComSlot"; this.cbComSlot.Size = new System.Drawing.Size(37, 21); this.cbComSlot.TabIndex = 5; this.cbComSlot.Text = "1"; this.cbComSlot.SelectedIndexChanged += new System.EventHandler(this.cbComSlot_SelectedIndexChanged); // + // lblSensorNo + // + this.lblSensorNo.AutoSize = true; + this.lblSensorNo.Location = new System.Drawing.Point(9, 20); + this.lblSensorNo.Name = "lblSensorNo"; + this.lblSensorNo.Size = new System.Drawing.Size(33, 13); + this.lblSensorNo.TabIndex = 23; + this.lblSensorNo.Text = "NOT "; + // + // tbxSensorNo + // + this.tbxSensorNo.Location = new System.Drawing.Point(103, 45); + this.tbxSensorNo.Name = "tbxSensorNo"; + this.tbxSensorNo.ReadOnly = true; + this.tbxSensorNo.Size = new System.Drawing.Size(116, 20); + this.tbxSensorNo.TabIndex = 32; + // // lblWaitingForMeterResponse // this.lblWaitingForMeterResponse.AutoSize = true; @@ -229,7 +243,7 @@ // this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox1.Image = global::Xylem.Common.Ui.MagFluxToolBox.Properties.Resources.MagFluxVerySmall; - this.pictureBox1.Location = new System.Drawing.Point(9, 9); + this.pictureBox1.Location = new System.Drawing.Point(9, 5); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(85, 96); this.pictureBox1.TabIndex = 33; @@ -246,22 +260,24 @@ this.picLogo.TabIndex = 34; this.picLogo.TabStop = false; // - // grpBoxInfo + // grpMeasurements // - 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); - this.grpBoxInfo.Name = "grpBoxInfo"; - this.grpBoxInfo.Size = new System.Drawing.Size(348, 228); - this.grpBoxInfo.TabIndex = 37; - this.grpBoxInfo.TabStop = false; - this.grpBoxInfo.Text = "Measurements"; + this.grpMeasurements.Controls.Add(this.tbxStatus); + this.grpMeasurements.Controls.Add(this.lblStatus); + this.grpMeasurements.Controls.Add(this.tbxVolume); + this.grpMeasurements.Controls.Add(this.tbxFlowRate); + this.grpMeasurements.Controls.Add(this.label7); + this.grpMeasurements.Controls.Add(this.label11); + this.grpMeasurements.Location = new System.Drawing.Point(320, -1); + this.grpMeasurements.Name = "grpMeasurements"; + this.grpMeasurements.Size = new System.Drawing.Size(203, 102); + this.grpMeasurements.TabIndex = 37; + this.grpMeasurements.TabStop = false; + this.grpMeasurements.Text = "Measurements"; // // tbxVolume // - this.tbxVolume.Location = new System.Drawing.Point(124, 22); + this.tbxVolume.Location = new System.Drawing.Point(114, 17); this.tbxVolume.Name = "tbxVolume"; this.tbxVolume.ReadOnly = true; this.tbxVolume.Size = new System.Drawing.Size(68, 20); @@ -269,7 +285,7 @@ // // tbxFlowRate // - this.tbxFlowRate.Location = new System.Drawing.Point(124, 52); + this.tbxFlowRate.Location = new System.Drawing.Point(114, 47); this.tbxFlowRate.Name = "tbxFlowRate"; this.tbxFlowRate.ReadOnly = true; this.tbxFlowRate.Size = new System.Drawing.Size(68, 20); @@ -278,20 +294,152 @@ // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(6, 56); + this.label7.Location = new System.Drawing.Point(6, 50); this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(92, 13); + this.label7.Size = new System.Drawing.Size(89, 13); this.label7.TabIndex = 27; - this.label7.Text = "Flow Rate [cm/h]:"; + this.label7.Text = "Flow Rate [m²/h]:"; // // label11 // this.label11.AutoSize = true; - this.label11.Location = new System.Drawing.Point(6, 26); + this.label11.Location = new System.Drawing.Point(6, 20); this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(68, 13); + this.label11.Size = new System.Drawing.Size(65, 13); this.label11.TabIndex = 25; - this.label11.Text = "Volume [cm]:"; + this.label11.Text = "Volume [m²]:"; + // + // tbxUniqueId + // + this.tbxUniqueId.Location = new System.Drawing.Point(103, 20); + this.tbxUniqueId.Name = "tbxUniqueId"; + this.tbxUniqueId.ReadOnly = true; + this.tbxUniqueId.Size = new System.Drawing.Size(190, 20); + this.tbxUniqueId.TabIndex = 34; + // + // lblUniqueId + // + this.lblUniqueId.AutoSize = true; + this.lblUniqueId.Location = new System.Drawing.Point(3, 23); + this.lblUniqueId.Name = "lblUniqueId"; + this.lblUniqueId.Size = new System.Drawing.Size(58, 13); + this.lblUniqueId.TabIndex = 35; + this.lblUniqueId.Text = "Unique ID:"; + // + // grpInfo + // + this.grpInfo.Controls.Add(this.lblMeterSize); + this.grpInfo.Controls.Add(this.tbxMeterSize); + this.grpInfo.Controls.Add(this.lblFwGitHash); + this.grpInfo.Controls.Add(this.tbxFwGitHash); + this.grpInfo.Controls.Add(this.lblFwBuildDate); + this.grpInfo.Controls.Add(this.tbxFwBuildDate); + this.grpInfo.Controls.Add(this.lblFwVersion); + this.grpInfo.Controls.Add(this.tbxFwVersion); + this.grpInfo.Controls.Add(this.lblSensorId); + this.grpInfo.Controls.Add(this.tbxUniqueId); + this.grpInfo.Controls.Add(this.tbxSensorNo); + this.grpInfo.Controls.Add(this.lblUniqueId); + this.grpInfo.Location = new System.Drawing.Point(9, 107); + this.grpInfo.Name = "grpInfo"; + this.grpInfo.Size = new System.Drawing.Size(305, 232); + this.grpInfo.TabIndex = 25; + this.grpInfo.TabStop = false; + this.grpInfo.Text = "Info"; + // + // lblSensorId + // + this.lblSensorId.AutoSize = true; + this.lblSensorId.Location = new System.Drawing.Point(4, 48); + this.lblSensorId.Name = "lblSensorId"; + this.lblSensorId.Size = new System.Drawing.Size(57, 13); + this.lblSensorId.TabIndex = 36; + this.lblSensorId.Text = "Sensor ID:"; + // + // tbxStatus + // + this.tbxStatus.Location = new System.Drawing.Point(114, 74); + this.tbxStatus.Name = "tbxStatus"; + this.tbxStatus.ReadOnly = true; + this.tbxStatus.Size = new System.Drawing.Size(68, 20); + this.tbxStatus.TabIndex = 33; + // + // lblStatus + // + this.lblStatus.AutoSize = true; + this.lblStatus.Location = new System.Drawing.Point(6, 77); + this.lblStatus.Name = "lblStatus"; + this.lblStatus.Size = new System.Drawing.Size(40, 13); + this.lblStatus.TabIndex = 32; + this.lblStatus.Text = "Status:"; + // + // lblFwVersion + // + this.lblFwVersion.AutoSize = true; + this.lblFwVersion.Location = new System.Drawing.Point(4, 73); + this.lblFwVersion.Name = "lblFwVersion"; + this.lblFwVersion.Size = new System.Drawing.Size(65, 13); + this.lblFwVersion.TabIndex = 38; + this.lblFwVersion.Text = "FW Version:"; + // + // tbxFwVersion + // + this.tbxFwVersion.Location = new System.Drawing.Point(103, 70); + this.tbxFwVersion.Name = "tbxFwVersion"; + this.tbxFwVersion.ReadOnly = true; + this.tbxFwVersion.Size = new System.Drawing.Size(116, 20); + this.tbxFwVersion.TabIndex = 37; + // + // lblFwBuildDate + // + this.lblFwBuildDate.AutoSize = true; + this.lblFwBuildDate.Location = new System.Drawing.Point(4, 98); + this.lblFwBuildDate.Name = "lblFwBuildDate"; + this.lblFwBuildDate.Size = new System.Drawing.Size(79, 13); + this.lblFwBuildDate.TabIndex = 40; + this.lblFwBuildDate.Text = "FW Build Date:"; + // + // tbxFwBuildDate + // + this.tbxFwBuildDate.Location = new System.Drawing.Point(103, 95); + this.tbxFwBuildDate.Name = "tbxFwBuildDate"; + this.tbxFwBuildDate.ReadOnly = true; + this.tbxFwBuildDate.Size = new System.Drawing.Size(116, 20); + this.tbxFwBuildDate.TabIndex = 39; + // + // lblFwGitHash + // + this.lblFwGitHash.AutoSize = true; + this.lblFwGitHash.Location = new System.Drawing.Point(6, 123); + this.lblFwGitHash.Name = "lblFwGitHash"; + this.lblFwGitHash.Size = new System.Drawing.Size(76, 13); + this.lblFwGitHash.TabIndex = 42; + this.lblFwGitHash.Text = "FW GIT Hash:"; + // + // tbxFwGitHash + // + this.tbxFwGitHash.Location = new System.Drawing.Point(103, 120); + this.tbxFwGitHash.Name = "tbxFwGitHash"; + this.tbxFwGitHash.ReadOnly = true; + this.tbxFwGitHash.Size = new System.Drawing.Size(116, 20); + this.tbxFwGitHash.TabIndex = 41; + // + // lblMeterSize + // + this.lblMeterSize.AutoSize = true; + this.lblMeterSize.Location = new System.Drawing.Point(4, 148); + this.lblMeterSize.Name = "lblMeterSize"; + this.lblMeterSize.Size = new System.Drawing.Size(85, 13); + this.lblMeterSize.TabIndex = 44; + this.lblMeterSize.Text = "Meter Size [DN]:"; + // + // tbxMeterSize + // + this.tbxMeterSize.Location = new System.Drawing.Point(103, 145); + this.tbxMeterSize.Name = "tbxMeterSize"; + this.tbxMeterSize.ReadOnly = true; + this.tbxMeterSize.Size = new System.Drawing.Size(116, 20); + this.tbxMeterSize.TabIndex = 43; // // FrmTest // @@ -299,11 +447,12 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(723, 432); - this.Controls.Add(this.grpBoxInfo); + this.Controls.Add(this.grpInfo); + this.Controls.Add(this.grpMeasurements); this.Controls.Add(this.picLogo); - this.Controls.Add(this.pictureBox1); this.Controls.Add(this.lblUpdateTime); this.Controls.Add(this.label9); + this.Controls.Add(this.pictureBox1); this.Controls.Add(this.lblWaitingForMeterResponse); this.Controls.Add(this.lblOverall); this.Controls.Add(this.lblFwUpdateInfo); @@ -323,8 +472,10 @@ this.grpSetup.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picLogo)).EndInit(); - this.grpBoxInfo.ResumeLayout(false); - this.grpBoxInfo.PerformLayout(); + this.grpMeasurements.ResumeLayout(false); + this.grpMeasurements.PerformLayout(); + this.grpInfo.ResumeLayout(false); + this.grpInfo.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -334,7 +485,7 @@ private System.Windows.Forms.GroupBox grpSetup; private System.Windows.Forms.Button btnConnect; - private System.Windows.Forms.Label lblConnectPcb; + private System.Windows.Forms.Label lblSensorNo; private System.Windows.Forms.Label label2; private System.Windows.Forms.ComboBox cbComSlot; private System.Windows.Forms.ProgressBar barOverallProgressUpdate; @@ -351,10 +502,24 @@ 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.GroupBox grpMeasurements; private System.Windows.Forms.TextBox tbxVolume; private System.Windows.Forms.TextBox tbxFlowRate; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label11; + private System.Windows.Forms.TextBox tbxUniqueId; + private System.Windows.Forms.Label lblUniqueId; + private System.Windows.Forms.GroupBox grpInfo; + private System.Windows.Forms.Label lblSensorId; + private System.Windows.Forms.TextBox tbxStatus; + private System.Windows.Forms.Label lblStatus; + private System.Windows.Forms.Label lblMeterSize; + private System.Windows.Forms.TextBox tbxMeterSize; + private System.Windows.Forms.Label lblFwGitHash; + private System.Windows.Forms.TextBox tbxFwGitHash; + private System.Windows.Forms.Label lblFwBuildDate; + private System.Windows.Forms.TextBox tbxFwBuildDate; + private System.Windows.Forms.Label lblFwVersion; + private System.Windows.Forms.TextBox tbxFwVersion; } } \ No newline at end of file diff --git a/Common/Ui/MagFluxToolBox/FrmTest.cs b/Common/Ui/MagFluxToolBox/FrmTest.cs index 49085eff..c913c442 100644 --- a/Common/Ui/MagFluxToolBox/FrmTest.cs +++ b/Common/Ui/MagFluxToolBox/FrmTest.cs @@ -5,7 +5,6 @@ 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; @@ -24,10 +23,9 @@ namespace Xylem.Common.Ui.MagFluxToolBox private MagFluxMeter _magFluxMeter; private const String StrConnecting = "Connecting to PCB"; private const String StrNotConnected = "NOT CONNECTED"; - private const String StrPartPcbConnected = "PCB ID: "; private const String StrOverallProcess = "Overall Process"; - private String _lastFwUpdateState; + private String _lastState; private Int32 _lastSingleProgress; private DateTimeOffset _startTime; private Boolean _resetTimeMeasurement; @@ -40,6 +38,9 @@ namespace Xylem.Common.Ui.MagFluxToolBox private readonly Version _version; + // marker for initial connection to update information just needed once + private Boolean _initialConnect; + // status information private static readonly Color ColorDefault = Color.Black; private static readonly Color ColorSuccess = Color.Green; @@ -72,12 +73,12 @@ namespace Xylem.Common.Ui.MagFluxToolBox private void Init() { ProcessViewControl(false); - lblConnectPcb.Text = StrNotConnected; - lblConnectPcb.ForeColor = Color.Red; + lblSensorNo.Text = StrNotConnected; + lblSensorNo.ForeColor = Color.Red; lblWaitingForMeterResponse.Visible = false; btnConnect.Enabled = true; SetControlDownloadsLocked(); - tbxSensorNo.Visible = false; + _initialConnect = true; } private void FrmTest_Load(Object sender, EventArgs e) @@ -141,9 +142,9 @@ namespace Xylem.Common.Ui.MagFluxToolBox { Invoke(new Action(() => { - tbxSensorNo.Text = e.NewData.SensorId; tbxVolume.Text = $@"{e.NewData.VolumeCm:F3}"; tbxFlowRate.Text = $@"{e.NewData.FlowRateCmPh:F3}"; + tbxStatus.Text = $@"0x{e.NewData.StatusBits:X8}"; })); } @@ -185,42 +186,23 @@ namespace Xylem.Common.Ui.MagFluxToolBox _meterBatch.MetersLogin(); - //if (!_magFluxMeter.IsLoggedOn) - //{ - // //this is needed from meter as an unsuccessfully login requires a delay for the next trial - // Thread.Sleep(2000); - // _meterBatch.MetersLogin(); - //} - - //if (!_magFluxMeter.IsLoggedOn) - //{ - // return; - //} - Invoke(new Action(() => { - //lblConnectPcb.Text = StrPartPcbConnected; - //tbxPcbId.Text = _magFluxMeter.PcbId; - //tbxPcbId.Visible = true; - //tbxMeterFw.Text = _magFluxMeter.FwVersion; - //tbxMeterMeterSize.Text = _magFluxMeter.MeterSize; - //tbxMeterLutCrc.Text = _magFluxMeter.LutCrc; - //tbxRegion.Text = _magFluxMeter.Region; - //LogText("Meter FW Version: " + _magFluxMeter.FwVersion); - //LogText("Meter LUT CRC: " + _magFluxMeter.LutCrc); - //LogText("Meter Size: " + _magFluxMeter.MeterSize); - //LogText("Meter Region: " + _magFluxMeter.Region); - //if (_magFluxMeter.RadioFrequencyMhz != null) - //{ - // tbxRadio.Text = $@"{_magFluxMeter.RadioFrequencyMhz}"; - // LogText($"Meter radio frequency [MHz]: {_magFluxMeter.RadioFrequencyMhz}"); - //} - - lblConnectPcb.ForeColor = Color.Green; - CheckUpdateEnabled(); - _magFluxMeter.StartStreamingCatcher(); - _magFluxMeter.Logout(); - LogInstalledMeterFw(); + if (_magFluxMeter != null && _magFluxMeter.IsLoggedOn) + { + lblSensorNo.Text = ""; + tbxUniqueId.Text = _magFluxMeter.PcbId; + tbxSensorNo.Text = _magFluxMeter.SerialNumber; + tbxFwVersion.Text = _magFluxMeter.FwVersion; + tbxFwBuildDate.Text = _magFluxMeter.FwBuildDate; + tbxFwGitHash.Text = _magFluxMeter.FwGitHash; + tbxMeterSize.Text = _magFluxMeter.MeterSize_mm.ToString(); + lblSensorNo.ForeColor = Color.Green; + CheckUpdateEnabled(); + _magFluxMeter.StartStreamingCatcher(); + _magFluxMeter.Logout(); + LogInstalledMeterFw(); + } })); }).ContinueWith(delegate { @@ -272,7 +254,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox lblOverall.Visible = true; barOverallProgressUpdate.Visible = true; barSingleProgressUpdate.Visible = true; - _lastFwUpdateState = ""; + _lastState = ""; tmrProgressUpdate.Enabled = true; } else @@ -282,7 +264,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox barOverallProgressUpdate.Visible = false; barSingleProgressUpdate.Visible = false; tmrProgressUpdate.Enabled = false; - _lastFwUpdateState = ""; + _lastState = ""; lblWaitingForMeterResponse.Visible = false; lblActualProcess.Text = ""; lblOverall.Text = ""; @@ -317,10 +299,10 @@ namespace Xylem.Common.Ui.MagFluxToolBox //// update the display of the meter size, LUT CRC and region //tbxMeterFw.Text = _magFluxMeter.FwVersion; - //tbxMeterMeterSize.Text = _magFluxMeter.MeterSize; + //tbxMeterMeterSize.Text = _magFluxMeter.MeterSize_mm; //tbxMeterLutCrc.Text = _magFluxMeter.LutCrc; //tbxRegion.Text = _magFluxMeter.Region; - + //if (!_lutFileSuccessfulWritten) //{ // lblLutFileLoadedInfo.ForeColor = Color.Red; @@ -436,7 +418,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox private void CheckUpdateEnabled() { //this check has been placed here to force display update - if (_magFluxMeter != null ) + if (_magFluxMeter != null) { SetControlsDownloadEnabled(); return; @@ -486,9 +468,9 @@ namespace Xylem.Common.Ui.MagFluxToolBox //barOverallProgressUpdate.Update(); //var singleProgress = (Int32)(_meterLutUpdate?.SingleFileProcessCtrPercent ?? 0); - //if (_meterLutUpdate?.GetActualOperation() != _lastFwUpdateState) + //if (_meterLutUpdate?.GetActualOperation() != _lastState) //{ - // _lastFwUpdateState = _meterLutUpdate?.GetActualOperation(); + // _lastState = _meterLutUpdate?.GetActualOperation(); // lblWaitingForMeterResponse.Visible = false; //} //else @@ -524,13 +506,13 @@ namespace Xylem.Common.Ui.MagFluxToolBox } /// - /// Download LUT file + /// Download calibration to MagFlux /// /// /// - private void btnDownloadLutFile_Click(Object sender, EventArgs e) + private void btnDownloadCalibration_Click(Object sender, EventArgs e) { - if (_magFluxMeter == null ) + if (_magFluxMeter == null) { return; } @@ -588,10 +570,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox } } - #endregion - - } }