16 KiB
16 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:31:14.887778+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 927e0a96c4cf2bf8 |
Sensor Database Module Documentation
1. Purpose
This module provides data structures and services for importing, managing, and accessing sensor configuration and calibration data from a database into the DataPRO system. It defines concrete types for various sensor categories (analog, digital input, digital output, squib), their associated calibration records, and supporting classes for ISO code parsing, filter classification, and range definitions. The module acts as the data layer abstraction for sensor metadata, enabling consistent representation of sensor properties, calibration parameters, and configuration settings across the application.
2. Public Interface
Classes
SensorRange
SensorRange(string value)
Parses a comma-separated string of three doubles intoLow,Medium, andHighproperties. ThrowsInvalidDataExceptionif the input does not contain exactly three values.SensorRange(double low, double medium, double high)
Constructor that directly initializesLow,Medium, andHighproperties.
LowHigh
LowHigh(double low, double high)
Constructor initializingLowandHighproperties.LowHigh(string value)
Parses a comma-separated string of two doubles intoLowandHigh. ThrowsInvalidDataExceptionif fewer than two values are present. UsesInvariantCulturefor parsing.
FilterClass
FilterClass(FilterClassType fc)
Constructor initializingFClassandFrequencybased on predefined CFC filter types. ThrowsExceptionfor unknown types.FilterClass(string fclass)
Constructor parsing a string representation (e.g.,"17","CFC60","1000","AdHoc") intoFClassandFrequency. Supports numeric codes, CFC names, and arbitrary numeric values forAdHoc.ToString()
Returns a human-readable string representation (e.g.,"17 (CFC10)","None","100"forAdHoc).FilterClassTypeenum:
None = 0,AdHoc = -1,CFC10 = 17,CFC60 = 100,CFC180 = 300,CFC600 = 1000,CFC1000 = 1650.
IsoCode
IsoCode(string isoCode)
Constructor initializing the 16-character ISO code. Truncates or pads with'?'as needed.StringRepresentationproperty (string)
Gets/sets the full 16-character ISO code string.- Component properties (all
stringtype, each representing a fixed-width segment):TestObject(1 char, index 0)Position(1 char, index 1)MainLocation(4 chars, indices 2–5)FineLocation1(2 chars, indices 6–7)FineLocation2(2 chars, indices 8–9)FineLocation3(2 chars, indices 10–11)PhysicalDimension(2 chars, indices 12–13)Direction(1 char, index 14)FilterClass(1 char, index 15)
Each property setter pads with'?'or truncates as needed; empty or null inputs default to'?'.
SensorCalibration
SensorCalibration()
Default constructor.SensorCalibration(string s)
Deserializes from aListSeparator-delimited string (seeSEPARATOR_REPLACEMENT).SensorCalibration(DataRow dr)
Populates from a database row usingDbOperations.SensorDB.SensorCalibrationFieldsenum.SensorCalibration(SensorCalibration sc)
Copy constructor.FromSerializedString(string s)
Deserializes from a string usingSEPARATOR_REPLACEMENT("__SC__") to escape list separators.NewDigitalSC()
Static factory returning a default calibration for digital sensors (Sensitivity=1,EngineeringUnits="V",Excitation=Volt5,IsProportional=false,RemoveOffset=false).GetLatestCalibrationBySerialNumberAndExcitation(SensorData sd, ExcitationVoltageOption exc)
Static method delegating toSensorCalibrationList.GetLatestCalibrationBySerialNumberAndExcitation.CompareTo(SensorCalibration other)
ImplementsIComparable<SensorCalibration>: sorts descending byCalibrationDate, thenModifyDate, thenCalVersion.- Properties:
CalVersion(long)CalibrationDate(DateTime)ModifyDate(DateTime)SerialNumber(string)Username(string)Records(CalibrationRecords)IsProportional(bool, read-only logic:!NonLinear && _isProportional)RemoveOffset(bool, read-only logic:!NonLinear && _bRemoveOffset)NonLinear(bool)LocalOnly(bool)ZeroMethod(ZeroMethod)InitialOffset(InitialOffset)CertificationDocuments(string[])
SensorCalibrationList
Reload()
Static method that clears and rebuilds the internal_calibrationListsingleton instance (thread-safe viaLOCK).GetLatestCalibrationBySerialNumberAndExcitation(SensorData sd, ExcitationVoltageOption exc)
Static method returning the most recent calibration for a given sensor and excitation. ReturnsSensorCalibration.NewDigitalSC()for digital/squib types. Uses_cachedCalibrationsif available; otherwise queries_calibrationList.DeleteAll()
Static method calling stored proceduresp_SensorCalibrationsDelete, clearing_calibrationList._calibrations, and logging errors.
CalibrationRecords
CalibrationRecords()
Default constructor initializingRecordsto a single defaultCalibrationRecord.CalibrationRecords(string records)
Parses a serialized string using"__x__"as primary separator and"___xx___"as backup escape sequence.CalibrationRecords(CalibrationRecords copy)
Deep copy constructor.FromSerializedString(string s)
Parses serialized string intoRecordsarray.
CalibrationRecord
CalibrationRecord()
Default constructor initializingPolyto a newLinearizationFormula.CalibrationRecord(string s)
Parses from aListSeparator-delimited string (e.g.,";"inInvariantCulture).CalibrationRecord(CalibrationRecord copy)
Copy constructor.FromString(string s)
Deserializes from aListSeparator-delimited string. Uses"x_Separator_x"as escape sequence for list separators.- Properties:
Sensitivity(double)ZeroPoint(double, computed fromPoly.ZeroPositionIntercept / Poly.CalibrationFactorifPoly.CalibrationFactor != 0, else stored_zeroPoint)Poly(LinearizationFormula)AtCapacity(bool)EngineeringUnits(string, default"g")SensitivityUnits(SensUnits, defaultNONE)Excitation(ExcitationVoltageOption, defaultVolt5)CapacityOutputIsBasedOn(double, default1.0)
DigitalInputSetting
DigitalInputSetting(IDataRecord reader)
Constructor populating from database record usingDbOperations.DigitalInputSettings.Fieldsenum. CallsSetDefaults(this)first. Catches and logs exceptions.SetDefaults(SensorData sd)
Static method setting default values for digital input sensors (e.g.,Bridge=DigitalInput,Capacity=1,DisplayUnit="V",Shunt=ShuntMode.None).
DigitalOutputSetting
DigitalOutputSetting()
Default constructor callingSetDefaults(this).DigitalOutputSetting(IDataRecord reader)
Constructor populating from database record usingDbOperations.DigitalOutputSettings.Fieldsenum. SetsBridgetoTOMDigitalbefore callingSetDefaults(this).ChannelDescriptionproperty
Getter returnsSerialNumber; setter assigns toSerialNumberand raisesPropertyChanged("ChannelDescription").SetDefaults(SensorData sd)
Static method setting defaults for digital output sensors (e.g.,Bridge=TOMDigital,SupportedExcitation=[Volt5],DisplayUnit="V").
SquibSetting
SquibSetting(IDataRecord reader)
Constructor populating from database record usingDbOperations.Squib.Fieldsenum. CallsSetDefaults(this)first, then overrides with DB values. EnsuresCommentis non-null (defaults toSerialNumberif empty).SquibDescriptionproperty
Getter returnsSerialNumber; setter assigns toSerialNumberand raisesPropertyChanged("SquibDescription").ArticleIdproperty
Getter returnsId; setter assigns toIdand raisesPropertyChanged("ArticleId").BypassCurrentFilter/BypassVoltageFilterproperties
Boolean properties withSetPropertypattern forINotifyPropertyChanged.SetDefaults(SensorData sd)
Static method setting defaults for squib sensors (e.g.,Bridge=SQUIB,Capacity=5,SupportedExcitation=[Volt5],DisplayUnit="V").
SensorsCollection
SensorsListproperty
Static singleton property (thread-safe viaLock).GetSensorBySerialNumber(string serialNumber, bool excludeBroken = true, bool bUseCache = true)
Returns aSensorData(or derived type) by serial number. Checks cache first ifbUseCache. Queries database via stored procedures in order:sp_SensorsAnalogGet,sp_SensorsDigitalInGet,sp_SensorsSquibGet,sp_SensorsDigitalOutGet. Returnsnullif not found. Handles test-specific digital output serial numbers.DeleteAll()
Static method callingsp_SensorDeleteAllstored procedure, then callingSensorCalibrationList.DeleteAll(), and raisingOnPropertyChanged("AllSensors").HookedUpproperty
Controls whetherOnPropertyChangedevents are raised (iffalse, events suppressed).
Enums
ShuntMode (SensorDB.cs)
None, Emulation, Internal, External
BridgeLeg (SensorDB.cs)
First, Second, Third, Fourth
CouplingModes (SensorDB.cs)
AC = 0, DC
3. Invariants
SensorRange: Must contain exactly three comma-separated numeric values; otherwise,InvalidDataExceptionis thrown.LowHigh: Must contain at least two comma-separated numeric values; otherwise,InvalidDataExceptionis thrown.FilterClass:Frequencyis always set to the numeric value corresponding toFClass(e.g.,CFC10→17.0).AdHoctype stores arbitrary numeric frequency.IsoCode: The internal_isoCodeFullarray is always exactly 16 characters. Any component property setter ensures its segment is exactly the correct width (1, 2, or 4 chars) by padding with'?'or truncating. Invalid/empty inputs default to'?'.SensorCalibration:IsProportionalandRemoveOffsetare forced tofalsewhenNonLinearistrue.ZeroPointinCalibrationRecordis computed fromPolyif possible; otherwise, it uses the stored_zeroPoint.- Serialization uses
SEPARATOR_REPLACEMENT = "__SC__"to escape list separators.
CalibrationRecords: Uses"__x__"as primary separator and"___xx___"as escape sequence during serialization/deserialization.CalibrationRecord: UsesInvariantCulturefor numeric parsing and"x_Separator_x"as escape sequence for list separators.DigitalInputSetting,DigitalOutputSetting,SquibSetting: All inherit fromSensorDataand callSetDefaults()during construction to ensure consistent baseline properties.
4. Dependencies
Internal Dependencies (from source)
DbOperations: Used for database field names (DbOperations.*.Fields.*), SQL command creation (GetSQLCommand), and stored procedure names (DbOperationsEnum.StoredProcedure.*).Test.Module.Channel.Sensor: Referenced forBridgeType,SensUnits, andExcitationVoltageOptions.ZeroMethod,InitialOffset,LinearizationFormula,SensorData: Referenced but not included in the provided source files. Their definitions are assumed to exist elsewhere in the codebase.ICalibrationRecords,ISensorCalibration: Interfaces implemented byCalibrationRecordsandSensorCalibrationrespectively.
External Dependencies
- System:
System,System.ComponentModel,System.Data,System.Data.SqlClient,System.Globalization,System.Linq,System.Text,System.Xml. - Database: SQL Server stored procedures:
sp_SensorDeleteAllsp_SensorCalibrationsDeletesp_SensorsAnalogGetsp_SensorsDigitalInGetsp_SensorsSquibGetsp_SensorsDigitalOutGet
Dependencies on this Module
SensorsCollection.SensorsListis used to retrieve sensor configurations by serial number.SensorCalibrationList.GetLatestCalibrationBySerialNumberAndExcitationis used to retrieve calibration data.SensorRange,LowHigh,FilterClass,IsoCodeare likely used for parsing configuration strings and ISO codes elsewhere in the system.
5. Gotchas
SensorRangeconstructor: ThrowsInvalidDataExceptionfor malformed input, but no validation is performed on the numeric values (e.g.,Low > Mediumis allowed).LowHighconstructor: UsesInvariantCulturefor parsing, butSensorRangedoes not specify culture—assumes current culture or default parsing behavior.FilterClassconstructor: Ambiguity in parsing"1000": matches bothCFC600(1000 Hz) andCFC1000(1650 Hz)? The code prioritizes exact numeric match (case 1000→CFC600), but"CFC1000"string match would take precedence if present.IsoCode: Setter forStringRepresentationpads with'0'if input is shorter than 16 chars, but constructor pads with'?'. Inconsistent behavior.CalibrationRecord.ZeroPoint: The computed value depends onPoly.CalibrationFactor; ifPolyis uninitialized orCalibrationFactor == 0, the stored_zeroPointis returned. This could lead to stale or incorrect values ifPolyis modified afterZeroPointis set.SensorCalibrationList.GetLatestCalibrationBySerialNumberAndExcitation: Uses_cachedCalibrationsif available, but this field is never populated in the provided source—likely populated elsewhere (e.g., duringReload()or initial load). If_cachedCalibrationsis null, it falls back to_calibrationList, which may be uninitialized ifReload()hasn’t been called.SensorCalibrationList.DeleteAll(): Clears_calibrationList._calibrationsbut does not clear_cachedCalibrations, potentially leaving stale data in memory.DigitalInputSettingconstructor: AssignsComment = UserValue1(line 25), butUserValue1is also assigned fromDbOperations.DigitalInputSettings.Fields.UserValue1.ToString()(line 18). This may be intentional, but could be a source of confusion.SquibSettingconstructor: AssignsComment = UserValue1after reading from DB, but then reassignsComment = SerialNumberifCommentis null/whitespace. This double-assignment is redundant and could be simplified.DigitalOutputSetting.ChannelDescription: Setter modifiesSerialNumberand raisesPropertyChanged("ChannelDescription"). This is unusual—typically, a property namedChannelDescriptionwould not mutateSerialNumber.SensorCalibrationserialization: UsesSEPARATOR_REPLACEMENT = "__SC__"to escape list separators, butCalibrationRecorduses"x_Separator_x"—different escaping schemes for nested serialization.SensorCalibrationListconstructor: The private constructor contains a comment indicating removed code that “appeared it would never work (wrong parameters to sql sp)”, suggesting potential instability or incomplete implementation.SensorsCollection.GetSensorBySerialNumber: Does not use theexcludeBrokenparameter in the provided code—broken sensors are not filtered out despite the parameter name.SensorCalibrationList.GetLatestCalibrationBySerialNumberAndExcitation: ReturnsSensorCalibration.NewDigitalSC()for digital/squib sensors, but this default calibration may not reflect actual sensor behavior (e.g.,Sensitivity=1is arbitrary).