Files
2026-04-17 14:55:32 -04:00

141 lines
7.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
source_files:
- DataPRO/Modules/Hardware/AddEditHardware/Model/DASModule.cs
generated_at: "2026-04-16T04:37:06.260294+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "05acdd30203849a0"
---
# Model
## Documentation: `DASModule.cs`
---
### 1. **Purpose**
The `DASModule` class models a hardware module in a Data Acquisition System (DAS) for use in a WPF-based UI for adding or editing hardware configurations. It encapsulates module-specific metadata—including type, bridge configuration (for SLICE modules), serial number, and associated visual representation—and exposes this data through a property-changed-aware model suitable for data binding. It serves as a view-model-like abstraction for hardware modules in the `AddEditHardware` workflow, implementing `IAddEditHardwareDASModule` and inheriting from `BasePropertyChanged` to support UI updates via `INotifyPropertyChanged`.
---
### 2. **Public Interface**
#### `public bool Disabled { get; set; } = false;`
- Indicates whether this module instance is disabled (e.g., not in use). Default is `false`.
#### `public SLICEBridgeTypes SLICEBridgeType { get; set; }`
- Gets or sets the bridge type for SLICE modules (e.g., `Bridge`, `IEPE`, `ARS`, `ACC`).
- **Behavior**: On change, triggers `SetProperty`, then calls `SetImage()` to update the image based on the new type.
#### `public HardwareTypes ModuleType { get; set; }`
- Gets or sets the high-level hardware type (e.g., `SLICE_Bridge`, `TOM`, `SIM`, `DIM`, `UNDEFINED`).
- **Behavior**: On change, triggers `SetProperty`, then calls `SetImage()`.
#### `public string SerialNumber { get; set; }`
- Gets or sets the modules serial number (empty string by default). No validation or prefix enforcement is performed in this property.
#### `public ImageSource DASImage { get; set; }`
- Gets or sets the `ImageSource` used to display the modules image in the UI.
- **Behavior**: Set via `SetImage()` based on `ModuleType` and (for `SLICE_Bridge`) `SLICEBridgeType`. May be `null` if image loading fails or no matching asset is found.
#### `public SLICEBridgeTypes[] AvailableNanoBridges { get; }`
- Returns a read-only array of valid `SLICEBridgeTypes` for *nano*-form-factor SLICE modules:
`SLICEBridgeTypes.Bridge`, `SLICEBridgeTypes.IEPE`.
#### `public SLICEBridgeTypes[] AvailableMicroBridges { get; }`
- Returns a read-only array of valid `SLICEBridgeTypes` for *micro*-form-factor SLICE modules:
`SLICEBridgeTypes.Bridge`, `SLICEBridgeTypes.IEPE`, `SLICEBridgeTypes.ARS`, `SLICEBridgeTypes.ACC`.
#### `public HardwareTypes[] AvailableRACKModules { get; }`
- Returns a read-only array of valid hardware types for rack-mounted modules:
`HardwareTypes.UNDEFINED`, `HardwareTypes.SIM`, `HardwareTypes.TOM`, `HardwareTypes.DIM`.
#### `public IAddEditHardwareHardware OwningHardware { get; set; }`
- Reference to the parent hardware object (e.g., chassis or device) that owns this module. Used for contextual navigation or validation.
#### `public string GetSerialNumberPrefix()`
- Returns a short string prefix used for generating or validating serial numbers based on module type:
- `"DIM"` for `HardwareTypes.DIM`
- `"SIM"` for `HardwareTypes.SIM`
- `"TOM"` for `HardwareTypes.TOM`
- For `HardwareTypes.SLICE_Bridge`, returns a 2-letter prefix based on `SLICEBridgeType`:
- `"AC"` for `ACC`
- `"AR"` for `ARS`
- `"BR"` for `Bridge`
- `"IEPE"` for `IEPE`
- Returns `string.Empty` for `UNDEFINED` or unrecognized types.
#### `public DASModule()`
- Default constructor. Initializes `Disabled = false`, `_sliceBridgeType = Bridge`, `_moduleType = UNDEFINED`.
---
### 3. **Invariants**
- **Image Consistency**: `DASImage` is always derived from `ModuleType` and (if applicable) `SLICEBridgeType`. Changing either triggers `SetImage()` and updates `DASImage`.
- **Image Source URI**: All image paths are relative to the pack URI `pack://application:,,,/ResourceFile.xaml`.
- **Image Loading Failure Handling**: If image loading fails (e.g., missing file), `DASImage` is set to `null`, and an error is logged via `APILogger`.
- **Image Freezing**: Loaded `BitmapImage` instances are frozen for thread-safety and performance.
- **Module Type Constraints**:
- `SLICEBridgeType` is only meaningful when `ModuleType == HardwareTypes.SLICE_Bridge`.
- `AvailableNanoBridges` and `AvailableMicroBridges` are static and immutable; they define allowed values but are not enforced by property setters.
- **Serial Number Prefix**:
- `GetSerialNumberPrefix()` returns `string.Empty` for unrecognized or `UNDEFINED` module types.
---
### 4. **Dependencies**
#### **Imports/Usings**
- `System`, `System.Windows`, `System.Windows.Input`, `System.Windows.Media`, `System.Windows.Media.Imaging`
- `DTS.Common.Base``BasePropertyChanged`
- `DTS.Common.Enums.Hardware``SLICEBridgeTypes`, `HardwareTypes`
- `DTS.Common.Interface.Hardware.AddEditHardware``IAddEditHardwareDASModule`, `IAddEditHardwareHardware`
- `DTS.Common.Utilities.Logging``APILogger`
#### **External Dependencies**
- **WPF**: Uses `ImageSource`, `BitmapImage`, `Uri`, `pack://` URIs.
- **Common Libraries**:
- `DTS.Common.Base` for `BasePropertyChanged` (likely implements `INotifyPropertyChanged`).
- `DTS.Common.Enums.Hardware` for type definitions.
- `DTS.Common.Interface.Hardware.AddEditHardware` for interface contracts.
- `DTS.Common.Utilities.Logging` for error logging.
#### **Consumers**
- UI components bound to `DASModule` (e.g., `DataGrid`, `UserControl`) for editing hardware configurations.
- Any class implementing or consuming `IAddEditHardwareDASModule`.
- Likely instantiated and managed by a parent `IAddEditHardwareHardware` (via `OwningHardware`).
---
### 5. **Gotchas**
- **No Validation on `ModuleType`/`SLICEBridgeType` Combinations**:
The class allows setting `ModuleType = SLICE_Bridge` and `SLICEBridgeType = ACC`, but also allows `ModuleType = TOM` with `SLICEBridgeType = IEPE`, which is semantically invalid. Validation (if any) must occur elsewhere (e.g., in UI or service layer).
- **`Disabled` Property Has No Side Effects**:
Setting `Disabled = true` does not affect image loading, serial number generation, or any other logic in this class.
- **Image Paths Are Hardcoded and Fragile**:
`SetImage()` uses hardcoded relative paths (e.g., `@"Assets/Hardware/SLICEIEPE_Side.png"`). If assets are renamed or moved, image loading silently fails (logs error, sets `DASImage = null`).
- **`GetSerialNumberPrefix()` Returns `"IEPE"` (4 chars) While Others Are 23 chars**:
Inconsistent prefix length may cause downstream parsing issues if consumers assume fixed-width prefixes.
- **No Null/Empty Handling for `SerialNumber`**:
The property accepts any string, including `null` or whitespace. No validation or trimming is applied.
- **`OwningHardware` Is Not Initialized**:
The property is nullable and must be set externally; no constructor overloads or defaults are provided.
- **`_baseUri` Is Static and Fixed**:
Assumes all images are in the same resource file (`ResourceFile.xaml`). Not configurable at runtime.
- **Exception Handling in `SetImage()` Is Broad**:
Catches all exceptions during image loading but logs only the message (no stack trace or context), making debugging harder.
- **No Explicit Interface Implementation**:
The class implements `IAddEditHardwareDASModule` implicitly; if the interface defines additional members, they are not visible in this file.
- **None identified from source alone.** *(Note: The above are inferred from observed behavior, not documented quirks.)*