diff --git a/Common/CommonConsole/CommonConsole.csproj b/Common/CommonConsole/CommonConsole.csproj index ef56b581..c3725ba0 100644 --- a/Common/CommonConsole/CommonConsole.csproj +++ b/Common/CommonConsole/CommonConsole.csproj @@ -108,5 +108,8 @@ Common.Utils.Extensions + + + \ No newline at end of file diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index ec6598d6..d2bafc5a 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -1,6 +1,7 @@ namespace CommonConsole { using Common.Hardware.WaterMeter.OmniPlus; + using Common.Hardware.WaterMeter.OmniPlus.Features; using Common.Utils.Extensions; using System; @@ -11,13 +12,24 @@ public static void Main() { var connection = new OmniConnection(); - connection.UseIrda("COM40"); + connection.UseUniPro("COM9"); - var _params = connection.ViewSystemParameters(); - - var x1 = connection.FactorySeal(false); - var x2 = connection.FactorySeal(true); - var x3 = connection.FactorySeal(false); + var _params = connection.Set(new ConfigurationParametersSet + { + AlarmPercistancePeriodDays = 8, + BuildInfo = "816234014680", + DataLogIntervalMinutes = 60, + DeviceID = "OMNI-02", + FactoryID = "98944637", + ManifacturingTime = (UInt32)new DateTime(2023, 01, 01, 12, 0, 0).TimeOfDay.TotalSeconds, + NumberOfReadingDigits = 8, + OptionalUniDirFields = 12, + ProgrammableID = "95061881", + ReadingPreset = "00000010", + RebootCount = 0, + SystemTime = Epoch20000101.UTCNow + }); + connection.Disconnect(); @@ -82,4 +94,5 @@ return requestBytesList.ToArray(); } } -} \ No newline at end of file +} + diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/ConfigurationParameters.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/ConfigurationParameters.cs index bc1a0f27..ed5bccf7 100644 --- a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/ConfigurationParameters.cs +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/ConfigurationParameters.cs @@ -201,7 +201,10 @@ get => this.optionalFields; set { - BitConverter.GetBytes(value).CopyTo(bytes, 48); + var x = BitConverter.GetBytes(value); + + Array.Reverse(x); + x.CopyTo(bytes, 48); this.optionalFields = BitConverter.ToUInt16(this.bytes, 48); } diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/Enums/Status.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/Enums/Status.cs index cbcbb39e..1c3db25d 100644 --- a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/Enums/Status.cs +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus.Features/Enums/Status.cs @@ -47,6 +47,10 @@ /// /// Used by communication devices to indicate unrecognized communication device command. /// - UnrecognizedDevice = 0xFF + UnrecognizedDevice = 0xFF, + /// + /// Used by communication devices to indicate unrecognized communication device command. + /// + Exception = 0xEE } } \ No newline at end of file diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/CalibrationParameters.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/CalibrationParameters.cs new file mode 100644 index 00000000..c0da7ded --- /dev/null +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/CalibrationParameters.cs @@ -0,0 +1,17 @@ +namespace Common.Hardware.WaterMeter.OmniPlus +{ + using System; + + public class CalibrationParameters + { + public Byte Direction { get; set; } + + public UInt16 Fraction { get; set; } + + public Byte IntPart { get; set; } + + public Byte Range { get; set; } + + public Byte Size { get; set; } + } +} \ No newline at end of file diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/Common.Hardware.WaterMeter.OmniPlus.csproj b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/Common.Hardware.WaterMeter.OmniPlus.csproj index 9bf68a94..ae4cdf34 100644 --- a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/Common.Hardware.WaterMeter.OmniPlus.csproj +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/Common.Hardware.WaterMeter.OmniPlus.csproj @@ -41,8 +41,13 @@ + + + + + diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/Omni.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/Omni.cs new file mode 100644 index 00000000..5a6e57fb --- /dev/null +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/Omni.cs @@ -0,0 +1,31 @@ +namespace Common.Hardware.WaterMeter.OmniPlus +{ + using Common.Hardware.WaterMeter.OmniPlus.Features.Enums; + + using System; + + public class OMNI + { + public event Action StateHasChanged; + + public Boolean LastCmdCompleted { get; internal set; } + + public Status LastCmdStatus { get; internal set; } + + public String LastCmdMessage { get; internal set; } + + public String Pcb { get; internal set; } + + public DateTime ManifacturingDate { get; internal set; } + + public Boolean HasValidSystem { get; internal set; } + + public String SystemValidationMessage { get; internal set; } + + public UInt16 LastCalibrationRotations { get; internal set; } + + public Double LastCalibrationDuration { get; internal set; } + + internal void NotifyStateHasChanged() => this.StateHasChanged?.Invoke(); + } +} diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/ProgrammingBatch.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/ProgrammingBatch.cs new file mode 100644 index 00000000..9e76c819 --- /dev/null +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/ProgrammingBatch.cs @@ -0,0 +1,151 @@ +namespace Common.Hardware.WaterMeter.OmniPlus +{ + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + public class ProgrammingBatch + { + private readonly ConcurrentDictionary connections; + private readonly ConcurrentDictionary models; + + private CancellationTokenSource cancellationTokenSource; + private CancellationToken cancellationToken; + + public ProgrammingBatch() + { + this.connections = new ConcurrentDictionary(); + this.models = new ConcurrentDictionary(); + } + + public OMNI CreateForSerialPortName(String portName) + { + var connection = new OmniConnection(); + var omni = new OMNI(); + + this.connections.AddOrUpdate(portName, connection, (_portName, _connection) => + { + _connection?.Disconnect(); + + return connection; + }); + this.models.AddOrUpdate(portName, omni, (_portName, _omni) => omni); + + return omni; + } + + public void ConnectToIrda() + { + this.StartTasksForAllAndWaitUntilCompleted(programmingState => + { + programmingState.ConnectToIrda(); + }); + } + + public void ConnectToUniPro() + { + this.StartTasksForAllAndWaitUntilCompleted(programmingState => + { + programmingState.ConnectToUniPro(); + }); + } + + public void ViewSystemParameters() + { + this.StartTasksForAllAndWaitUntilCompleted(programmingState => + { + programmingState.ViewSystemParameters(); + }); + } + + public void SetCalibrationParameters(CalibrationParameters parameters) + { + this.StartTasksForAllAndWaitUntilCompleted(programmingState => + { + programmingState.SetCalibrationParameters(parameters); + }); + } + + public void StartCalibration(StartCalibrationParameters parameters) + { + this.StartTasksForAllAndWaitUntilCompleted(programmingState => + { + programmingState.StartCalibration(parameters); + }); + } + + public void StopCalibration() + { + this.StartTasksForAllAndWaitUntilCompleted(programmingState => + { + programmingState.StopCalibration(); + }); + } + + /// + /// Starts a new task for each entry in the connections dictionary. + /// + /// Callback that will be executed for each entry with the connection and its model as parameters. + private void StartTasksForAllAndWaitUntilCompleted(Action handler) + { + this.cancellationTokenSource = new CancellationTokenSource(); + this.cancellationToken = this.cancellationTokenSource.Token; + + var tasks = new List(); + + foreach (var portName in this.connections.Keys) + { + _ = this.connections.TryGetValue(portName, out var connection); + _ = this.models.TryGetValue(portName, out var omni); + + var programmingState = new ProgrammingState() + { + PortName = portName, + Connection = connection, + OMNI = omni + }; + + var task = Task.Factory.StartNew(state => + { + if (state is ProgrammingState _programmingState) + { + handler?.Invoke(_programmingState); + } + } + , programmingState, this.cancellationToken); + + tasks.Add(task); + } + + Task.Factory.ContinueWhenAll(tasks.ToArray(), this.ExceptionLogging); + } + + /// + /// By default Task dose not throwing exceptions, so the exceptions are handeled on after task callbacks. + /// If the exception of the task is not null this method logs the exception. + /// + /// A list of task to check for exceptions. + private void ExceptionLogging(Task[] tasks) + { + foreach (var task in tasks) + { + this.ExceptionLogging(task); + } + } + + /// + /// By default Task dose not throwing exceptions, so the exceptions are handeled on after task callbacks. + /// If the exception of the task is not null this method logs the exception. + /// + /// A single task to check for exception. + private void ExceptionLogging(Task task) + { + if (task.Exception != null && task.AsyncState is ProgrammingState programmingState) + { + programmingState.AddException(task.Exception); + } + } + } +} diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/ProgrammingState.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/ProgrammingState.cs new file mode 100644 index 00000000..755f69b6 --- /dev/null +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/ProgrammingState.cs @@ -0,0 +1,96 @@ +namespace Common.Hardware.WaterMeter.OmniPlus +{ + using Common.Hardware.WaterMeter.OmniPlus.Features; + using Common.Hardware.WaterMeter.OmniPlus.Features.Enums; + + using System; + + internal class ProgrammingState + { + public String PortName { get; set; } + + public OmniConnection Connection { get; set; } + + public OMNI OMNI { get; set; } + + public void ConnectToIrda() + { + this.Connection.UseIrda(this.PortName); + this.Connection.StartRecording(); + } + + public void ConnectToUniPro() + { + this.Connection.UseUniPro(this.PortName); + this.Connection.StartRecording(); + } + + public void ViewSystemParameters() + { + var systemParameters = this.Connection.ViewSystemParameters(); + + this.OMNI.LastCmdStatus = systemParameters.Status; + this.OMNI.LastCmdCompleted = systemParameters.Completed; + this.OMNI.LastCmdMessage = systemParameters.Status.ToString(); + this.OMNI.HasValidSystem = systemParameters.Completed && systemParameters.IsValid; + this.OMNI.SystemValidationMessage = systemParameters.ValidationMessage; + this.OMNI.Pcb = systemParameters.BuildInfo.Value; + this.OMNI.ManifacturingDate = systemParameters.ManifacturingTime.DateTime; + + this.OMNI.NotifyStateHasChanged(); + } + + public void SetCalibrationParameters(CalibrationParameters parameters) + { + var setInputVolumeResponse = this.Connection.Set(new InputVolume + { + Direction = parameters.Direction, + Fraction = parameters.Fraction, + IntPart = parameters.IntPart, + Range = parameters.Range, + Size = parameters.Size + }); + + this.OMNI.LastCmdStatus = setInputVolumeResponse.Status; + this.OMNI.LastCmdCompleted = setInputVolumeResponse.Completed; + this.OMNI.LastCmdMessage = setInputVolumeResponse.Status.ToString(); + + this.OMNI.NotifyStateHasChanged(); + } + + public void StartCalibration(StartCalibrationParameters parameters) + { + var startCalibrationResponse = this.Connection.StartChamberCalibration( + parameters.Rotations, + parameters.Duration); + + this.OMNI.LastCmdStatus = startCalibrationResponse.Status; + this.OMNI.LastCmdCompleted = startCalibrationResponse.Completed; + this.OMNI.LastCmdMessage = startCalibrationResponse.Status.ToString(); + + this.OMNI.NotifyStateHasChanged(); + } + + public void StopCalibration() + { + var viewCalibrationResponse = this.Connection.ViewChamberCalibration(); + + this.OMNI.LastCmdStatus = viewCalibrationResponse.Status; + this.OMNI.LastCmdCompleted = viewCalibrationResponse.Completed; + this.OMNI.LastCmdMessage = viewCalibrationResponse.Status.ToString(); + this.OMNI.LastCalibrationRotations = viewCalibrationResponse.Rotations; + this.OMNI.LastCalibrationDuration = viewCalibrationResponse.DurationSec; + + this.OMNI.NotifyStateHasChanged(); + } + + internal void AddException(Exception exception) + { + this.OMNI.LastCmdCompleted = false; + this.OMNI.LastCmdStatus = Status.Exception; + this.OMNI.LastCmdMessage = $"{this.OMNI.LastCmdMessage}{Environment.NewLine}{Status.Exception}{Environment.NewLine}{exception}"; + + this.OMNI.NotifyStateHasChanged(); + } + } +} \ No newline at end of file diff --git a/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/StartCalibrationParameters.cs b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/StartCalibrationParameters.cs new file mode 100644 index 00000000..a62c4704 --- /dev/null +++ b/Common/Hardware/WaterMeter/OmniPlus/Common.Hardware.WaterMeter.OmniPlus/StartCalibrationParameters.cs @@ -0,0 +1,11 @@ +namespace Common.Hardware.WaterMeter.OmniPlus +{ + using System; + + public class StartCalibrationParameters + { + public UInt16 Rotations { get; set; } + + public UInt16 Duration { get; set; } + } +} \ No newline at end of file diff --git a/Common/OmniPlus/InspectionUI/App.config b/Common/OmniPlus/InspectionUI/App.config index f2d22ac7..1fbae926 100644 --- a/Common/OmniPlus/InspectionUI/App.config +++ b/Common/OmniPlus/InspectionUI/App.config @@ -10,6 +10,7 @@ + diff --git a/Common/OmniPlus/InspectionUI/App.xaml b/Common/OmniPlus/InspectionUI/App.xaml index 27ba5371..766f7bb6 100644 --- a/Common/OmniPlus/InspectionUI/App.xaml +++ b/Common/OmniPlus/InspectionUI/App.xaml @@ -2,7 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Converters="clr-namespace:InspectionUI.Converters" - StartupUri="MainWindow.xaml"> + StartupUri="Omni/Views/OmniInspection.xaml" > + diff --git a/Common/OmniPlus/InspectionUI/App.xaml.cs b/Common/OmniPlus/InspectionUI/App.xaml.cs index eb28bf08..bb99edcc 100644 --- a/Common/OmniPlus/InspectionUI/App.xaml.cs +++ b/Common/OmniPlus/InspectionUI/App.xaml.cs @@ -12,7 +12,7 @@ internal static event Action Exiting; - internal static readonly IAppsettings Appsettings = new Appsettings(); + internal static IAppsettings Appsettings => InspectionUI.Appsettings.Current; protected override void OnExit(ExitEventArgs e) => Exiting?.Invoke(); diff --git a/Common/OmniPlus/InspectionUI/InspectionUI.csproj b/Common/OmniPlus/InspectionUI/InspectionUI.csproj index f96f9be0..58c58622 100644 --- a/Common/OmniPlus/InspectionUI/InspectionUI.csproj +++ b/Common/OmniPlus/InspectionUI/InspectionUI.csproj @@ -75,6 +75,14 @@ ItemsGrid.xaml + + + + + + + OmniInspection.xaml + @@ -108,6 +116,10 @@ MainWindow.xaml Code + + Designer + MSBuild:Compile + @@ -144,6 +156,14 @@ + + {6480CC2A-AB54-4A26-8413-D5141431C080} + Common.Hardware.WaterMeter.OmniPlus + + + {62490923-CD17-45A6-B79F-A027927C75B5} + Common.Logic.Extensions.SQL + {C6BFAC88-5647-4131-90B1-4D6265E08348} InspectionUI.Abstraction @@ -164,6 +184,7 @@ false + diff --git a/Common/OmniPlus/InspectionUI/Omni/Models/DatabaseM.cs b/Common/OmniPlus/InspectionUI/Omni/Models/DatabaseM.cs new file mode 100644 index 00000000..a0f53990 --- /dev/null +++ b/Common/OmniPlus/InspectionUI/Omni/Models/DatabaseM.cs @@ -0,0 +1,33 @@ +namespace InspectionUI.Omni.Models +{ + using Common.Logic.Extensions.SQL; + using Common.Logic.Extensions.SQL.Interfaces; + + using System; + + internal class DataM + { + private readonly ISQLConnection mssql; + + public DataM() + { + var connectionString = Appsettings.Current["MSSQL.Auftrag"]; + this.mssql = SQLConnection.CreateSQLConnection(connectionString, this.OnSqlError); + } + + public void LoadOrderHead() + { + + } + + public void LoadTestRun() + { + throw new NotImplementedException(); + } + + public void OnSqlError(String error) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Common/OmniPlus/InspectionUI/Omni/Models/OmniInspectionM.cs b/Common/OmniPlus/InspectionUI/Omni/Models/OmniInspectionM.cs new file mode 100644 index 00000000..5fb23c58 --- /dev/null +++ b/Common/OmniPlus/InspectionUI/Omni/Models/OmniInspectionM.cs @@ -0,0 +1,26 @@ +namespace InspectionUI.Omni.Models +{ + internal class OmniInspectionM + { + private readonly Appsettings appsettings; + private readonly DataM dataModel; + private readonly RemoteConnectionM remoteConnectionModel; + private readonly ProgrammingBatchM programmingBatchModel; + + public OmniInspectionM(Appsettings appsettings) + { + this.appsettings = appsettings; + this.dataModel = new DataM(); + this.remoteConnectionModel = new RemoteConnectionM(); + this.programmingBatchModel = new ProgrammingBatchM(); + } + + public void Initialize() + { + this.remoteConnectionModel.LoadTestBenchInfo(); + this.dataModel.LoadOrderHead(); + this.dataModel.LoadTestRun(); + this.programmingBatchModel.LoadMeters(); + } + } +} diff --git a/Common/OmniPlus/InspectionUI/Omni/Models/ProgrammingBatchM.cs b/Common/OmniPlus/InspectionUI/Omni/Models/ProgrammingBatchM.cs new file mode 100644 index 00000000..599de0a4 --- /dev/null +++ b/Common/OmniPlus/InspectionUI/Omni/Models/ProgrammingBatchM.cs @@ -0,0 +1,20 @@ +namespace InspectionUI.Omni.Models +{ + using System; + using Common.Hardware.WaterMeter.OmniPlus; + + internal class ProgrammingBatchM + { + private readonly ProgrammingBatch programmingBatch; + + public ProgrammingBatchM() + { + this.programmingBatch = new ProgrammingBatch(); + } + + public void LoadMeters() + { + throw new NotImplementedException(); + } + } +} diff --git a/Common/OmniPlus/InspectionUI/Omni/Models/RemoteConnectionM.cs b/Common/OmniPlus/InspectionUI/Omni/Models/RemoteConnectionM.cs new file mode 100644 index 00000000..bf7bc5e0 --- /dev/null +++ b/Common/OmniPlus/InspectionUI/Omni/Models/RemoteConnectionM.cs @@ -0,0 +1,17 @@ +namespace InspectionUI.Omni.Models +{ + using System; + using InspectionUI.RemoteControl; + + public class RemoteConnectionM + { + private readonly RemoteConnection connection; + + public RemoteConnectionM() => this.connection = new RemoteConnection(); + + internal void LoadTestBenchInfo() + { + throw new NotImplementedException(); + } + } +} diff --git a/Common/OmniPlus/InspectionUI/Omni/ViewModels/OmniInspectionVM.cs b/Common/OmniPlus/InspectionUI/Omni/ViewModels/OmniInspectionVM.cs new file mode 100644 index 00000000..1bfd4821 --- /dev/null +++ b/Common/OmniPlus/InspectionUI/Omni/ViewModels/OmniInspectionVM.cs @@ -0,0 +1,26 @@ +namespace InspectionUI.Omni.ViewModels +{ + using InspectionUI.Omni.Models; + + using System; + + internal class OmniInspectionVM + { + private readonly OmniInspectionM model; + + public OmniInspectionVM() + { + this.model = new OmniInspectionM(Appsettings.Current); + } + + public String OrderNo { get; set; } + + public String PosNo { get; set; } + + public String ProductionOrderNumber { get; set; } + + public String IdentNo { get; set; } + + public String Type { get; set; } + } +} diff --git a/Common/OmniPlus/InspectionUI/Omni/Views/OmniInspection.xaml b/Common/OmniPlus/InspectionUI/Omni/Views/OmniInspection.xaml new file mode 100644 index 00000000..cca7cd00 --- /dev/null +++ b/Common/OmniPlus/InspectionUI/Omni/Views/OmniInspection.xaml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +