10 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T03:37:03.448977+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | d8ac04ef5386bd66 |
TDMS
Documentation: TDMS.File Module
Purpose
This module implements serialization and deserialization logic for the TDMS (Technical Data Management Streaming) file format, a binary format used primarily for storing time-series test data. It defines the DTS.Serialization.TDMS.File class, which represents a TDMS file and encapsulates metadata and configuration (e.g., filtering options, test plan association), and its nested Writer class, responsible for writing Test objects to disk in the NI TDMS v2.0 format (as referenced by the whitepaper URL in comments). The module serves as the core serialization backend for exporting test data in a standardized, interoperable format compatible with National Instruments tools.
Public Interface
Class: DTS.Serialization.TDMS.File
-
Constructor
public File(Common.ISO.TestPlan plan)Initializes a new
Fileinstance, associating it with a givenTestPlan. Callsbase("TDMS"), indicating it inherits fromSerialization.File. -
Properties
public static string Extension => ".tdms"
Returns the file extension for TDMS files.public bool UseZeroForUnfiltered { get; set; } = false
Controls whether unfiltered data should be represented as zero (default:false).public bool FilteredExport { get; set; } = false
Indicates whether filtered data export is enabled (default:false).public IWriter<Test> Exporter { get; }
Lazily initializes and returns aWriterinstance associated with thisFile. SetsWriter.TestPlanandWriter.WriterParentappropriately. Throws a wrapped exception on failure.
-
Methods
public override void SetEUData(string channelId, FilteredData fd)
Stores or updates Eu (engineering units) unfiltered data for a given channel ID in an internal dictionary_EUUnfilteredDataForLinearizedChannels.public override FilteredData GetEUData(string channelId)
Retrieves stored Eu unfiltered data for a given channel ID from_EUUnfilteredDataForLinearizedChannels. Returnsnullif not present.
Note
:
_EUUnfilteredDataForLinearizedChannelsis a privateDictionary<string, FilteredData>, used to associate channel IDs with precomputed Eu data (likely for linearized channels).
Nested Class: DTS.Serialization.TDMS.File.Writer
-
Constructor
internal Writer(File fileType, int encoding)Internal constructor; initializes the base
Writer<File>with the parentFileand encoding. Theencodingparameter is passed to the base class. -
Properties
public File WriterParent { get; set; }
Reference back to the parentFileinstance. Set byFile.Exportergetter.public Common.ISO.TestPlan TestPlan { get; set; } = null
Reference to the test plan associated with the export. Set byFile.Exporter.public string ExtensionPrefix { get; set; } = string.Empty
Optional prefix appended to the base filename (e.g., for multi-file exports).
-
Methods
public void Write(string pathname, string id, Test test, bool bFiltering, bool includeGroupNameInISOExport, double minStartTime, int dataCollectionLength)
Convenience overload ofWrite(...). Delegates to the 18-parameter overload with many arguments set tonullor defaults.public void Write(string pathname, string id, string dataFolder, Test test, bool bFiltering, bool includeGroupNameInISOExport, FilteredData fd, Test.Module.Channel tmChannel, int channelNumber, BeginEventHandler beginEventHandler, CancelEventHandler cancelEventHandler, EndEventHandler endEventHandler, TickEventHandler tickEventHandler, ErrorEventHandler errorEventHandler, CancelRequested cancelRequested, double minStartTime, int dataCollectionLength)
Main export method. Writes aTestto disk as a.tdmsfile.- Creates the target directory if missing.
- Constructs filename as
Path.Combine(pathname, id + ExtensionPrefix + ".tdms"). - Writes a binary stream using
BinaryWriter. - Invokes event handlers (
begin,tick,end,error) for progress/error reporting. - Calls
WriteLeadInAndMetaData(...)andWriteRawData(...)to serialize metadata and raw data. - Logs exceptions via
APILogger.Log(...). - Throws or reports exceptions depending on presence of
errorEventHandler.
public void Initialize(...)
Currently empty stub. No-op implementation.
Note
:
BeginEventHandler,CancelEventHandler,EndEventHandler,TickEventHandler,ErrorEventHandler, andCancelRequestedare delegate/event types used for progress reporting but are not defined in this file.
Invariants
-
File Format Compliance:
- The written file adheres to the NI TDMS v2.0 format (per NI whitepaper 3727).
- The lead-in signature is always
"TDSm"(4 bytes). - The
ToCMaskis fixed to14(TocMetaData | TocNewObjList | TocRawData). - The file version is fixed to
4713. - All numeric fields use little-endian encoding (no big-endian support;
TocBigEndianbit is unset).
-
Data Layout:
- Raw data is stored as 16-bit signed integers (
DataTypes.I16), regardless of source data type. - Each channel’s raw data is written sequentially, with no interleaving.
- The raw data offset and next segment offset are computed and written as 8-byte unsigned integers.
- Raw data is stored as 16-bit signed integers (
-
Metadata Structure:
- Exactly four objects are written:
- File object (
"/"), - Group object (
"/'TestId'"), - One channel object per
test.Channels.
- File object (
- Group properties are always written in the order defined by
GroupPropertiesenum (TestId, Description, TestDate, TestTime). - Channel properties are written in the order defined by
ChannelPropertiesenum.
- Exactly four objects are written:
-
String Encoding:
- Strings are written as UTF-16 (via
char[]→BinaryWriter.Write(char[])), with length prefix (4 bytes). - SuperScript characters (e.g., in
LinearizationFormula) increase the string’s byte length beyond the character count (handled byGetSuperScriptBytes).
- Strings are written as UTF-16 (via
Dependencies
-
Internal Dependencies
DTS.Serialization.Test(typeTest,Test.Module.Channel,Test.Module.AnalogInputChannel,Test.Module)DTS.Serialization.TDMS.FilteredData(used inSetEUData/GetEUData)DTS.Common.ISO.TestPlan(passed to constructor)DTS.Common.Utilities.Logging.APILogger(used for logging exceptions)
-
External Dependencies
System.IO(FileStream,BinaryWriter,Directory,Path)System.Linq(used for LINQ queries inGetChannelPropertyLengths)System.Collections.Generic(Dictionary,HashSet,List,Enum.GetValues)
-
Inheritance & Interfaces
Fileinherits fromSerialization.File(base class).FileimplementsIWritable<Test>.Writerinherits fromWriter<File>(generic base class) and implementsIWriter<Test>.
Gotchas
-
Hardcoded Data Type:
Raw data is always written asI16(DataTypes.I16), even if the underlyingPersistentChannelInfo[i]values are larger or different types. This may cause data truncation if values exceedInt16range. -
SuperScript Byte Counting Quirk:
TheGetSuperScriptBytesmethod computes extra bytes for certain Unicode super/subscript characters (e.g.,⁰,²,ⁿ) inLinearizationFormula. This logic assumes UTF-16 encoding and checks specific byte patterns (byteArray[0],byteArray[1]). This is non-standard and may break if the source strings contain unexpected Unicode. -
Unused Parameters in
Write(...)Overloads:
Several parameters in the 18-argumentWrite(...)overload (dataFolder,fd,tmChannel,channelNumber,minStartTime,dataCollectionLength) are not used in the implementation. Their presence suggests partial refactoring or future extensibility. -
Empty
Initialize(...)Method:
TheInitialize(...)method is a no-op stub. Its signature implies it may have been intended for streaming or multi-pass writes but is currently unused. -
No Support for Event Cancellation:
AlthoughCancelRequestedandCancelEventHandlerare passed toWrite(...), the method does not check for cancellation during iteration over samples. Progress reporting (tickEventHandler) occurs only once (at 100%) after full write. -
String Concatenation in Paths:
Channel object paths are built via string concatenation (e.g.,groupObjectPath + "/" + "'" + channelName + "':" + description + "'"). This assumes no special characters (e.g., quotes, slashes) inchannel.ChannelName2orchannel.ChannelDescriptionString, which could break path parsing. -
No Validation of Input Data:
TheWriteRawDatamethod writes raw samples directly without validation. IfPersistentChannelInfo.NumberOfSamplesis inconsistent with actual data length, it may causeIndexOutOfRangeExceptionor silent truncation. -
Hardcoded Property Lists:
Property lists (GroupProperties,ChannelProperties) are fixed viaEnum.GetValues. Adding new properties requires updating the enum and all switch statements inWriteGroupPropertiesandWriteChannelSection. -
No Support for Multiple Segments or Append Mode:
The implementation writes a single segment with fixednextSegmentOffset = RawDataOffset + totalNumberRawDataBytes. It does not support appending to existing TDMS files or multi-segment files. -
Encoding Assumption:
Theencodingparameter passed toWriterconstructor is used only in the base class. No explicit encoding configuration (e.g., UTF-8 vs UTF-16) is exposed or validated in this module.
End of Documentation.