--- source_files: - Common/DTS.Common.DataModel/Classes/Arming/Arming.cs generated_at: "2026-04-17T15:43:00.640638+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "f820a35e3a0ae97a" --- # Documentation: Arming Class ## 1. Purpose The `Arming` class orchestrates the complete arming sequence for Data Acquisition System (DAS) devices. It manages configuration application, flash memory clearing, pre-arm validation (including level trigger checks), and the final arm execution. This class serves as the primary controller for transitioning DAS hardware from an idle state to an armed, trigger-ready state in test measurement scenarios. --- ## 2. Public Interface ### `Arming()` **Signature:** `public Arming()` Default constructor. Initializes a new instance with a `Configuration` object. --- ### `SetConfigAndFlashClear` **Signature:** ```csharp public bool SetConfigAndStartFlashClear( DataModel.TestTemplate currentTest, List dasList, Dictionary dasSampleRateList, double duration, StatusHelpers.SetProgressValueDelegate setProgressFunction, ServiceBase.ServiceCallbackErrorEventHandler onError) ``` **Behavior:** Entry point for the arming workflow. Configures DAS modules with test parameters (post-trigger duration, pre-trigger seconds, number of events, wake-up motion timeout), applies configuration via `Configuration.SetConfig()`, and initiates the flash clear sequence. Returns `true` on success, `false` on failure. --- ### `SoftwareTrigger` **Signature:** ```csharp public void SoftwareTrigger(List dasList) ``` **Behavior:** Sends a software trigger command to all DAS devices in the list. Executes within the `DASHardware.GetArmStatusLock`. Logs failures via `APILogger.Log()`. --- ### `DisarmAsync` **Signature:** ```csharp public void DisarmAsync(List dasList) ``` **Behavior:** Public entry point for disarming DAS devices. Delegates to `DisarmSync()` internally (despite the async naming). --- ## 3. Invariants - **Thread Safety:** All hardware operations (`FlashErase`, `PrepareArmFunc`, `ArmNowFunc`, `SoftwareTrigger`, `DisarmSync`) execute within a lock on `DASHardware.GetArmStatusLock`. - **Pre-trigger Calculation:** Pre-trigger seconds is always calculated as `TSRAIR.TSRAIR_MAX_PRE_TRIGGER_SAMPLES / sampleRate` for each DAS. - **Flash Clear Prerequisite:** Flash memory must be successfully erased before proceeding to `PrepareArmFunc`. - **Level Trigger Validation:** If `currentTest.LevelTriggerChannels.Count > 0`, the system checks for already-level-triggered channels and fails if any are detected. - **Failure Propagation:** Any failure during the arming sequence results in `false` return and invocation of the `onError` callback. - **Disarm on Partial Failure:** If some devices arm successfully while others fail, all devices are disarmed for safety (per FogBugz 4527). --- ## 4. Dependencies ### This Module Depends On: | Dependency | Usage | |------------|-------| | `DTS.Common.Interface.DASFactory.IDASCommunication` | DAS device abstraction | | `DTS.Common.Utilities.Logging.APILogger` | Logging | | `DTS.DASLib.Service.ArmingService` | Service layer for arming operations | | `DTS.DASLib.Service.ServiceBase` | Callback infrastructure | | `DTS.Common.SharedResource.Strings.StringResources` | Localized error messages | | `DTS.Common.DataModel.Common.StatusHelpers` | Progress reporting helpers | | `DTS.Common.DataModel.Common.DASHardware` | Hardware lock singleton | | `DTS.Common.Enums.TSRAIRGo.TSRAIRGoStatus` | Status type enums | | `DTS.Common.Constant.DASSpecific.TSRAIR` | Constants including `TSRAIR_MAX_PRE_TRIGGER_SAMPLES` | | `DTS.Common.DataModel.Classes.TSRAIRGo.Configuration` | Configuration application | ### Data Types Referenced: - `DataModel.TestTemplate` - Test configuration container - `AnalogInputDASChannel` - Channel type with `AlreadyLevelTriggered` property - `ArmStatus` - Arm state tracking object --- ## 5. Gotchas ### Namespace Mismatch The file path indicates `DTS.Common.DataModel` but the namespace is declared as `DataPROWin7.DataModel.Classes`. This may cause confusion or require external aliasing. ### Misleading Async Naming `DisarmAsync()` is **not asynchronous**—it calls `DisarmSync()` which blocks on a `ManualResetEvent`. The naming is misleading. ### Magic Numbers - `ARM_NOW_TIMEOUT = 30000` (30 seconds) - `600000` (10 minutes) passed to `ReadyForArm()` - `50` ms polling interval used throughout - Hardcoded `30000` and `dasList.Count > 1` in `PreparedArmNowFunc` with a TODO comment: `"///////////fix the 30000 and 1 (at least)"` ### Historical Bug Fixes Referenced - **FB 26980:** Override `mod.NumberOfEvents` to ensure correct value - **39345:** Don't hang if Flash Erase fails - **4527:** Disarm all devices if any fail during arm (safety measure) - **15630:** Limit `EnableFaultChecking` to single unit at a time for TDAS with rack - **15267:** Stop on ERR response from TDAS ARM RF ### Unused Code Path In `ArmNowFunc()`, there is an empty conditional block: ```csharp if (Common.SerializedSettings.StoreTestHistoryInDb) { //add code here? } ``` This suggests incomplete implementation. ### Polling Pattern The code uses a busy-wait polling pattern with `ManualResetEvent.WaitOne(50, false)` in multiple places. This is not ideal for performance but appears intentional for the hardware communication layer.