diff --git a/.gitignore b/.gitignore index 753dd6452..aa8441b67 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ Config/bin/ Config/obj/ DataStreamInterface/bin/ DataStreamInterface/obj/ +DataStreamInterfaceTest/bin/ +DataStreamInterfaceTest/obj/ +DataStreamMeter/bin/ +DataStreamMeter/obj/ Decrypt/bin/ Decrypt/obj/ DeviceTest/bin/ diff --git a/Config/Units.cs b/Config/Units.cs index 429be1ad0..0ae42b165 100644 --- a/Config/Units.cs +++ b/Config/Units.cs @@ -385,7 +385,7 @@ namespace Config case Unit.lph: return 1000 * v; /// 1 l/h case Unit.lpm: return v / 0.06; /// 1 l/m case Unit.lps: return v / 3.6; /// 1 l/s - case Unit.USgalps: return 0.733811257326 * v; /// 1 US gallon per second + case Unit.USgalps: return 0.0733811257326 * v; /// 1 US gallon per second case Unit.m3pm: return v / 60; /// 1 m3/m case Unit.cfs: return 0.009809629644858 * v; /// 1 cubic foot per second diff --git a/DataStreamInterface/DataFrame.cs b/DataStreamInterface/DataFrame.cs index 6338df650..2f5835223 100644 --- a/DataStreamInterface/DataFrame.cs +++ b/DataStreamInterface/DataFrame.cs @@ -7,12 +7,12 @@ namespace DataStreamInterface { public class DataFrame { - public readonly UInt64 ID; /// Frame ID + public readonly Int64 ID; /// Frame ID public readonly double Time; /// Time stamp in units of time public readonly double Volume; /// Volume in units of volume public readonly double[] Quantity; /// An array of optional quantities in their respective units - public DataFrame(UInt64 id, double time, double volume, double[] quantity) + public DataFrame(Int64 id, double time, double volume, double[] quantity) { ID = id; Time = time; diff --git a/DataStreamInterface/DataStreamInterface.csproj b/DataStreamInterface/DataStreamInterface.csproj index 49ae9f254..df67cc35b 100644 --- a/DataStreamInterface/DataStreamInterface.csproj +++ b/DataStreamInterface/DataStreamInterface.csproj @@ -9,7 +9,7 @@ Properties DataStreamInterface DataStreamInterface - v4.0 + v4.7.2 512 @@ -21,6 +21,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -29,9 +30,11 @@ TRACE prompt 4 + false + diff --git a/DataStreamInterface/Doc/Software interface for datastream water meters.docx b/DataStreamInterface/Doc/Software interface for datastream water meters.docx index 09770fbc1..2fdd60f86 100644 Binary files a/DataStreamInterface/Doc/Software interface for datastream water meters.docx and b/DataStreamInterface/Doc/Software interface for datastream water meters.docx differ diff --git a/DataStreamInterface/Enums.cs b/DataStreamInterface/Enums.cs index 688d8fce6..d13d6f9ad 100644 --- a/DataStreamInterface/Enums.cs +++ b/DataStreamInterface/Enums.cs @@ -259,7 +259,7 @@ namespace DataStreamInterface case Unit.lph: return 1000 * v; /// 1 l/h case Unit.lpm: return v / 0.06; /// 1 l/m case Unit.lps: return v / 3.6; /// 1 l/s - case Unit.USgalps: return 0.733811257326 * v; /// 1 US gallon per second + case Unit.USgalps: return 0.0733811257326 * v; /// 1 US gallon per second case Unit.m3pm: return v / 60; /// 1 m3/m case Unit.cfs: return 0.009809629644858 * v; /// 1 cubic foot per second diff --git a/DataStreamInterface/IDataStreamMeter.cs b/DataStreamInterface/IDataStreamMeter.cs index 6255b1b0a..922af4ec4 100644 --- a/DataStreamInterface/IDataStreamMeter.cs +++ b/DataStreamInterface/IDataStreamMeter.cs @@ -2,10 +2,6 @@ /// Copyright (c) 2020 Sensus Slovensko a.s. /// using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace DataStreamInterface { @@ -51,9 +47,9 @@ namespace DataStreamInterface /// Stops saving measurement results into internal data structures of the component. /// Updates ID of the last date frame received from the meter. /// - /// ID of the last date frame + /// Number of stored date frames /// true when successful - bool StopMeasurement(out UInt64 lastFrameID); + bool StopMeasurement(out Int64 storedFramesCount); ///------------------------------------------------ /// Units of time, volume and optional quantities @@ -70,7 +66,7 @@ namespace DataStreamInterface Unit GetVolumeUnits(); ///----------------------------------------------- - /// Ooptional quantities: count, units, captions + /// Optional quantities: count, units, captions ///----------------------------------------------- /// @@ -83,13 +79,13 @@ namespace DataStreamInterface /// Returns units of the specified quantity /// /// Zero based quantity number 0 .. quantites count-1 - Unit GetQuantityUnits(int quanityNr); + Unit GetQuantityUnits(int quantityNr); /// /// Returns caption of the specified quantity /// /// Zero based quantity number 0 .. quantites count-1 - string GetQuantityCaption(int quanityNr); + string GetQuantityCaption(int quantityNr); ///--------------------------- /// Datastream data exchange @@ -101,7 +97,7 @@ namespace DataStreamInterface /// First frame ID /// Frames count /// Selected data frames - DataFrame[] GetFrames(UInt64 id, int count); + DataFrame[] GetFrames(Int64 id, int count); /// /// Returns ID of the data frame where time equals or exceeds the specified time. @@ -109,6 +105,6 @@ namespace DataStreamInterface /// /// Time /// ID of the data frame at or after the pecified time - UInt64 GetID(double time); + Int64 GetID(double time); } } diff --git a/DataStreamInterfaceTest/ActivityLog.cs b/DataStreamInterfaceTest/ActivityLog.cs new file mode 100644 index 000000000..fe9e0c701 --- /dev/null +++ b/DataStreamInterfaceTest/ActivityLog.cs @@ -0,0 +1,36 @@ +using System; +using System.Text; +using System.Windows.Forms; + +namespace DataStreamInterfaceTest +{ + public class ActivityLog + { + const int LinesCount = 50; + + TextBox textBox; + string[] lines; + string activity; + + public ActivityLog(TextBox textBox) + { + this.textBox = textBox; + lines = new string[LinesCount]; + for (int i = 0; i < LinesCount; i++) lines[i] = string.Empty; + } + + public void Print(string log) + { + for (int i = LinesCount - 1; i > 0; i--) lines[i] = lines[i - 1]; + lines[0] = log; + DisplayLines(); + } + + private void DisplayLines() + { + StringBuilder sb = new StringBuilder(); + foreach (var line in lines) sb.AppendLine(line); + textBox.Text = sb.ToString(); + } + } +} diff --git a/DataStreamInterfaceTest/App.config b/DataStreamInterfaceTest/App.config new file mode 100644 index 000000000..56efbc7b5 --- /dev/null +++ b/DataStreamInterfaceTest/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/DataStreamInterfaceTest.csproj b/DataStreamInterfaceTest/DataStreamInterfaceTest.csproj new file mode 100644 index 000000000..2335e07f1 --- /dev/null +++ b/DataStreamInterfaceTest/DataStreamInterfaceTest.csproj @@ -0,0 +1,134 @@ + + + + + Debug + AnyCPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23} + WinExe + Properties + DataStreamInterfaceTest + DataStreamInterfaceTest + v4.7.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + Form + + + DemoMainWnd.cs + + + Form + + + GetDblValueDlg.cs + + + Form + + + GetFrameBoundariesDlg.cs + + + Form + + + GetIntegerNumberDlg.cs + + + Form + + + GetStateDlg.cs + + + + + + DemoMainWnd.cs + Designer + + + GetDblValueDlg.cs + + + GetFrameBoundariesDlg.cs + + + GetIntegerNumberDlg.cs + + + GetStateDlg.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {7ebeea14-91c4-48d7-af0a-7a4bc3ff9a28} + DataStreamInterface + + + + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/DemoMainWnd.Designer.cs b/DataStreamInterfaceTest/DemoMainWnd.Designer.cs new file mode 100644 index 000000000..f87a15e46 --- /dev/null +++ b/DataStreamInterfaceTest/DemoMainWnd.Designer.cs @@ -0,0 +1,379 @@ +namespace DataStreamInterfaceTest +{ + partial class DemoMainWnd + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.getIDButton = new System.Windows.Forms.Button(); + this.getFramesButton = new System.Windows.Forms.Button(); + this.measurementLabel = new System.Windows.Forms.Label(); + this.stateLabel = new System.Windows.Forms.Label(); + this.capabilitiesLabel = new System.Windows.Forms.Label(); + this.getQuantityUnitsButton = new System.Windows.Forms.Button(); + this.getQuantityCaptionButton = new System.Windows.Forms.Button(); + this.getQuantitiesCountButton = new System.Windows.Forms.Button(); + this.getVolumeUnitsButton = new System.Windows.Forms.Button(); + this.getTimeUnitsButton = new System.Windows.Forms.Button(); + this.setStateButton = new System.Windows.Forms.Button(); + this.getStateButton = new System.Windows.Forms.Button(); + this.stopMeasurementButton = new System.Windows.Forms.Button(); + this.startMeasurementButton = new System.Windows.Forms.Button(); + this.closeConnectionButton = new System.Windows.Forms.Button(); + this.openConnectionButton = new System.Windows.Forms.Button(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.logsTextBox = new System.Windows.Forms.TextBox(); + this.dataTabControl = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.framesListView = new System.Windows.Forms.ListView(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + this.dataTabControl.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer1.IsSplitterFixed = true; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.getIDButton); + this.splitContainer1.Panel1.Controls.Add(this.getFramesButton); + this.splitContainer1.Panel1.Controls.Add(this.measurementLabel); + this.splitContainer1.Panel1.Controls.Add(this.stateLabel); + this.splitContainer1.Panel1.Controls.Add(this.capabilitiesLabel); + this.splitContainer1.Panel1.Controls.Add(this.getQuantityUnitsButton); + this.splitContainer1.Panel1.Controls.Add(this.getQuantityCaptionButton); + this.splitContainer1.Panel1.Controls.Add(this.getQuantitiesCountButton); + this.splitContainer1.Panel1.Controls.Add(this.getVolumeUnitsButton); + this.splitContainer1.Panel1.Controls.Add(this.getTimeUnitsButton); + this.splitContainer1.Panel1.Controls.Add(this.setStateButton); + this.splitContainer1.Panel1.Controls.Add(this.getStateButton); + this.splitContainer1.Panel1.Controls.Add(this.stopMeasurementButton); + this.splitContainer1.Panel1.Controls.Add(this.startMeasurementButton); + this.splitContainer1.Panel1.Controls.Add(this.closeConnectionButton); + this.splitContainer1.Panel1.Controls.Add(this.openConnectionButton); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.splitContainer2); + this.splitContainer1.Size = new System.Drawing.Size(826, 583); + this.splitContainer1.SplitterDistance = 150; + this.splitContainer1.TabIndex = 0; + // + // getIDButton + // + this.getIDButton.Location = new System.Drawing.Point(12, 480); + this.getIDButton.Name = "getIDButton"; + this.getIDButton.Size = new System.Drawing.Size(128, 24); + this.getIDButton.TabIndex = 12; + this.getIDButton.Text = "Get ID"; + this.getIDButton.UseVisualStyleBackColor = true; + this.getIDButton.Click += new System.EventHandler(this.getIDButton_Click); + // + // getFramesButton + // + this.getFramesButton.Location = new System.Drawing.Point(12, 450); + this.getFramesButton.Name = "getFramesButton"; + this.getFramesButton.Size = new System.Drawing.Size(128, 24); + this.getFramesButton.TabIndex = 11; + this.getFramesButton.Text = "Get frames"; + this.getFramesButton.UseVisualStyleBackColor = true; + this.getFramesButton.Click += new System.EventHandler(this.getFramesButton_Click); + // + // measurementLabel + // + this.measurementLabel.AutoSize = true; + this.measurementLabel.Location = new System.Drawing.Point(12, 374); + this.measurementLabel.Name = "measurementLabel"; + this.measurementLabel.Size = new System.Drawing.Size(74, 13); + this.measurementLabel.TabIndex = 15; + this.measurementLabel.Text = "Measurement:"; + // + // stateLabel + // + this.stateLabel.AutoSize = true; + this.stateLabel.Location = new System.Drawing.Point(12, 194); + this.stateLabel.Name = "stateLabel"; + this.stateLabel.Size = new System.Drawing.Size(112, 13); + this.stateLabel.TabIndex = 14; + this.stateLabel.Text = "State and connection:"; + // + // capabilitiesLabel + // + this.capabilitiesLabel.AutoSize = true; + this.capabilitiesLabel.Location = new System.Drawing.Point(12, 9); + this.capabilitiesLabel.Name = "capabilitiesLabel"; + this.capabilitiesLabel.Size = new System.Drawing.Size(63, 13); + this.capabilitiesLabel.TabIndex = 13; + this.capabilitiesLabel.Text = "Capabilities:"; + // + // getQuantityUnitsButton + // + this.getQuantityUnitsButton.Location = new System.Drawing.Point(12, 145); + this.getQuantityUnitsButton.Name = "getQuantityUnitsButton"; + this.getQuantityUnitsButton.Size = new System.Drawing.Size(128, 24); + this.getQuantityUnitsButton.TabIndex = 4; + this.getQuantityUnitsButton.Text = "Get quantity units"; + this.getQuantityUnitsButton.UseVisualStyleBackColor = true; + this.getQuantityUnitsButton.Click += new System.EventHandler(this.getQuantityUnitsButton_Click); + // + // getQuantityCaptionButton + // + this.getQuantityCaptionButton.Location = new System.Drawing.Point(12, 115); + this.getQuantityCaptionButton.Name = "getQuantityCaptionButton"; + this.getQuantityCaptionButton.Size = new System.Drawing.Size(128, 24); + this.getQuantityCaptionButton.TabIndex = 3; + this.getQuantityCaptionButton.Text = "Get quantity caption"; + this.getQuantityCaptionButton.UseVisualStyleBackColor = true; + this.getQuantityCaptionButton.Click += new System.EventHandler(this.getQuantityCaptionButton_Click); + // + // getQuantitiesCountButton + // + this.getQuantitiesCountButton.Location = new System.Drawing.Point(12, 85); + this.getQuantitiesCountButton.Name = "getQuantitiesCountButton"; + this.getQuantitiesCountButton.Size = new System.Drawing.Size(128, 24); + this.getQuantitiesCountButton.TabIndex = 2; + this.getQuantitiesCountButton.Text = "Get quantities count"; + this.getQuantitiesCountButton.UseVisualStyleBackColor = true; + this.getQuantitiesCountButton.Click += new System.EventHandler(this.getQuantitiesCountButton_Click); + // + // getVolumeUnitsButton + // + this.getVolumeUnitsButton.Location = new System.Drawing.Point(12, 55); + this.getVolumeUnitsButton.Name = "getVolumeUnitsButton"; + this.getVolumeUnitsButton.Size = new System.Drawing.Size(128, 24); + this.getVolumeUnitsButton.TabIndex = 1; + this.getVolumeUnitsButton.Text = "Get volume units"; + this.getVolumeUnitsButton.UseVisualStyleBackColor = true; + this.getVolumeUnitsButton.Click += new System.EventHandler(this.getVolumeUnitsButton_Click); + // + // getTimeUnitsButton + // + this.getTimeUnitsButton.Location = new System.Drawing.Point(12, 25); + this.getTimeUnitsButton.Name = "getTimeUnitsButton"; + this.getTimeUnitsButton.Size = new System.Drawing.Size(128, 24); + this.getTimeUnitsButton.TabIndex = 0; + this.getTimeUnitsButton.Text = "Get time units"; + this.getTimeUnitsButton.UseVisualStyleBackColor = true; + this.getTimeUnitsButton.Click += new System.EventHandler(this.getTimeUnitsButton_Click); + // + // setStateButton + // + this.setStateButton.Location = new System.Drawing.Point(12, 315); + this.setStateButton.Name = "setStateButton"; + this.setStateButton.Size = new System.Drawing.Size(128, 24); + this.setStateButton.TabIndex = 8; + this.setStateButton.Text = "Set state"; + this.setStateButton.UseVisualStyleBackColor = true; + this.setStateButton.Click += new System.EventHandler(this.setStateButton_Click); + // + // getStateButton + // + this.getStateButton.Location = new System.Drawing.Point(12, 285); + this.getStateButton.Name = "getStateButton"; + this.getStateButton.Size = new System.Drawing.Size(128, 24); + this.getStateButton.TabIndex = 7; + this.getStateButton.Text = "Get state"; + this.getStateButton.UseVisualStyleBackColor = true; + this.getStateButton.Click += new System.EventHandler(this.getStateButton_Click); + // + // stopMeasurementButton + // + this.stopMeasurementButton.Location = new System.Drawing.Point(12, 420); + this.stopMeasurementButton.Name = "stopMeasurementButton"; + this.stopMeasurementButton.Size = new System.Drawing.Size(128, 24); + this.stopMeasurementButton.TabIndex = 10; + this.stopMeasurementButton.Text = "Stop measurement"; + this.stopMeasurementButton.UseVisualStyleBackColor = true; + this.stopMeasurementButton.Click += new System.EventHandler(this.stopMeasurementButton_Click); + // + // startMeasurementButton + // + this.startMeasurementButton.Location = new System.Drawing.Point(12, 390); + this.startMeasurementButton.Name = "startMeasurementButton"; + this.startMeasurementButton.Size = new System.Drawing.Size(128, 24); + this.startMeasurementButton.TabIndex = 9; + this.startMeasurementButton.Text = "Start measurement"; + this.startMeasurementButton.UseVisualStyleBackColor = true; + this.startMeasurementButton.Click += new System.EventHandler(this.startMeasurementButton_Click); + // + // closeConnectionButton + // + this.closeConnectionButton.Location = new System.Drawing.Point(12, 240); + this.closeConnectionButton.Name = "closeConnectionButton"; + this.closeConnectionButton.Size = new System.Drawing.Size(128, 24); + this.closeConnectionButton.TabIndex = 6; + this.closeConnectionButton.Text = "Close connection"; + this.closeConnectionButton.UseVisualStyleBackColor = true; + this.closeConnectionButton.Click += new System.EventHandler(this.closeConnectionButton_Click); + // + // openConnectionButton + // + this.openConnectionButton.Location = new System.Drawing.Point(12, 210); + this.openConnectionButton.Name = "openConnectionButton"; + this.openConnectionButton.Size = new System.Drawing.Size(128, 24); + this.openConnectionButton.TabIndex = 5; + this.openConnectionButton.Text = "Open connection"; + this.openConnectionButton.UseVisualStyleBackColor = true; + this.openConnectionButton.Click += new System.EventHandler(this.openConnectionButton_Click); + // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.Location = new System.Drawing.Point(0, 0); + this.splitContainer2.Name = "splitContainer2"; + this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.logsTextBox); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.dataTabControl); + this.splitContainer2.Size = new System.Drawing.Size(672, 583); + this.splitContainer2.SplitterDistance = 222; + this.splitContainer2.TabIndex = 0; + // + // logsTextBox + // + this.logsTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.logsTextBox.Location = new System.Drawing.Point(0, 0); + this.logsTextBox.Multiline = true; + this.logsTextBox.Name = "logsTextBox"; + this.logsTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.logsTextBox.Size = new System.Drawing.Size(672, 222); + this.logsTextBox.TabIndex = 0; + // + // dataTabControl + // + this.dataTabControl.Controls.Add(this.tabPage1); + this.dataTabControl.Controls.Add(this.tabPage2); + this.dataTabControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataTabControl.Location = new System.Drawing.Point(0, 0); + this.dataTabControl.Name = "dataTabControl"; + this.dataTabControl.SelectedIndex = 0; + this.dataTabControl.Size = new System.Drawing.Size(672, 357); + this.dataTabControl.TabIndex = 0; + // + // tabPage1 + // + this.tabPage1.Controls.Add(this.framesListView); + this.tabPage1.Location = new System.Drawing.Point(4, 22); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(664, 331); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "Transferred frames"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // tabPage2 + // + this.tabPage2.Location = new System.Drawing.Point(4, 22); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(664, 331); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "Graph"; + this.tabPage2.UseVisualStyleBackColor = true; + // + // framesListView + // + this.framesListView.Dock = System.Windows.Forms.DockStyle.Fill; + this.framesListView.GridLines = true; + this.framesListView.Location = new System.Drawing.Point(3, 3); + this.framesListView.Name = "framesListView"; + this.framesListView.Size = new System.Drawing.Size(658, 325); + this.framesListView.TabIndex = 0; + this.framesListView.UseCompatibleStateImageBehavior = false; + this.framesListView.View = System.Windows.Forms.View.Details; + // + // DemoMainWnd + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(826, 583); + this.Controls.Add(this.splitContainer1); + this.Name = "DemoMainWnd"; + this.Text = "Datastream interface test"; + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel1.PerformLayout(); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + this.dataTabControl.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Button openConnectionButton; + private System.Windows.Forms.Button closeConnectionButton; + private System.Windows.Forms.Button stopMeasurementButton; + private System.Windows.Forms.Button startMeasurementButton; + private System.Windows.Forms.Button setStateButton; + private System.Windows.Forms.Button getStateButton; + private System.Windows.Forms.Button getQuantityUnitsButton; + private System.Windows.Forms.Button getQuantityCaptionButton; + private System.Windows.Forms.Button getQuantitiesCountButton; + private System.Windows.Forms.Button getVolumeUnitsButton; + private System.Windows.Forms.Button getTimeUnitsButton; + private System.Windows.Forms.Label measurementLabel; + private System.Windows.Forms.Label stateLabel; + private System.Windows.Forms.Label capabilitiesLabel; + private System.Windows.Forms.Button getIDButton; + private System.Windows.Forms.Button getFramesButton; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.TextBox logsTextBox; + private System.Windows.Forms.TabControl dataTabControl; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.ListView framesListView; + private System.Windows.Forms.TabPage tabPage2; + } +} + diff --git a/DataStreamInterfaceTest/DemoMainWnd.cs b/DataStreamInterfaceTest/DemoMainWnd.cs new file mode 100644 index 000000000..af1252f38 --- /dev/null +++ b/DataStreamInterfaceTest/DemoMainWnd.cs @@ -0,0 +1,284 @@ +using System; +using System.Text; +using System.Windows.Forms; +using DataStreamInterface; + +namespace DataStreamInterfaceTest +{ + public partial class DemoMainWnd : Form + { + IDataStreamMeter dataStreamMeter; + + ActivityLog activityLog; + + Unit timeUnits; + Unit volumeUnits; + int quantitiesCount; + string[] quantityCaption; + Unit[] quantityUnit; + + Int64 storedFramesCount; + DataFrame[] transferredFrames; + + public DemoMainWnd() : this(null) { } + + public DemoMainWnd(IDataStreamMeter dataStreamMeter) + { + InitializeComponent(); + this.dataStreamMeter = dataStreamMeter; + activityLog = new ActivityLog(logsTextBox); + + framesListView.Columns.Add("ID", 100); + framesListView.Columns.Add("Time", 100); + framesListView.Columns.Add("Volume", 100); + framesListView.Columns.Add("Additional quantities", 300); + framesListView.ListViewItemSorter = new LviIDComparer(); + } + + void ShowNoMeterInterfaceMessage() + { + MessageBox.Show("No datastream meter interface"); + } + + private void getTimeUnitsButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + timeUnits = dataStreamMeter.GetTimeUnits(); + activityLog.Print(string.Format("Time units are {0}", timeUnits)); + } + } + + private void getVolumeUnitsButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + volumeUnits = dataStreamMeter.GetVolumeUnits(); + activityLog.Print(string.Format("Volume units are {0}", volumeUnits)); + } + } + + private void getQuantitiesCountButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + int quantitesCountOri = quantitiesCount; + quantitiesCount = dataStreamMeter.GetQuantitiesCount(); + activityLog.Print(string.Format("There are {0} additional quantites", quantitiesCount)); + + if (quantitesCountOri == 0) + { + quantityUnit = new Unit[quantitiesCount]; + quantityCaption = new string[quantitiesCount]; + for (int i = 0; i < quantitiesCount; i++) quantityCaption[i] = string.Empty; + } + else if (quantitiesCount != quantitesCountOri) + { + quantityUnit = new Unit[quantitiesCount]; + quantityCaption = new string[quantitiesCount]; + for (int i = 0; i < quantitiesCount; i++) quantityCaption[i] = string.Empty; + + activityLog.Print(string.Format("Quantities count changed during operation")); + MessageBox.Show("Quantities count changed during operation", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + private void getQuantityCaptionButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + GetIntegerNumberDlg dlg = new GetIntegerNumberDlg(string.Format("Enter index {0} .. {1}", 0, quantitiesCount - 1), 0, quantitiesCount - 1); + if (dlg.ShowDialog() == DialogResult.OK) + { + quantityCaption[dlg.Number] = dataStreamMeter.GetQuantityCaption(dlg.Number); + activityLog.Print(string.Format("Caption of quantity #{0} is {1}", dlg.Number, quantityCaption[dlg.Number])); + } + } + } + + private void getQuantityUnitsButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + GetIntegerNumberDlg dlg = new GetIntegerNumberDlg(string.Format("Enter index {0} .. {1}", 0, quantitiesCount - 1), 0, quantitiesCount - 1); + if (dlg.ShowDialog() == DialogResult.OK) + { + quantityUnit[dlg.Number] = dataStreamMeter.GetQuantityUnits(dlg.Number); + activityLog.Print(string.Format("Units of quantity #{0} are {1}", dlg.Number, quantityUnit[dlg.Number])); + } + } + } + + private void openConnectionButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + string meterId; + if (dataStreamMeter.OpenConnection("no connection parameters", out meterId)) + { + activityLog.Print(string.Format("Connection established, meter ID is {0}", meterId)); + } + else + { + activityLog.Print("Failed to establish a connection"); + } + } + } + + private void closeConnectionButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + if (dataStreamMeter.CloseConnection()) + { + framesListView.Items.Clear(); + activityLog.Print("Connection closed"); + } + else + { + activityLog.Print("Failed to close the connection"); + } + } + } + + private void getStateButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + int state; + string parameter; + if (dataStreamMeter.GetState(out state, out parameter)) + { + activityLog.Print(string.Format("Water meter state is {0} / {1}", state, parameter)); + } + else + { + activityLog.Print("Failed to obtain the water meter state"); + } + } + } + + private void setStateButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + GetStateDlg dlg = new GetStateDlg(); + if (dlg.ShowDialog() == DialogResult.OK) + { + if (dataStreamMeter.SetState(dlg.State, dlg.Parameter)) + { + activityLog.Print(string.Format("Water meter state set to {0} / {1}", dlg.State, dlg.Parameter)); + } + else + { + activityLog.Print(string.Format("Failed to set the water meter state to {0} / {1}", dlg.State, dlg.Parameter)); + } + } + } + } + + private void startMeasurementButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + if (dataStreamMeter.StartMeasurement()) + { + framesListView.Items.Clear(); + activityLog.Print(string.Format("Measurement started")); + } + else + { + activityLog.Print("Failed to start a measurement"); + } + } + } + + private void stopMeasurementButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + if (dataStreamMeter.StopMeasurement(out storedFramesCount)) + { + framesListView.Items.Clear(); + activityLog.Print(string.Format("Measurement sopped, {0} frames acquired", storedFramesCount)); + } + else + { + activityLog.Print("Failed to stop the measurement"); + } + } + } + + private void getFramesButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + GetFrameBoundariesDlg dlg = new GetFrameBoundariesDlg("Enter frames range boundaries", 0, storedFramesCount - 1); + if (dlg.ShowDialog() != DialogResult.OK) return; + DataFrame[] frames = dataStreamMeter.GetFrames(dlg.From, Convert.ToInt32(dlg.To - dlg.From + 1)); + { + foreach (var frame in frames) + { + if (frame != null) framesListView.Items.Add(GetListViewItem(frame)); + } + } + } + } + + private void getIDButton_Click(object sender, EventArgs e) + { + if (dataStreamMeter == null) + ShowNoMeterInterfaceMessage(); + else + { + GetDblValueDlg dlg = new GetDblValueDlg("Enter time in seconds"); + if (dlg.ShowDialog() == DialogResult.OK) + { + Int64 id = dataStreamMeter.GetID(dlg.DblValue); + activityLog.Print(string.Format("GetID({0}) returned {1}", dlg.DblValue, id)); + } + } + } + + ListViewItem GetListViewItem(DataFrame frame) + { + ListViewItem lvi = new ListViewItem(frame.ID.ToString()); + lvi.SubItems.Add(frame.Time.ToString()); + lvi.SubItems.Add(frame.Volume.ToString()); + StringBuilder sb = new StringBuilder(); + foreach (var quantity in frame.Quantity) + { + sb.Append(quantity.ToString()); + sb.Append(" "); + } + lvi.SubItems.Add(sb.ToString()); + lvi.Tag = frame; + return lvi; + } + } +} diff --git a/DataStreamInterfaceTest/DemoMainWnd.resx b/DataStreamInterfaceTest/DemoMainWnd.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/DataStreamInterfaceTest/DemoMainWnd.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetDblValueDlg.Designer.cs b/DataStreamInterfaceTest/GetDblValueDlg.Designer.cs new file mode 100644 index 000000000..500e93d0b --- /dev/null +++ b/DataStreamInterfaceTest/GetDblValueDlg.Designer.cs @@ -0,0 +1,88 @@ +namespace DataStreamInterfaceTest +{ + partial class GetDblValueDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.valueTextBox = new System.Windows.Forms.TextBox(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // valueTextBox + // + this.valueTextBox.Location = new System.Drawing.Point(35, 20); + this.valueTextBox.Name = "valueTextBox"; + this.valueTextBox.Size = new System.Drawing.Size(94, 20); + this.valueTextBox.TabIndex = 0; + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.Location = new System.Drawing.Point(216, 16); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 29); + this.okButton.TabIndex = 1; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(306, 16); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 29); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // GetFlowDlg + // + this.AcceptButton = this.okButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(396, 58); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.Controls.Add(this.valueTextBox); + this.Name = "GetFlowDlg"; + this.Text = "Enter flow"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox valueTextBox; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + } +} \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetDblValueDlg.cs b/DataStreamInterfaceTest/GetDblValueDlg.cs new file mode 100644 index 000000000..2ca605b97 --- /dev/null +++ b/DataStreamInterfaceTest/GetDblValueDlg.cs @@ -0,0 +1,59 @@ +using System; +using System.Globalization; +using System.Windows.Forms; + +namespace DataStreamInterfaceTest +{ + public partial class GetDblValueDlg : Form + { + public double DblValue; + + double lowerLimit; + double upperLimit; + + + public GetDblValueDlg() + : this("Enter flow in [m3/h] please") + { + } + + public GetDblValueDlg(string title) + : this(title, 0, 100.0) + { + } + + public GetDblValueDlg(string title, double lowerLimit, double upperLimit) + { + InitializeComponent(); + this.Text = title; + this.lowerLimit = lowerLimit; + this.upperLimit = upperLimit; + } + + + private void okButton_Click(object sender, EventArgs e) + { + double val; + if (TryParseUDouble(valueTextBox.Text, out val)) + { + DblValue = val; + DialogResult = DialogResult.OK; + Close(); + } + else + { + MessageBox.Show("Invalid value"); + DialogResult = DialogResult.None; + } + } + + /// + /// Parse an unsigned double number + /// + bool TryParseUDouble(string text, out double result) + { + return double.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out result) || + double.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result); + } + } +} diff --git a/DataStreamInterfaceTest/GetDblValueDlg.resx b/DataStreamInterfaceTest/GetDblValueDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/DataStreamInterfaceTest/GetDblValueDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetFrameBoundariesDlg.Designer.cs b/DataStreamInterfaceTest/GetFrameBoundariesDlg.Designer.cs new file mode 100644 index 000000000..3a54bf6b4 --- /dev/null +++ b/DataStreamInterfaceTest/GetFrameBoundariesDlg.Designer.cs @@ -0,0 +1,126 @@ +namespace DataStreamInterfaceTest +{ + partial class GetFrameBoundariesDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.fromTextBox = new System.Windows.Forms.TextBox(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.toTextBox = new System.Windows.Forms.TextBox(); + this.fromLabel = new System.Windows.Forms.Label(); + this.toLabel = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // fromTextBox + // + this.fromTextBox.Location = new System.Drawing.Point(89, 16); + this.fromTextBox.Name = "fromTextBox"; + this.fromTextBox.Size = new System.Drawing.Size(100, 20); + this.fromTextBox.TabIndex = 0; + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.Location = new System.Drawing.Point(225, 24); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 36); + this.okButton.TabIndex = 1; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(316, 24); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 36); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // toTextBox + // + this.toTextBox.Location = new System.Drawing.Point(89, 46); + this.toTextBox.Name = "toTextBox"; + this.toTextBox.Size = new System.Drawing.Size(100, 20); + this.toTextBox.TabIndex = 3; + // + // fromLabel + // + this.fromLabel.AutoSize = true; + this.fromLabel.Location = new System.Drawing.Point(12, 19); + this.fromLabel.Name = "fromLabel"; + this.fromLabel.Size = new System.Drawing.Size(30, 13); + this.fromLabel.TabIndex = 4; + this.fromLabel.Text = "From"; + // + // toLabel + // + this.toLabel.AutoSize = true; + this.toLabel.Location = new System.Drawing.Point(12, 49); + this.toLabel.Name = "toLabel"; + this.toLabel.Size = new System.Drawing.Size(20, 13); + this.toLabel.TabIndex = 5; + this.toLabel.Text = "To"; + // + // GetFrameBoundariesDlg + // + this.AcceptButton = this.okButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(419, 79); + this.ControlBox = false; + this.Controls.Add(this.toLabel); + this.Controls.Add(this.fromLabel); + this.Controls.Add(this.toTextBox); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.Controls.Add(this.fromTextBox); + this.Name = "GetFrameBoundariesDlg"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Enter frames range boundaries"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox fromTextBox; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.TextBox toTextBox; + private System.Windows.Forms.Label fromLabel; + private System.Windows.Forms.Label toLabel; + } +} \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetFrameBoundariesDlg.cs b/DataStreamInterfaceTest/GetFrameBoundariesDlg.cs new file mode 100644 index 000000000..91d47f87e --- /dev/null +++ b/DataStreamInterfaceTest/GetFrameBoundariesDlg.cs @@ -0,0 +1,88 @@ +using System; +using System.Windows.Forms; + +namespace DataStreamInterfaceTest +{ + public partial class GetFrameBoundariesDlg : Form + { + /// + /// Integer number entered in this form + /// + public Int64 From; + public Int64 To; + + Int64 lowerLimit; + Int64 upperLimit; + + + /// + /// Default constructor + /// + public GetFrameBoundariesDlg() + : this("Enter state please") + { + } + + /// + /// Constructor with a custom window title. + /// + /// Window title + public GetFrameBoundariesDlg(string title) + : this(title, Int64.MinValue, Int64.MaxValue) + { + } + + /// + /// Constructor with a custom window title, limits and non-empty initial value. + /// + /// Window title + /// Lower limit + /// Upper limit + /// Initial value + public GetFrameBoundariesDlg(string title, Int64 lowerLimit, Int64 upperLimit, int initialValue) + : this(title, lowerLimit, upperLimit) + { + fromTextBox.Text = initialValue.ToString(); + } + + /// + /// Constructor with a custom window title and lower/upper limits. + /// + /// Window title + /// Lower limit + /// Upper limit + public GetFrameBoundariesDlg(string title, Int64 lowerLimit, Int64 upperLimit) + { + InitializeComponent(); + this.Text = title; + this.lowerLimit = lowerLimit; + this.upperLimit = upperLimit; + } + + + /// + /// OK button handler that verifies validity of the entered value. + /// + private void okButton_Click(object sender, EventArgs e) + { + Int64 from; + Int64 to; + if (Int64.TryParse(fromTextBox.Text, out from) && from >= lowerLimit && from <= upperLimit && + Int64.TryParse(toTextBox.Text, out to) && to >= lowerLimit && to <= upperLimit && + to >= from && to < from + Int32.MaxValue) + { + From = from; + To = to; + DialogResult = DialogResult.OK; + } + else + { + string message = (lowerLimit != 0 || upperLimit != Int32.MaxValue) + ? string.Format("Invalid boundaries ({0}..{1})", lowerLimit, upperLimit) + : "Invalid boundaries"; + MessageBox.Show(message); + DialogResult = DialogResult.None; /// Prevent closing this window + } + } + } +} diff --git a/DataStreamInterfaceTest/GetFrameBoundariesDlg.resx b/DataStreamInterfaceTest/GetFrameBoundariesDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/DataStreamInterfaceTest/GetFrameBoundariesDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetIntegerNumberDlg.Designer.cs b/DataStreamInterfaceTest/GetIntegerNumberDlg.Designer.cs new file mode 100644 index 000000000..8e77c8cb4 --- /dev/null +++ b/DataStreamInterfaceTest/GetIntegerNumberDlg.Designer.cs @@ -0,0 +1,90 @@ +namespace DataStreamInterfaceTest +{ + partial class GetIntegerNumberDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.numberTextBox = new System.Windows.Forms.TextBox(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // numberTextBox + // + this.numberTextBox.Location = new System.Drawing.Point(36, 16); + this.numberTextBox.Name = "numberTextBox"; + this.numberTextBox.Size = new System.Drawing.Size(100, 20); + this.numberTextBox.TabIndex = 0; + // + // okButton + // + this.okButton.Location = new System.Drawing.Point(174, 7); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 36); + this.okButton.TabIndex = 1; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(265, 7); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 36); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // GetIntegerNumberDlg + // + this.AcceptButton = this.okButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(363, 50); + this.ControlBox = false; + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.Controls.Add(this.numberTextBox); + this.Name = "GetIntegerNumberDlg"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Enter integer number please"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox numberTextBox; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + } +} \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetIntegerNumberDlg.cs b/DataStreamInterfaceTest/GetIntegerNumberDlg.cs new file mode 100644 index 000000000..155c3d3f2 --- /dev/null +++ b/DataStreamInterfaceTest/GetIntegerNumberDlg.cs @@ -0,0 +1,83 @@ +using System; +using System.Windows.Forms; + +namespace DataStreamInterfaceTest +{ + public partial class GetIntegerNumberDlg : Form + { + /// + /// Integer number entered in this form + /// + public int Number; + + int lowerLimit; + int upperLimit; + + + /// + /// Default constructor + /// + public GetIntegerNumberDlg() + : this("Enter integer number please") + { + } + + /// + /// Constructor with a custom window title. + /// + /// Window title + public GetIntegerNumberDlg(string title) + : this(title, Int32.MinValue, Int32.MaxValue) + { + } + + /// + /// Constructor with a custom window title, limits and non-empty initial value. + /// + /// Window title + /// Lower limit + /// Upper limit + /// Initial value + public GetIntegerNumberDlg(string title, int lowerLimit, int upperLimit, int initialValue) + : this(title, lowerLimit, upperLimit) + { + numberTextBox.Text = initialValue.ToString(); + } + + /// + /// Constructor with a custom window title and lower/upper limits. + /// + /// Window title + /// Lower limit + /// Upper limit + public GetIntegerNumberDlg(string title, int lowerLimit, int upperLimit) + { + InitializeComponent(); + this.Text = title; + this.lowerLimit = lowerLimit; + this.upperLimit = upperLimit; + } + + + /// + /// OK button handler that verifies validity of the entered value. + /// + private void okButton_Click(object sender, EventArgs e) + { + int number; + if (int.TryParse(numberTextBox.Text, out number) && number >= lowerLimit && number <= upperLimit) + { + Number = number; + DialogResult = DialogResult.OK; + } + else + { + string message = (lowerLimit != Int32.MinValue || upperLimit != Int32.MaxValue) + ? string.Format("Invalid integer number ({0}..{1})", lowerLimit, upperLimit) + : "Invalid integer number"; + MessageBox.Show(message); + DialogResult = DialogResult.None; /// Prevent closing this window + } + } + } +} diff --git a/DataStreamInterfaceTest/GetIntegerNumberDlg.resx b/DataStreamInterfaceTest/GetIntegerNumberDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/DataStreamInterfaceTest/GetIntegerNumberDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetStateDlg.Designer.cs b/DataStreamInterfaceTest/GetStateDlg.Designer.cs new file mode 100644 index 000000000..6dc14c2c4 --- /dev/null +++ b/DataStreamInterfaceTest/GetStateDlg.Designer.cs @@ -0,0 +1,126 @@ +namespace DataStreamInterfaceTest +{ + partial class GetStateDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.stateTextBox = new System.Windows.Forms.TextBox(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.parameterTextBox = new System.Windows.Forms.TextBox(); + this.stateLabel = new System.Windows.Forms.Label(); + this.parameterLabel = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // stateTextBox + // + this.stateTextBox.Location = new System.Drawing.Point(89, 16); + this.stateTextBox.Name = "stateTextBox"; + this.stateTextBox.Size = new System.Drawing.Size(100, 20); + this.stateTextBox.TabIndex = 0; + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.Location = new System.Drawing.Point(225, 24); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 36); + this.okButton.TabIndex = 1; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(316, 24); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 36); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // parameterTextBox + // + this.parameterTextBox.Location = new System.Drawing.Point(89, 46); + this.parameterTextBox.Name = "parameterTextBox"; + this.parameterTextBox.Size = new System.Drawing.Size(100, 20); + this.parameterTextBox.TabIndex = 3; + // + // stateLabel + // + this.stateLabel.AutoSize = true; + this.stateLabel.Location = new System.Drawing.Point(12, 19); + this.stateLabel.Name = "stateLabel"; + this.stateLabel.Size = new System.Drawing.Size(32, 13); + this.stateLabel.TabIndex = 4; + this.stateLabel.Text = "State"; + // + // parameterLabel + // + this.parameterLabel.AutoSize = true; + this.parameterLabel.Location = new System.Drawing.Point(12, 49); + this.parameterLabel.Name = "parameterLabel"; + this.parameterLabel.Size = new System.Drawing.Size(55, 13); + this.parameterLabel.TabIndex = 5; + this.parameterLabel.Text = "Parameter"; + // + // GetStateDlg + // + this.AcceptButton = this.okButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(419, 79); + this.ControlBox = false; + this.Controls.Add(this.parameterLabel); + this.Controls.Add(this.stateLabel); + this.Controls.Add(this.parameterTextBox); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.Controls.Add(this.stateTextBox); + this.Name = "GetStateDlg"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Enter state please"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox stateTextBox; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.TextBox parameterTextBox; + private System.Windows.Forms.Label stateLabel; + private System.Windows.Forms.Label parameterLabel; + } +} \ No newline at end of file diff --git a/DataStreamInterfaceTest/GetStateDlg.cs b/DataStreamInterfaceTest/GetStateDlg.cs new file mode 100644 index 000000000..04589c91e --- /dev/null +++ b/DataStreamInterfaceTest/GetStateDlg.cs @@ -0,0 +1,85 @@ +using System; +using System.Windows.Forms; + +namespace DataStreamInterfaceTest +{ + public partial class GetStateDlg : Form + { + /// + /// Integer number entered in this form + /// + public int State; + public string Parameter; + + int lowerLimit; + int upperLimit; + + + /// + /// Default constructor + /// + public GetStateDlg() + : this("Enter state please") + { + } + + /// + /// Constructor with a custom window title. + /// + /// Window title + public GetStateDlg(string title) + : this(title, Int32.MinValue, Int32.MaxValue) + { + } + + /// + /// Constructor with a custom window title, limits and non-empty initial value. + /// + /// Window title + /// Lower limit + /// Upper limit + /// Initial value + public GetStateDlg(string title, int lowerLimit, int upperLimit, int initialValue) + : this(title, lowerLimit, upperLimit) + { + stateTextBox.Text = initialValue.ToString(); + } + + /// + /// Constructor with a custom window title and lower/upper limits. + /// + /// Window title + /// Lower limit + /// Upper limit + public GetStateDlg(string title, int lowerLimit, int upperLimit) + { + InitializeComponent(); + this.Text = title; + this.lowerLimit = lowerLimit; + this.upperLimit = upperLimit; + } + + + /// + /// OK button handler that verifies validity of the entered value. + /// + private void okButton_Click(object sender, EventArgs e) + { + int number; + if (int.TryParse(stateTextBox.Text, out number) && number >= lowerLimit && number <= upperLimit) + { + State = number; + Parameter = parameterTextBox.Text; + DialogResult = DialogResult.OK; + } + else + { + string message = (lowerLimit != Int32.MinValue || upperLimit != Int32.MaxValue) + ? string.Format("Invalid state ({0}..{1})", lowerLimit, upperLimit) + : "Invalid state"; + MessageBox.Show(message); + DialogResult = DialogResult.None; /// Prevent closing this window + } + } + } +} diff --git a/DataStreamInterfaceTest/GetStateDlg.resx b/DataStreamInterfaceTest/GetStateDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/DataStreamInterfaceTest/GetStateDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/LviIDComparer.cs b/DataStreamInterfaceTest/LviIDComparer.cs new file mode 100644 index 000000000..93f3c1613 --- /dev/null +++ b/DataStreamInterfaceTest/LviIDComparer.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections; +using System.Windows.Forms; + +namespace DataStreamInterfaceTest +{ + public class LviIDComparer : IComparer + { + int column; + SortOrder order; + + public LviIDComparer() + { + column = 0; + order = SortOrder.Ascending; + } + + public LviIDComparer(int column, SortOrder order) + { + this.column = column; + this.order = order; + } + + public int Compare(object x, object y) + { + Int64 valX = Int64.Parse(((ListViewItem)x).SubItems[column].Text); + Int64 valY = Int64.Parse(((ListViewItem)y).SubItems[column].Text); + + if (order == SortOrder.Ascending) + { + return valX > valY ? 1 : valX == valY ? 0 : -1; + } + else + { + return valX < valY ? 1 : valX == valY ? 0 : -1; + } + } + } +} diff --git a/DataStreamInterfaceTest/Program.cs b/DataStreamInterfaceTest/Program.cs new file mode 100644 index 000000000..b027b1729 --- /dev/null +++ b/DataStreamInterfaceTest/Program.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; +using System.ComponentModel.Composition; +using System.ComponentModel.Composition.Hosting; +using System.Windows.Forms; +using DataStreamInterface; + +namespace DataStreamInterfaceTest +{ + class Program + { +#if DEBUG + const string CatalogDir = "..\\..\\..\\DataStreamMeter\\bin\\Debug"; +#else + const string CatalogDir = "..\\..\\..\\DataStreamMeter\\bin\\Release"; +#endif + + [Import(typeof(IDataStreamMeter))] + IDataStreamMeter dataStreamMeter; + + private Program() + { + Console.WriteLine("Components found:"); + foreach (var file in Directory.EnumerateFiles(CatalogDir)) + { + Console.WriteLine(file); + } + + try + { + var catalog = new AggregateCatalog(); + catalog.Catalogs.Add(new AssemblyCatalog(typeof(DataStreamInterface.IDataStreamMeter).Assembly)); + catalog.Catalogs.Add(new DirectoryCatalog(CatalogDir)); + (new CompositionContainer(catalog)).ComposeParts(this); + } + catch (CompositionException compositionException) + { + Console.WriteLine(compositionException.ToString()); + } + } + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Program p = new Program(); + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new DemoMainWnd(p.dataStreamMeter)); + } + } +} diff --git a/DataStreamInterfaceTest/Properties/AssemblyInfo.cs b/DataStreamInterfaceTest/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..faac7b59f --- /dev/null +++ b/DataStreamInterfaceTest/Properties/AssemblyInfo.cs @@ -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("DataStreamInterfaceTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataStreamInterfaceTest")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[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("429fdea9-ec3a-47d8-88b3-5df11de8b4c8")] + +// 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")] diff --git a/DataStreamInterfaceTest/Properties/Resources.Designer.cs b/DataStreamInterfaceTest/Properties/Resources.Designer.cs new file mode 100644 index 000000000..b9b484555 --- /dev/null +++ b/DataStreamInterfaceTest/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DataStreamInterfaceTest.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DataStreamMainDemo.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/DataStreamInterfaceTest/Properties/Resources.resx b/DataStreamInterfaceTest/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/DataStreamInterfaceTest/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataStreamInterfaceTest/Properties/Settings.Designer.cs b/DataStreamInterfaceTest/Properties/Settings.Designer.cs new file mode 100644 index 000000000..09d23c23a --- /dev/null +++ b/DataStreamInterfaceTest/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DataStreamInterfaceTest.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/DataStreamInterfaceTest/Properties/Settings.settings b/DataStreamInterfaceTest/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/DataStreamInterfaceTest/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/DataStreamMeter/DataStreamMeter.csproj b/DataStreamMeter/DataStreamMeter.csproj new file mode 100644 index 000000000..b0abf9878 --- /dev/null +++ b/DataStreamMeter/DataStreamMeter.csproj @@ -0,0 +1,85 @@ + + + + + Debug + AnyCPU + {E6925701-57A6-4167-B5C4-BF670F1DE310} + Library + Properties + DataStreamMeter + DataStreamMeter + v4.7.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + GetDblValueDlg.cs + + + + Form + + + MeterSimulationDlg.cs + + + + + + + + {7ebeea14-91c4-48d7-af0a-7a4bc3ff9a28} + DataStreamInterface + + + + + GetDblValueDlg.cs + + + MeterSimulationDlg.cs + Designer + + + + + \ No newline at end of file diff --git a/DataStreamMeter/GetDblValueDlg.Designer.cs b/DataStreamMeter/GetDblValueDlg.Designer.cs new file mode 100644 index 000000000..0d8c565f1 --- /dev/null +++ b/DataStreamMeter/GetDblValueDlg.Designer.cs @@ -0,0 +1,88 @@ +namespace DataStreamMeter +{ + partial class GetDblValueDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.valueTextBox = new System.Windows.Forms.TextBox(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // valueTextBox + // + this.valueTextBox.Location = new System.Drawing.Point(35, 20); + this.valueTextBox.Name = "valueTextBox"; + this.valueTextBox.Size = new System.Drawing.Size(94, 20); + this.valueTextBox.TabIndex = 0; + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.Location = new System.Drawing.Point(216, 16); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 29); + this.okButton.TabIndex = 1; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(306, 16); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 29); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // GetFlowDlg + // + this.AcceptButton = this.okButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(396, 58); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.Controls.Add(this.valueTextBox); + this.Name = "GetFlowDlg"; + this.Text = "Enter flow"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox valueTextBox; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + } +} \ No newline at end of file diff --git a/DataStreamMeter/GetDblValueDlg.cs b/DataStreamMeter/GetDblValueDlg.cs new file mode 100644 index 000000000..408a4fcb6 --- /dev/null +++ b/DataStreamMeter/GetDblValueDlg.cs @@ -0,0 +1,59 @@ +using System; +using System.Globalization; +using System.Windows.Forms; + +namespace DataStreamMeter +{ + public partial class GetDblValueDlg : Form + { + public double DblValue; + + double lowerLimit; + double upperLimit; + + + public GetDblValueDlg() + : this("Enter flow in [m3/h] please") + { + } + + public GetDblValueDlg(string title) + : this(title, 0, 100.0) + { + } + + public GetDblValueDlg(string title, double lowerLimit, double upperLimit) + { + InitializeComponent(); + this.Text = title; + this.lowerLimit = lowerLimit; + this.upperLimit = upperLimit; + } + + + private void okButton_Click(object sender, EventArgs e) + { + double val; + if (TryParseUDouble(valueTextBox.Text, out val)) + { + DblValue = val; + DialogResult = DialogResult.OK; + Close(); + } + else + { + MessageBox.Show("Invalid value"); + DialogResult = DialogResult.None; + } + } + + /// + /// Parse an unsigned double number + /// + bool TryParseUDouble(string text, out double result) + { + return double.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out result) || + double.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result); + } + } +} diff --git a/DataStreamMeter/GetDblValueDlg.resx b/DataStreamMeter/GetDblValueDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/DataStreamMeter/GetDblValueDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataStreamMeter/MeterDataEventArgs.cs b/DataStreamMeter/MeterDataEventArgs.cs new file mode 100644 index 000000000..fdd0aa6de --- /dev/null +++ b/DataStreamMeter/MeterDataEventArgs.cs @@ -0,0 +1,20 @@ +using System; + +namespace DataStreamMeter +{ + public class MeterDataEventArgs : EventArgs + { + public State State; + public double Time; + public double Volume; + public double Flow; + + public MeterDataEventArgs(State state, double time, double volume, double flow) + { + State = state; + Time = time; + Volume = volume; + Flow = flow; + } + } +} diff --git a/DataStreamMeter/MeterSimulation.cs b/DataStreamMeter/MeterSimulation.cs new file mode 100644 index 000000000..81b023bde --- /dev/null +++ b/DataStreamMeter/MeterSimulation.cs @@ -0,0 +1,319 @@ +using System; +using System.ComponentModel.Composition; +using DataStreamInterface; + +namespace DataStreamMeter +{ + [Export(typeof(IDataStreamMeter))] + public class MeterSimulation : IDataStreamMeter + { + MeterSimulationDlg modelessDlg; + + /// Water meter specification + public readonly string MeterID = "3141592653"; + public const Unit TimeUnits = Unit.s; /// Unit.s, Unit.ms, ... + public const Unit VolumeUnits = Unit.l; /// Unit.l, Unit.USgal, ... + public const Unit FlowUnits = Unit.m3ph; /// Unit.m3ph, Unit.USgalps, Unit.cfs, ... + public const double SamplingPeriodSec = 0.125; /// Sampling period in seconds (here 125 ms, 8 Hz) + public readonly double SamplingPeriod; + + + public const Int64 MaxSamplesCount = 40000; /// Maximal test time is SamplingPeriod * MaxSamplesCount + Sample[] samples = new Sample[MaxSamplesCount]; + Int64 storedSamplesCount; + + + readonly object stateChangeAndTimerTickLock = new object(); + public State State; + string connectionParameters; + + /// initialTime is time when simulation started + /// (lastSampleTime - initialTime).TotalSeconds is multiple of Sampling Period + DateTime initialTime; + + /// Last user interface tick info + bool lastTickValid; + State lastTickState; + + /// Values incrementally updated on each timer tick + double currentTime; + double currentVolume; + double currentFlow; + double currentFlow_m3ph; + + DateTime startTimeStamp; /// Measurement start DateTime + double startTime; /// Measurement start time in seconds + DateTime stopTimeStamp; /// Measurement end DateTime + double stopTime; /// Measurement end time in seconds + + + public MeterSimulation() + { + modelessDlg = null; + State = State.Disconnected; + SamplingPeriod = DataStreamInterface.Units.ConvertTo(TimeUnits, SamplingPeriodSec); + lastTickValid = false; + initialTime = DateTime.Now.Date; /// An arbitrary initial time (in this case the last midnight) + } + + public Unit GetTimeUnits() + { + return TimeUnits; + } + + public Unit GetVolumeUnits() + { + return VolumeUnits; + } + + public int GetQuantitiesCount() + { + return 1; + } + + public string GetQuantityCaption(int quantityNr) + { + if (quantityNr == 0) return "Flow"; + return string.Empty; + } + + public Unit GetQuantityUnits(int quantityNr) + { + if (quantityNr == 0) return FlowUnits; + return Unit.None; + } + + public bool OpenConnection(string connectionParameters, out string meterID) + { + lock (stateChangeAndTimerTickLock) + { + if (State != State.Disconnected) + { + /// Meter is already connected + meterID = MeterID; + return true; + } + + /// Connect the meter + meterID = MeterID; + this.connectionParameters = connectionParameters; + lastTickValid = false; + State = State.Connected; + } + + /// Open modeless form + modelessDlg = new MeterSimulationDlg(this, MeterID); + modelessDlg.Show(); + return true; + } + + public bool CloseConnection() + { + bool closeModelessDlg = false; + + lock (stateChangeAndTimerTickLock) + { + if (State != State.Disconnected) + { + State = State.Disconnected; + storedSamplesCount = 0; + closeModelessDlg = true; + } + } + + if (closeModelessDlg) + { + if (modelessDlg != null) modelessDlg.Close(); + modelessDlg = null; + } + return true; + } + + public bool GetState(out int state, out string parameter) + { + state = (int)this.State; + parameter = this.connectionParameters; + return true; + } + + public bool SetState(int state, string parameter) + { + /// It's not allowed to change the satate in this demo + return false; + } + + public bool StartMeasurement() + { + lock (stateChangeAndTimerTickLock) + { + if (State == State.Connected) + { + startTimeStamp = DateTime.Now; + startTime = TimeInSecondsFromDateTime(startTimeStamp, initialTime, SamplingPeriodSec); + storedSamplesCount = 0; + State = State.MeasurementInProgress; + return true; + } + else + { + return false; + } + } + } + + public bool StopMeasurement(out Int64 storedFramesCount) + { + lock (stateChangeAndTimerTickLock) + { + if (State == State.MeasurementInProgress) + { + stopTimeStamp = DateTime.Now; + stopTime = TimeInSecondsFromDateTime(stopTimeStamp, initialTime, SamplingPeriodSec); + + int newSamplesCount = Convert.ToInt32(Math.Round((stopTime - currentTime) / SamplingPeriodSec)); + double time = Units.ConvertTo(TimeUnits, currentTime); + double volume = currentVolume; + double volumeIncrement = Units.ConvertTo(VolumeUnits, currentFlow_m3ph * (SamplingPeriodSec / 3.6)); + for (int i = 0; i < newSamplesCount; i++) + { + time += SamplingPeriod; + volume += volumeIncrement; + if (storedSamplesCount < MaxSamplesCount) + { + samples[storedSamplesCount++] = new Sample(time, volume, currentFlow); + } + } + + State = State.Connected; + storedFramesCount = storedSamplesCount; + return true; + } + else + { + storedFramesCount = 0; + return false; + } + } + } + + public void TimerTick(double flow_m3ph) + { + lock (stateChangeAndTimerTickLock) + { + double lastSampleTime = TimeInSecondsFromDateTime(DateTime.Now, initialTime, SamplingPeriodSec); + currentFlow_m3ph = flow_m3ph; + currentFlow = Units.ConvertTo(FlowUnits, flow_m3ph); + + if (!lastTickValid) + { + currentTime = lastSampleTime; + currentVolume = 0; + lastTickValid = true; + lastTickState = State; + return; + } + else + { + int newSamplesCount = Convert.ToInt32(Math.Round((lastSampleTime - currentTime) / SamplingPeriodSec)); + double volumeIncrement = Units.ConvertTo(VolumeUnits, currentFlow_m3ph * (SamplingPeriodSec / 3.6)); + for (int i = 0; i < newSamplesCount; i++) + { + currentTime += SamplingPeriodSec; + currentVolume += volumeIncrement; + + if (State == State.MeasurementInProgress && currentTime > startTime && storedSamplesCount < MaxSamplesCount) + { + samples[storedSamplesCount++] = new Sample(Units.ConvertTo(TimeUnits, currentTime), currentVolume, currentFlow); + } + } + currentTime = lastSampleTime; /// Rectify, prevent error propagation + lastTickState = State; + } + } + + modelessDlg.OnMeterdata(new MeterDataEventArgs(State, currentTime, currentVolume, currentFlow)); + } + + + /// + /// Obtain the last time instance before 'DateTime time' which is multiple of samplingPeriod-s after 'DateTime initialTime'. + /// + /// Time to be converted to seconds and rounded to samplingPeriod-s + /// Initial time + /// Sampling period in seconds + /// + double TimeInSecondsFromDateTime(DateTime time, DateTime initialTime, double samplingPeriod) + { + TimeSpan span = time - initialTime; + return samplingPeriod * Math.Floor(span.TotalSeconds / samplingPeriod); + } + + + ///--------------------------- + /// Datastream data exchange + ///--------------------------- + + /// + /// Retuns 'count' data frames starting with data frame with ID = 'id' + /// + /// First frame ID + /// Frames count + /// Selected data frames + public DataFrame[] GetFrames(Int64 startID, int count) + { + DataFrame[] frames = new DataFrame[count]; + + if (State != State.MeasurementInProgress) + { + for (int j = 0; j < count; j++) + { + Int64 id = startID + j; + if (id < storedSamplesCount) + { + frames[j] = new DataFrame(id, samples[id].Time, samples[id].Volume, new double[1] { samples[id].Flow }); + } + } + } + + return frames; + } + + /// + /// Returns ID of the data frame where time equals or exceeds the specified time. + /// When time of the first frame (ID=0) is larger then specified time, function returns 0. + /// + /// Time + /// ID of the data frame at or after the pecified time + public Int64 GetID(double time) + { + if (storedSamplesCount == 0) return -1; + + Int64 lo = 0; + Int64 hi = storedSamplesCount - 1; + + if (samples[hi].Time < time) return -1; + + while (lo < hi) + { + Int64 mid = (lo + hi) / 2; + if (samples[mid].Time < time) + { + lo = mid + 1; + } + else + { + hi = mid; + } + } + + return lo; + } + } + + public enum State + { + Disconnected = 0, + Connected = 1, + MeasurementInProgress = 2, + } +} diff --git a/DataStreamMeter/MeterSimulationDlg.Designer.cs b/DataStreamMeter/MeterSimulationDlg.Designer.cs new file mode 100644 index 000000000..aac135031 --- /dev/null +++ b/DataStreamMeter/MeterSimulationDlg.Designer.cs @@ -0,0 +1,323 @@ +namespace DataStreamMeter +{ + partial class MeterSimulationDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.meterIDGroupBox = new System.Windows.Forms.GroupBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.volumeUnitsTextBox = new System.Windows.Forms.TextBox(); + this.timeUnitsTextBox = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.meterIDTextBox = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.setFlowButton = new System.Windows.Forms.Button(); + this.flowm3phTextBox = new System.Windows.Forms.TextBox(); + this.flowTrackBar = new System.Windows.Forms.TrackBar(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.flowTextBox = new System.Windows.Forms.TextBox(); + this.volumeTextBox = new System.Windows.Forms.TextBox(); + this.timeTextBox = new System.Windows.Forms.TextBox(); + this.stateTextBox = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.lastUITickTextBox = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.meterIDGroupBox.SuspendLayout(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.flowTrackBar)).BeginInit(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // meterIDGroupBox + // + this.meterIDGroupBox.Controls.Add(this.label3); + this.meterIDGroupBox.Controls.Add(this.label2); + this.meterIDGroupBox.Controls.Add(this.volumeUnitsTextBox); + this.meterIDGroupBox.Controls.Add(this.timeUnitsTextBox); + this.meterIDGroupBox.Controls.Add(this.label1); + this.meterIDGroupBox.Controls.Add(this.meterIDTextBox); + this.meterIDGroupBox.Location = new System.Drawing.Point(12, 12); + this.meterIDGroupBox.Name = "meterIDGroupBox"; + this.meterIDGroupBox.Size = new System.Drawing.Size(453, 105); + this.meterIDGroupBox.TabIndex = 0; + this.meterIDGroupBox.TabStop = false; + this.meterIDGroupBox.Text = "Water meter info"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(18, 76); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(67, 13); + this.label3.TabIndex = 5; + this.label3.Text = "Volume units"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(18, 50); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(55, 13); + this.label2.TabIndex = 4; + this.label2.Text = "Time units"; + // + // volumeUnitsTextBox + // + this.volumeUnitsTextBox.Enabled = false; + this.volumeUnitsTextBox.Location = new System.Drawing.Point(122, 73); + this.volumeUnitsTextBox.Name = "volumeUnitsTextBox"; + this.volumeUnitsTextBox.Size = new System.Drawing.Size(52, 20); + this.volumeUnitsTextBox.TabIndex = 3; + // + // timeUnitsTextBox + // + this.timeUnitsTextBox.Enabled = false; + this.timeUnitsTextBox.Location = new System.Drawing.Point(122, 47); + this.timeUnitsTextBox.Name = "timeUnitsTextBox"; + this.timeUnitsTextBox.Size = new System.Drawing.Size(52, 20); + this.timeUnitsTextBox.TabIndex = 2; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(18, 24); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(73, 13); + this.label1.TabIndex = 1; + this.label1.Text = "Meter ID (s/n)"; + // + // meterIDTextBox + // + this.meterIDTextBox.Enabled = false; + this.meterIDTextBox.Location = new System.Drawing.Point(122, 21); + this.meterIDTextBox.Name = "meterIDTextBox"; + this.meterIDTextBox.Size = new System.Drawing.Size(145, 20); + this.meterIDTextBox.TabIndex = 0; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.setFlowButton); + this.groupBox1.Controls.Add(this.flowm3phTextBox); + this.groupBox1.Controls.Add(this.flowTrackBar); + this.groupBox1.Location = new System.Drawing.Point(12, 123); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(453, 96); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Flow"; + // + // setFlowButton + // + this.setFlowButton.Location = new System.Drawing.Point(289, 17); + this.setFlowButton.Name = "setFlowButton"; + this.setFlowButton.Size = new System.Drawing.Size(75, 23); + this.setFlowButton.TabIndex = 4; + this.setFlowButton.Text = "Set value"; + this.setFlowButton.UseVisualStyleBackColor = true; + this.setFlowButton.Click += new System.EventHandler(this.setFlowButton_Click); + // + // flowm3phTextBox + // + this.flowm3phTextBox.Enabled = false; + this.flowm3phTextBox.Location = new System.Drawing.Point(122, 19); + this.flowm3phTextBox.Name = "flowm3phTextBox"; + this.flowm3phTextBox.Size = new System.Drawing.Size(145, 20); + this.flowm3phTextBox.TabIndex = 3; + // + // flowTrackBar + // + this.flowTrackBar.LargeChange = 1; + this.flowTrackBar.Location = new System.Drawing.Point(0, 43); + this.flowTrackBar.Maximum = 25; + this.flowTrackBar.Name = "flowTrackBar"; + this.flowTrackBar.Size = new System.Drawing.Size(447, 45); + this.flowTrackBar.TabIndex = 2; + this.flowTrackBar.Scroll += new System.EventHandler(this.flowTrackBar_Scroll); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.flowTextBox); + this.groupBox2.Controls.Add(this.volumeTextBox); + this.groupBox2.Controls.Add(this.timeTextBox); + this.groupBox2.Controls.Add(this.stateTextBox); + this.groupBox2.Controls.Add(this.label8); + this.groupBox2.Controls.Add(this.label7); + this.groupBox2.Controls.Add(this.label6); + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Controls.Add(this.lastUITickTextBox); + this.groupBox2.Controls.Add(this.label4); + this.groupBox2.Location = new System.Drawing.Point(12, 225); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(453, 150); + this.groupBox2.TabIndex = 2; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "State"; + // + // flowTextBox + // + this.flowTextBox.Enabled = false; + this.flowTextBox.Location = new System.Drawing.Point(122, 121); + this.flowTextBox.Name = "flowTextBox"; + this.flowTextBox.Size = new System.Drawing.Size(99, 20); + this.flowTextBox.TabIndex = 9; + // + // volumeTextBox + // + this.volumeTextBox.Enabled = false; + this.volumeTextBox.Location = new System.Drawing.Point(122, 95); + this.volumeTextBox.Name = "volumeTextBox"; + this.volumeTextBox.Size = new System.Drawing.Size(99, 20); + this.volumeTextBox.TabIndex = 8; + // + // timeTextBox + // + this.timeTextBox.Enabled = false; + this.timeTextBox.Location = new System.Drawing.Point(122, 68); + this.timeTextBox.Name = "timeTextBox"; + this.timeTextBox.Size = new System.Drawing.Size(99, 20); + this.timeTextBox.TabIndex = 7; + // + // stateTextBox + // + this.stateTextBox.Enabled = false; + this.stateTextBox.Location = new System.Drawing.Point(122, 42); + this.stateTextBox.Name = "stateTextBox"; + this.stateTextBox.Size = new System.Drawing.Size(99, 20); + this.stateTextBox.TabIndex = 6; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(18, 124); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(29, 13); + this.label8.TabIndex = 5; + this.label8.Text = "Flow"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(18, 98); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(42, 13); + this.label7.TabIndex = 4; + this.label7.Text = "Volume"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(18, 71); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(30, 13); + this.label6.TabIndex = 3; + this.label6.Text = "Time"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(18, 45); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(32, 13); + this.label5.TabIndex = 2; + this.label5.Text = "State"; + // + // lastUITickTextBox + // + this.lastUITickTextBox.Enabled = false; + this.lastUITickTextBox.Location = new System.Drawing.Point(122, 13); + this.lastUITickTextBox.Name = "lastUITickTextBox"; + this.lastUITickTextBox.Size = new System.Drawing.Size(145, 20); + this.lastUITickTextBox.TabIndex = 1; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(18, 16); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(61, 13); + this.label4.TabIndex = 0; + this.label4.Text = "Last UI tick"; + // + // timer1 + // + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // MeterSimulationDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(477, 387); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.meterIDGroupBox); + this.Name = "MeterSimulationDlg"; + this.Text = "MeterDialog"; + this.meterIDGroupBox.ResumeLayout(false); + this.meterIDGroupBox.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.flowTrackBar)).EndInit(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox meterIDGroupBox; + private System.Windows.Forms.TextBox meterIDTextBox; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox volumeUnitsTextBox; + private System.Windows.Forms.TextBox timeUnitsTextBox; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox flowm3phTextBox; + private System.Windows.Forms.TrackBar flowTrackBar; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Button setFlowButton; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.TextBox lastUITickTextBox; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox flowTextBox; + private System.Windows.Forms.TextBox volumeTextBox; + private System.Windows.Forms.TextBox timeTextBox; + private System.Windows.Forms.TextBox stateTextBox; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label5; + } +} \ No newline at end of file diff --git a/DataStreamMeter/MeterSimulationDlg.cs b/DataStreamMeter/MeterSimulationDlg.cs new file mode 100644 index 000000000..f0e4ac49d --- /dev/null +++ b/DataStreamMeter/MeterSimulationDlg.cs @@ -0,0 +1,91 @@ +using System; +using System.Windows.Forms; + +namespace DataStreamMeter +{ + public partial class MeterSimulationDlg : Form + { + MeterSimulation meterSimulation; + double currentFlow; + + + public string MeterID; + + + public void OnMeterdata(MeterDataEventArgs args) + { + if (MeterDataHandler == null) return; + MeterDataHandler(null, args); + } + public event EventHandler MeterDataHandler; + + + /// + /// Default constructor with no meter + /// + public MeterSimulationDlg() + : this(null, string.Empty) + { + } + + public MeterSimulationDlg(MeterSimulation meterSimulation, string meterID) + { + InitializeComponent(); + this.meterSimulation = meterSimulation; + meterIDTextBox.Text = meterID; + + currentFlow = 0; + flowm3phTextBox.Text = currentFlow.ToString(); + flowTrackBar.Value = Convert.ToInt32(currentFlow); + + MeterDataHandler += delegate(object sender, MeterDataEventArgs args) + { + if (InvokeRequired) + { + Invoke(new EventHandler(DisplayMeterData), sender, args); + } + else + { + DisplayMeterData(sender, args); + } + }; + + if (meterSimulation != null) + { + timer1.Enabled = true; + timer1.Start(); + } + } + + private void flowTrackBar_Scroll(object sender, EventArgs e) + { + currentFlow = flowTrackBar.Value; + flowm3phTextBox.Text = currentFlow.ToString("F2"); + } + + private void setFlowButton_Click(object sender, EventArgs e) + { + GetDblValueDlg dlg = new GetDblValueDlg("Enter flow in [m3/h] please", 0, 25.0); + if (dlg.ShowDialog() == DialogResult.OK) + { + currentFlow = dlg.DblValue; + flowm3phTextBox.Text = currentFlow.ToString(); + flowTrackBar.Value = Convert.ToInt32(currentFlow); + } + } + + private void timer1_Tick(object sender, EventArgs e) + { + lastUITickTextBox.Text = DateTime.Now.ToString("HH:mm:ss fff"); + meterSimulation.TimerTick(currentFlow); + } + + void DisplayMeterData(object sender, MeterDataEventArgs args) + { + stateTextBox.Text = args.State.ToString(); + timeTextBox.Text = args.Time.ToString(); + volumeTextBox.Text = args.Volume.ToString(); + flowTextBox.Text = args.Flow.ToString(); + } + } +} diff --git a/DataStreamMeter/MeterSimulationDlg.resx b/DataStreamMeter/MeterSimulationDlg.resx new file mode 100644 index 000000000..1f666f268 --- /dev/null +++ b/DataStreamMeter/MeterSimulationDlg.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/DataStreamMeter/Properties/AssemblyInfo.cs b/DataStreamMeter/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..0822cd36a --- /dev/null +++ b/DataStreamMeter/Properties/AssemblyInfo.cs @@ -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("DataStreamMeter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataStreamMeter")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[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("8acd46eb-c84d-4199-9f40-7420b7ebabc2")] + +// 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")] diff --git a/DataStreamMeter/Sample.cs b/DataStreamMeter/Sample.cs new file mode 100644 index 000000000..3bd8b2966 --- /dev/null +++ b/DataStreamMeter/Sample.cs @@ -0,0 +1,23 @@ +using System; + +namespace DataStreamMeter +{ + public class Sample + { + public readonly double Time; /// In water meter time units + public readonly double Volume; /// In water meter colume units + public readonly double Flow; /// In water meter flow units + + public Sample(double time, double volume, double flow) + { + Time = time; + Volume = volume; + Flow = flow; + } + + public override string ToString() + { + return string.Format("time={0} volume={1} flow={2}", Time, Volume, Flow); + } + } +} diff --git a/TBF.sln b/TBF.sln index 86de24e4a..4c5262117 100644 --- a/TBF.sln +++ b/TBF.sln @@ -71,6 +71,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStreamInterface", "Data EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResetBatchNr", "ResetBatchNr\ResetBatchNr.csproj", "{D7F5A111-B2DF-4761-9574-AB730DF573A6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStreamInterfaceTest", "DataStreamInterfaceTest\DataStreamInterfaceTest.csproj", "{1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}" + ProjectSection(ProjectDependencies) = postProject + {E6925701-57A6-4167-B5C4-BF670F1DE310} = {E6925701-57A6-4167-B5C4-BF670F1DE310} + {7EBEEA14-91C4-48D7-AF0A-7A4BC3FF9A28} = {7EBEEA14-91C4-48D7-AF0A-7A4BC3FF9A28} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStreamMeter", "DataStreamMeter\DataStreamMeter.csproj", "{E6925701-57A6-4167-B5C4-BF670F1DE310}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -315,6 +323,26 @@ Global {D7F5A111-B2DF-4761-9574-AB730DF573A6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {D7F5A111-B2DF-4761-9574-AB730DF573A6}.Release|Mixed Platforms.Build.0 = Release|Any CPU {D7F5A111-B2DF-4761-9574-AB730DF573A6}.Release|x86.ActiveCfg = Release|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Debug|x86.ActiveCfg = Debug|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Release|Any CPU.Build.0 = Release|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {1D1EEF9C-7F41-43D3-BD09-5054D00F7A23}.Release|x86.ActiveCfg = Release|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Debug|x86.ActiveCfg = Debug|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Release|Any CPU.Build.0 = Release|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {E6925701-57A6-4167-B5C4-BF670F1DE310}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/clean.bat b/clean.bat index 435cc083e..cafdc074f 100644 --- a/clean.bat +++ b/clean.bat @@ -4,6 +4,10 @@ rmdir /s /q Config\bin rmdir /s /q Config\obj rmdir /s /q DataStreamInterface\bin rmdir /s /q DataStreamInterface\obj +rmdir /s /q DataStreamInterfaceTest\bin +rmdir /s /q DataStreamInterfaceTest\obj +rmdir /s /q DataStreamMeter\bin +rmdir /s /q DataStreamMeter\obj rmdir /s /q Decrypt\bin rmdir /s /q Decrypt\obj rmdir /s /q DeviceTest\bin