omni database scripts

This commit is contained in:
Stoyan Zlatev
2023-11-09 10:34:37 +01:00
parent a0d1625121
commit 6ee0244402
3 changed files with 146 additions and 19 deletions
+3
View File
@@ -95,5 +95,8 @@
<Compile Include="Options\SerialPortOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="OmniPlusDatabase.sql" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+19 -19
View File
@@ -1,4 +1,4 @@
using OmniPipes;
//using OmniPipes;
using OmniPlus.Connections;
using OmniPlus.Features;
@@ -21,7 +21,7 @@ namespace OmniPlus.UI.Inspection
private readonly ConcurrentDictionary<int, OmniPlusConnection> connections;
private readonly ConcurrentDictionary<int, OmniPlusMeter> meters;
private readonly ConcurrentDictionary<int, Task> tasks;
private readonly NamedPipeClient namedPipeClient;
//private readonly NamedPipeClient namedPipeClient;
private readonly OmniPlusDatabase database;
private bool available;
@@ -31,7 +31,7 @@ namespace OmniPlus.UI.Inspection
{
this.connections = new ConcurrentDictionary<int, OmniPlusConnection>();
this.meters = new ConcurrentDictionary<int, OmniPlusMeter>();
this.namedPipeClient = new NamedPipeClient();
//this.namedPipeClient = new NamedPipeClient();
this.database = new OmniPlusDatabase(dbConnectionString);
}
@@ -53,19 +53,19 @@ namespace OmniPlus.UI.Inspection
connection?.Disconnect();
}
this.namedPipeClient.Connected -= this.NamedPipeClient_Connected;
this.namedPipeClient.Disconnected -= this.NamedPipeClient_Disconnected;
//this.namedPipeClient.Connected -= this.NamedPipeClient_Connected;
//this.namedPipeClient.Disconnected -= this.NamedPipeClient_Disconnected;
this.namedPipeClient.Disconnect();
//this.namedPipeClient.Disconnect();
this.connections.Clear();
this.meters.Clear();
}
public void InitializeInspection(params string[] portNames)
{
this.namedPipeClient.Connected += this.NamedPipeClient_Connected;
this.namedPipeClient.Disconnected += this.NamedPipeClient_Disconnected;
this.namedPipeClient.Connect();
//this.namedPipeClient.Connected += this.NamedPipeClient_Connected;
//this.namedPipeClient.Disconnected += this.NamedPipeClient_Disconnected;
//this.namedPipeClient.Connect();
OmniPlusConnection connection;
OmniPlusMeter meter;
@@ -174,7 +174,7 @@ namespace OmniPlus.UI.Inspection
foreach (var point in inspectionPoints)
{
this.namedPipeClient.RequestFlowRate(point.FlowRate);
//this.namedPipeClient.RequestFlowRate(point.FlowRate);
foreach (var position in this.connections.Keys)
{
@@ -183,12 +183,12 @@ namespace OmniPlus.UI.Inspection
factory.ContinueWhenAll(this.tasks.Values.ToArray(), _ => { });
var volume = this.namedPipeClient.RequestReference();
//var volume = this.namedPipeClient.RequestReference();
foreach (var meter in this.meters.Values)
{
meter.AddInspectionVolume(point, volume);
}
//foreach (var meter in this.meters.Values)
//{
// meter.AddInspectionVolume(point, volume);
//}
}
foreach(var position in this.connections.Keys)
@@ -319,10 +319,10 @@ namespace OmniPlus.UI.Inspection
canContinue = systemTimeReset.Succeeded;
}
if (canContinue)
{
var registerSettings = connection.ViewRegisterSettings();
}
//if (canContinue)
//{
// var registerSettings = connection.ViewRegisterSettings();
//}
}
else // meter or connection not in use
{
+124
View File
@@ -0,0 +1,124 @@
USE [AuftragKopie];
IF OBJECT_ID(N'OmniTestPoints') IS NOT NULL BEGIN DROP TABLE [OmniTestPoints] END
IF OBJECT_ID(N'OmniTypes') IS NOT NULL BEGIN DROP TABLE [OmniTypes] END
CREATE TABLE [OmniTypes] (
[Id] TINYINT NOT NULL IDENTITY(1, 1),
[Type] VARCHAR(5) NOT NULL,
[Size] TINYINT NOT NULL,
[Range] TINYINT NOT NULL,
[Direction] TINYINT NOT NULL,
[IntPart] TINYINT NOT NULL,
[Fraction] INT NOT NULL,
[FractionLSB] TINYINT NOT NULL,
[FractionMSB] TINYINT NOT NULL,
[CorrectionFactor] SMALLINT NOT NULL,
[PulsePerRotation] TINYINT NOT NULL,
[MlPerPulse] FLOAT NULL
CONSTRAINT [PK_OmniTypes_Id] PRIMARY KEY ([Id])
);
SET IDENTITY_INSERT [OmniTypes] ON
INSERT INTO [OmniTypes]
([Id], [Type], [Size], [Range], [Direction], [IntPart], [Fraction], [FractionLSB], [FractionMSB], [CorrectionFactor], [PulsePerRotation])
VALUES ( 1, '1½"', 0x05, 0x00, 0x00, 0x00, 34017, 0xE1, 0x84, 100, 8)
, ( 2, '2"', 0x06, 0x00, 0x00, 0x00, 34017, 0xE1, 0x84, 100, 8)
, ( 3, '3"', 0x07, 0x01, 0x00, 0x01, 50827, 0x8B, 0xC6, 100, 8)
, ( 4, '4"', 0x08, 0x01, 0x00, 0x01, 50827, 0x8B, 0xC6, 100, 8)
, ( 5, '6"', 0x09, 0x02, 0x00, 0x06, 16754, 0x72, 0x41, 100, 8)
, ( 6, '8"', 0x0A, 0x03, 0x80, 0x01, 36814, 0xCE, 0x8F, 1000, 8)
, ( 7, '10"', 0x0B, 0x04, 0x80, 0x02, 21667, 0xA3, 0x54, 1000, 8);
SET IDENTITY_INSERT [OmniTypes] OFF
UPDATE [OmniTypes] SET [MlPerPulse] = ([IntPart] + [Fraction] / 65535) * [CorrectionFactor];
CREATE TABLE [OmniTestPoints] (
[Id] SMALLINT NOT NULL IDENTITY(1, 1),
[OmniTypeId] TINYINT NOT NULL,
[GalPerMin] FLOAT NOT NULL,
[Rotations] SMALLINT NOT NULL,
[Duration] SMALLINT NOT NULL,
[Enabled] BIT NOT NULL DEFAULT(0)
CONSTRAINT [PK_OmniTestPoints_Id] PRIMARY KEY ([Id]),
CONSTRAINT [FK_OmniTestPoints_OmniTypeId_OmniPlus_Id] FOREIGN KEY ([OmniTypeId]) REFERENCES [OmniTypes]([Id]),
CONSTRAINT [CHK_OmniTestPoints_Rotations] CHECK ([Rotations] BETWEEN 1 AND 5000),
CONSTRAINT [CHK_OmniTestPoints_Duration] CHECK ([Duration] BETWEEN 1 AND 3600)
);
INSERT INTO [OmniTestPoints]
([OmniTypeId], [GalPerMin], [Rotations], [Duration])
------------------------------------------------------
VALUES ( 1, 200.00, 900, 36)
, ( 1, 160.00, 700, 35)
, ( 1, 150.00, 600, 32)
, ( 1, 2.50, 10, 32)
, ( 1, 2.00, 8, 32)
, ( 1, 1.50, 6, 32)
, ( 1, 1.25, 6, 38)
, ( 1, 1.00, 4, 32)
, ( 1, 0.75, 4, 43)
, ( 1, 0.25, 4, 127)
------------------------------------------------------
, ( 2, 200.00, 1000, 40)
, ( 2, 160.00, 800, 40)
, ( 2, 2.50, 10, 32)
, ( 2, 1.50, 8, 43)
, ( 2, 0.25, 4, 127)
------------------------------------------------------
, ( 3, 500.00, 700, 38)
, ( 3, 400.00, 580, 40)
, ( 3, 350.00, 450, 35)
, ( 3, 20.00, 30, 41)
, ( 3, 10.00, 16, 44)
, ( 3, 2.50, 4, 44)
, ( 3, 2.00, 4, 55)
, ( 3, 1.50, 4, 73)
, ( 3, 0.50, 4, 217)
------------------------------------------------------
, ( 4, 1000.00, 1200, 33)
, ( 4, 800.00, 1100, 38)
, ( 4, 30.00, 40, 37)
, ( 4, 3.00, 4, 37)
, ( 4, 2.00, 4, 55)
, ( 4, 1.50, 4, 73)
, ( 4, 0.75, 4, 145)
------------------------------------------------------
, ( 5, 2000.00, 800, 39)
, ( 5, 1600.00, 660, 40)
, ( 5, 50.00, 20, 39)
, ( 5, 5.00, 4, 77)
, ( 5, 4.00, 4, 96)
, ( 5, 3.00, 4, 127)
, ( 5, 2.50, 4, 153)
, ( 5, 1.50, 4, 254)
------------------------------------------------------
, ( 6, 3500.00, 500, 34)
, ( 6, 2700.00, 400, 36)
, ( 6, 7.00, 4, 136)
, ( 6, 5.00, 4, 191)
, ( 6, 4.00, 4, 238)
, ( 6, 3.00, 4, 317)
, ( 6, 2.50, 4, 381)
------------------------------------------------------
, ( 7, 5500.00, 550, 36)
, ( 7, 4000.00, 400, 36)
, ( 7, 2500.00, 260, 37)
, ( 7, 14.00, 4, 102)
, ( 7, 5.00, 4, 284)
, ( 7, 3.50, 4, 406);
UPDATE [OmniTestPoints]
SET [Enabled] = 1
FROM [OmniTestPoints] AS [Current]
JOIN (SELECT [OmniTypeId] AS [TypeId]
, MIN([GalPerMin]) AS [Min]
, MAX([GalPerMin]) AS [Max]
FROM [OmniTestPoints]
GROUP BY [OmniTypeId])
AS [Aggregated]
ON [Aggregated].[TypeId] = [Current].[OmniTypeId]
AND ([Aggregated].[Min] = [Current].[GalPerMin]
OR [Aggregated].[Max] = [Current].[GalPerMin])