ProductionUiCordonel: - re-organized to support multiple production processes part 8

This commit is contained in:
Thomas Wiedebusch
2025-04-15 12:22:20 +02:00
parent c57e7bf377
commit 30c056f128
11 changed files with 30 additions and 285 deletions
@@ -21,7 +21,6 @@ using Xylem.Common.CommonCore.Consts;
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.Enum;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EolProcesses;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EventArgs;
using Xylem.Common.Utils.Logging;
using Xylem.Common.Utils.UserAccessCtrl;
@@ -54,7 +53,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel
// maximum processing steps for calculation of progress bar
private Int32 _maxOverallProcessSteps;
private Int32 _maxSingleProcessSteps;
private BaseProcessController _processCtrl;
private ProcessController _processCtrl;
private DateTimeOffset _startTime;
private DispatcherTimer _timer;
private String _lastLoggingTextToAvoidRepetition;
@@ -178,7 +177,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel
try
{
_processCtrl = new EolStateMachine(Slot);
_processCtrl = new ProcessController(Slot);
}
catch (Exception ex)
{
@@ -54,7 +54,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel
// maximum processing steps for calculation of progress bar
private Int32 _maxOverallProcessSteps;
private Int32 _maxSingleProcessSteps;
private BaseProcessController _processCtrl;
private ProcessController _processCtrl;
private DateTimeOffset _startTime;
private DispatcherTimer _timer;
private String _lastLoggingTextToAvoidRepetition;
@@ -178,7 +178,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel
try
{
_processCtrl = new EolStateMachine(Slot);
_processCtrl = new ProcessController(Slot);
}
catch (Exception ex)
{
@@ -1,144 +0,0 @@
using System;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.Enum;
namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EolProcesses
{
/// <summary>
/// Preparing the Cordonel for shipping:
/// - Setup device with standard parameters covered by the VAKO or customer specific CSD,
/// - If radio is installed: radio test,
/// - Requiring radio key from LuDB,
/// - Requiring 7 passwords for the Cordonel access levels,
/// - Building the password file (Level 3 is the modified skeleton key),
/// - Store all configurations,
/// - Reboot the Cordonel to load all settings from FLASH to RAM,
/// - Configuration check of all parameters defined by VAKO and CSD.
/// </summary>
public sealed class EolStateMachine : BaseProcessController, IProcessController
{
#region ------------------------------------------ Variables --------------------------------------------------
//
#endregion --------------------------------------- Variables --------------------------------------------------
#region ------------------------------------------ Class ------------------------------------------------------
/// <summary>
/// Ctor
/// </summary>
/// <param name="slot">physical slot for this meter</param>
/// <remarks date="2025-Apr-14" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public EolStateMachine(Int32 slot) : base(slot)
{
}
#endregion --------------------------------------- Class ------------------------------------------------------
#region ------------------------------------------ Events -----------------------------------------------------
//
#endregion --------------------------------------- Events -----------------------------------------------------
#region ------------------------------------------ State Machine ----------------------------------------------
/// <inheritdoc/>
/// <summary>
/// State machine of FinalProcessController which serves as preparation for SHIPPING named EOL (End-Of-Line).
/// </summary>
/// <remarks date="2023-Jan-17" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public override void IndividualStateMachine(ProcessStateStruct processStateStruct)
{
switch (_stateMachineState)
{
case ProcessState.GetProgrammingParameters:
// Precondition: - The connection process has to be completed as a readout of some register
// values from the Cordonel are needed to check the update capability:
// - Wait on completed connection process before starting this process.
// AVOID to change the process state on completion as parallel process is active!
StartProcess(processStateStruct);
// Do not wait on completion as new parallel process can be started by manually state change.
_stateMachineState = ProcessState.CheckProductionState;
break;
case ProcessState.CheckProductionState:
// Precondition: - The connection process has to be completed as a readout of some register
// values from the Cordonel are needed to check the update capability:
// - Wait on completed connection process before starting this process.
// AVOID to change the process state on completion as parallel process is active!
StartProcess(processStateStruct);
// Do not wait on completion as new parallel process can be started by manually state change.
_stateMachineState = ProcessState.ProcessPasswordFile;
break;
case ProcessState.ProcessPasswordFile:
// Precondition: - The connection process has to be completed as a password change in the DB
// will take place: Skeleton to Password Level 8. Not waiting for completion may cause side
// effects on login. Wait for all processes to complete.
// Leave state switch to automatic to avoid side effects on incomplete updated DB for next
// steps.
StartProcess(processStateStruct);
break;
case ProcessState.ExecFinalParametrization:
// This writes all setups to the device, it has to be executed exclusively with automatic
StartProcess(processStateStruct);
break;
case ProcessState.ExecStoreConfiguration:
// Precondition: - The final parametrization has to be finished as this shall be stored
// to non-volatile memory and checked if remaining valid after the reboot.
// Store configuration has to be executed exclusively with automatic
StartProcess(processStateStruct);
break;
case ProcessState.RebootCordonel:
// Precondition: - The store configuration has to be executed to safe all settings
// to non-volatile memory and checked if remaining valid after the reboot.
// Reboot has to be executed exclusively with automatic
StartProcess(processStateStruct);
break;
case ProcessState.CheckFinalParametrization:
// Precondition: - The reboot process including the store all configurations has to be
// completed.
// Check final configuration has to be executed exclusively with automatic
StartProcess(processStateStruct);
break;
case ProcessState.CheckRadio:
// Precondition: - The final parametrization, reboot process including the store all
// configurations and the check of all setups survived the reboot have to be completed.
// Radio signal level check, skipped on NA region or if skipping is required by special
// approval
StartProcess(processStateStruct);
break;
case ProcessState.CheckAttachments:
// Precondition: - All checks have to be executed with positive result
StartProcess(processStateStruct);
break;
case ProcessState.ExecVisualInspection:
// Precondition: - All checks have to be executed with positive result
StartProcess(processStateStruct);
break;
case ProcessState.PrepareShippingMode:
// Precondition: - All checks have to be executed with positive result
StartProcess(processStateStruct);
break;
case ProcessState.ReadyForShipping:
_stateMachineState = ProcessState.Idle;
break;
default:
_stateMachineState = ProcessState.Idle;
break;
}
}
#endregion --------------------------------------- State Machine ----------------------------------------------
#region ------------------------------------------ Tools ------------------------------------------------------
//
#endregion --------------------------------------- Tools ------------------------------------------------------
}
}
@@ -14,7 +14,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EolPr
/// <remarks date="2023-Feb-14" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
public class EolStateMachineCtrl : BaseProcessStates
public class EolStateMachineDef : BaseProcessStates
{
/// <summary>
/// State-machine definitions of production-processes which feeds the state-machine.
@@ -51,7 +51,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EolPr
/// - set the "waitForAllProcesses" to true.
///
/// </summary>
public EolStateMachineCtrl()
public EolStateMachineDef()
{
var stateContainer = new List<ProcessStateStruct>
{
@@ -66,7 +66,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EolPr
/// <remarks date="2023-Jul-11" author="Thomas Wiedebusch">
/// - Speed up to quick return if passwords are already set.
///
/// ATTENTION: This requires to remove those on new PcbId <see cref="BaseProcessController"/>
/// ATTENTION: This requires to remove those on new PcbId <see cref="ProcessController"/>
/// for CheckMeterChange!
///
/// </remarks>
@@ -39,7 +39,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EolPr
/// <remarks date="2023-Jul-11" author="Thomas Wiedebusch">
/// - Speed up to quick return if programming parameters are already set.
///
/// ATTENTION: This requires to remove those on new PcbId <see cref="BaseProcessController"/>
/// ATTENTION: This requires to remove those on new PcbId <see cref="ProcessController"/>
/// for CheckMeterChange!
/// </remarks>
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
@@ -1,12 +0,0 @@
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.Enum;
namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
{
public interface IProcessController
{
/// <summary>
/// Individual states to fill the state machine.
/// ATTENTION: All states have to be part of the <see cref="ProcessState"/>
/// </summary>
void IndividualStateMachine(ProcessStateStruct processStateStruct);
}
}
@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Controls;
using LaaPackages.Features.Cordonel.Models;
using Xylem.Common.CommonCore.Consts;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.Enum;
using Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.EventArgs;
namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
{
public interface IProcessStates
{
}
}
@@ -17,7 +17,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
/// <summary>
/// Implementation for all methods needed to drive the state machine of the process controller
/// </summary>
public abstract class BaseProcessController : IProcessController
public class ProcessController
{
#region ------------------------------------------ Variables --------------------------------------------------
// actual genesis meter
@@ -31,7 +31,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
// batch just used for setup, as only one meter will be assigned
private MeterBatch _meterBatch;
// state of the state machine
protected ProcessState _stateMachineState;
private ProcessState _stateMachineState;
// locker to avoid repeated state execution
private ProcessState _lockedProcessState;
// sender of state change event to evaluate in e.g. error process
@@ -44,7 +44,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
}
// Container for production process states
protected BaseProcessStates _processStateDef;
private BaseProcessStates _processStateDef;
// Container for production status information, a list is used to keep the content over all classes of production
// processes as a reference seems not to return their value (always reset to the initial value)
@@ -121,7 +121,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
/// - Always RegisterWatchService on,
/// - Always MinMaxCHeck on.
/// </remarks>
protected BaseProcessController(Int32 slot)
public ProcessController(Int32 slot)
{
_processCtrlTimer = new Timer(TmrProcessCtrlCycle_Elapsed, null, ProcessTimerCycleMs, ProcessTimerCycleMs);
_slot = slot;
@@ -286,62 +286,18 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
/// </remarks>
private void TmrProcessCtrlCycle_Elapsed(Object state)
{
GenericStateMachine();
StateMachine();
}
#endregion --------------------------------------- Events -----------------------------------------------------
#region ------------------------------------------ State Machine ----------------------------------------------
/// <inheritdoc/>
public abstract void IndividualStateMachine(ProcessStateStruct processSatProcessStateStruct);
/// <summary>
/// State machine of ProcessController which serves as template for all production processes.
/// State-machine of ProcessController which serves all production processes.
/// This-state machine executes all states defined in the "GenericStateMachineDef" and the individual
/// production-process specific "XxxStateMachineDef".
///
///
/// INSTRUCTION FOR NORMAL USAGE:
/// -----------------------------
/// Call the SetupProcess() with the
/// - new process automatically collected from <see cref="BaseProcessStates.GetProcessOfState"/> with new
/// _actualProcessState as input,
/// - successExitState set to the next required state after successfully execution.
/// That's it! The normal state change has always only one production process active and waits for completion
/// before changing to a new state and therefore a new production process.
///
/// If a special state is needed on errorExitState or breakExitState these can be assigned. Otherwise, the
/// errorExitState is linked to the error state, the breakExitState to the stop state.
///
///
/// INSTRUCTION FOR NON-BLOCKING MULTIPLE PROCESSES SIMULTANEOUSLY ACTIVITIES:
/// --------------------------------------------------------------------------
/// Sometimes production processes may be able to be executed simultaneously as they are independent of each
/// other. One example is a database access for data collection from different tables.
///
/// Call the SetupProcess with the
/// - new process automatically collected from <see cref="BaseProcessStates.GetProcessOfState"/> with new
/// _actualProcessState as input,
/// - successExitState being set to <see cref="BaseProductionProcess.DoNotChangeStateAfterCompletion"/> (null).
/// This will lock the sate change after completion as multiple processes may be active and a state change after
/// completion may cause unpredictable operation, the state is already where it should be (manually changed),
/// - change the state after the SetupProcess() call manually.
///
/// This is needed for non-blocking immediately new state change (not waiting for the successful execution of
/// the actual new assigned process):
/// E.g. all DB accesses need a certain time to get data, kicking off (fire and forget) the process without
/// waiting for the result, the exitSuccessState has to be set to null to avoid a state change on successfully
/// execution of the process. Instead, change the state here to go ahead with the next state. This forces a wait
/// on the state who needs the data from the "fire and forget" states, SEE next instruction how to proceed!
///
///
/// INSTRUCTION TO DELAY THE START OF A PROCESS:
/// --------------------------------------------
/// Each new process execution can be delayed as it may need the result of another process which is active.
///
/// Wait for a single process to complete:
/// - set the "waitForSingleProcess" to the process to wait for.
/// Wait for all preceding processes to complete:
/// - set the "waitForAllProcesses" to true.
///
/// A few states with special functions will be caught in advance in this StateMachine
/// </summary>
/// <remarks date="2023-Jan-17" author="Thomas Wiedebusch">
/// - Initial
@@ -349,7 +305,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
/// <remarks date="2025-Apr-15" author="Thomas Wiedebusch">
/// - Generic implementation
/// </remarks>
private void GenericStateMachine()
private void StateMachine()
{// avoid repeated execution of the state machine on unchanged state
if (_stateMachineState == _lockedProcessState)
{
@@ -371,9 +327,6 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
// get the processStateStruct of the actual set stateMachineSTate
var processStateStruct = _processStateDef.GetProcessStateStructOfState(_stateMachineState);
// get the actual required process from the state definition list
//var process = _processStateDef?.GetProcessOfState(_stateMachineState);
switch (_stateMachineState)
{
case ProcessState.Idle:
@@ -384,7 +337,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
// Wait for cancellation
if (_cancellationToken.IsCancellationRequested)
{
Thread.Sleep(1000);
Thread.Sleep(500);
// Reset the cancellation request
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = new CancellationTokenSource();
@@ -407,44 +360,11 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
_stateMachineState = CheckForNewMeter() ? ProcessState.DetectCordonel : ProcessState.ConnectCordonel;
break;
case ProcessState.ConnectCordonel:
// Precondition: - The detection process has to be completed as the PcbId is needed.
// AVOID to change the process state on completion as parallel process is active!
StartProcess(processStateStruct);
// Do not wait on completion as new parallel process can be started by manually state change.
_stateMachineState = ProcessState.GetSerialNumberAndRadioAddress;
break;
case ProcessState.GetSerialNumberAndRadioAddress:
// Precondition: - The detection process has to be completed as the PcbId is needed.
// AVOID to change the process state on completion as parallel process is active!
StartProcess(processStateStruct);
// Do not wait on completion as new parallel process can be started by manually state change.
_stateMachineState = ProcessState.GetProgrammingParameters;
break;
case ProcessState.CheckOrderNumber:
// This scans the order number, it has to be executed exclusively with automatic
StartProcess(processStateStruct);
break;
case ProcessState.CheckSerialNumber:
// This scans the serial number, it has to be executed exclusively with automatic
StartProcess(processStateStruct);
break;
case ProcessState.RepeatFailedTests:
_stateMachineState = RepeatFailedTests();
break;
case ProcessState.PrintReturnReport:
_stateMachineState = ProcessState.Idle;
break;
case ProcessState.PrintSuccessReport:
_stateMachineState = ProcessState.Idle;
break;
case ProcessState.AbortTest:
AbortProcesses();
_stateMachineState = ProcessState.Idle;
@@ -469,8 +389,12 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
break;
default:
// This is the call to the processes for a specific test e.g. EOL or Picking
IndividualStateMachine(processStateStruct);
// This is the call to the processes for a specific test
StartProcess(processStateStruct);
if (processStateStruct.KickOffParallelState != null)
{
_stateMachineState = (ProcessState)processStateStruct.KickOffParallelState;
}
break;
}
}
@@ -675,7 +599,7 @@ namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses
if (Processes == null)
Processes = new List<IProductionProcess>();
if (_processStateDef == null)
_processStateDef = new EolStateMachineCtrl();
_processStateDef = new EolStateMachineDef();
// get all processes relevant for EOL from table which has to be sorted
var processes = _processStateDef.GetAllEolRelevantProcesses();
@@ -289,7 +289,7 @@
<Compile Include="Model\EOLHandler.cs" />
<Compile Include="ProductionProcesses\Enum\PickingProcessState.cs" />
<Compile Include="ProductionProcesses\EolProcesses\VisualInspection.cs" />
<Compile Include="ProductionProcesses\GenericStateMachineCtrl.cs" />
<Compile Include="ProductionProcesses\GenericStateMachineDef.cs" />
<Compile Include="ProductionProcesses\GenericProcesses\ErrorHandler.cs" />
<Compile Include="ProductionProcesses\EolProcesses\ExecStoreConfiguration.cs" />
<Compile Include="ProductionProcesses\GenericProcesses\GetSerialNumberAndRadioAddress.cs" />
@@ -300,10 +300,7 @@
<Compile Include="ProductionProcesses\Enum\ImgState.cs" />
<Compile Include="ProductionProcesses\Enum\ProcessState.cs" />
<Compile Include="ProductionProcesses\EventArgs\SingleProcessStateArgs.cs" />
<Compile Include="ProductionProcesses\EolProcesses\EolStateMachineCtrl.cs" />
<Compile Include="ProductionProcesses\EolProcesses\EolStateMachine.cs" />
<Compile Include="ProductionProcesses\IProcessController.cs" />
<Compile Include="ProductionProcesses\IProcessStates.cs" />
<Compile Include="ProductionProcesses\EolProcesses\EolStateMachineDef.cs" />
<Compile Include="ProductionProcesses\ProcessStateStruct.cs" />
<Compile Include="Data\PickingResultData.cs" />
<Compile Include="Data\PressureResultDataNotifyable.cs" />
@@ -334,7 +331,7 @@
<Compile Include="ProductionProcesses\BaseProductionProcess.cs" />
<Compile Include="ProductionProcesses\Enum\SingleProcessState.cs" />
<Compile Include="ProductionProcesses\IProductionProcess.cs" />
<Compile Include="ProductionProcesses\BaseProcessController.cs" />
<Compile Include="ProductionProcesses\ProcessController.cs" />
<Compile Include="ProductionProcesses\EventArgs\ProcessStateArgs.cs" />
<Compile Include="ProductionProcesses\EventArgs\ProcessLogArgs.cs" />
<Compile Include="ProductionProcesses\EventArgs\ProcessProgressArgs.cs" />