This is a Python based script that extracts data from .dcm files (commonly used in automotive calibration) and outputs the results in JSON format. It supports extracting all data, functions, or variables separately based on user-specified modes.
It follows the standard ASCET DAMOS format and is coded as per ETAS Technical Format. You may find more information by visiting here: DCM File Formats Technical Note
The code only accepts DCM file extension. Any other format will not be parsed by the code.
-
File Selection: Uses a Tkinter file dialog to select
.dcmfiles. One can also pass the file URI directly todcm_file -
Data Extraction: Parses key data: Function, Variable, Description, and associated X/Y/Z values from
.dcmfiles. If values for any axis is not available, it returns"". -
Flexible Output: Returns JSON-formatted data in three modes:
all: Full extracted data including function names, variable names, descriptions, and data values.functions: List of unique function names.variables: List of unique variable names.
The above functionality depends on it is called from the constructor. Example:
- for all - output_all = extract_data(dcm_file, mode='all')
- for functions - output_functions = extract_data(dcm_file, mode='functions')
- for variables - output_variables = extract_data(dcm_file, mode='variables')
- Output: Returns the full extracted data into a JSON formatted human readable data and prints results to the console.
- Python 3.x: Ensure Python is installed on your system.
- Tkinter: Comes bundled with Python (this can be removed if file URI is passed directly).
- Clone or Download:
- Clone this repository or download the script file (
dcm_reader_v2.py) from here.
- Clone this repository or download the script file (
- Verify Python:
- Run
python --versionorpython3 --versionin your terminal to confirm Python is installed.
- Run
- No Dependencies: The script uses only standard Python libraries (
os,tkinter.filedialog,json).
-
Run the Script:
python3 dcm_reader_v2.py
- A file dialog will prompt you to select a
.dcmfile. For testing, you can use the Example.DCM file available in this repository under /DCM/ .
- A file dialog will prompt you to select a
-
Output:
- The script processes the file and outputs JSON-formatted data in three modes:
- All Data: Printed to the console.
- Functions: Printed to the console.
- Variables: Printed to the console.
- The script processes the file and outputs JSON-formatted data in three modes:
-
Modes:
- The
extract_data()function accepts amodeparameter:'all': Returns full extracted data.'functions': Returns unique function names.'variables': Returns unique variable names.
- Example usage within Python:
output = extract_data("path/to/file.dcm", mode="all") print(output) # JSON string
- The
select_dcm_file(): Opens a file dialog to select a.dcmfile.extract_data(dcm_file, mode='all'):- Parses the
.dcmfile line-by-line. - Recognizes keywords (e.g.,
FESTWERT,KENNFELD) and specific tags (FUNKTION,ST_TX/X, etc.). - Returns JSON-formatted strings based on the specified mode.
- Parses the
main(): Orchestrates file selection, data extraction, file writing, and printing.
For a .dcm file with content like:
FUNKTION Func1
FESTWERT Var1
ST_TX/X "1" "2"
WERT "10"
Running the script produces:
- All Data:
{ "DCM Name": "example.dcm", "Extracted Data": [ { "Function": "Func1", "Variable": "Var1", "Description": null, "Data": { "X": ["1", "2"], "Y": null, "Values": ["10"] } } ] } - Functions:
{ "DCM Name": "example.dcm", "DCM Functions": "Func1" } - Variables:
{ "DCM Name": "example.dcm", "DCM Variables": "Var1" }
- Quote Handling: The current version does not strip quotes from values (e.g.,
"\"SomeMode\""remains as-is). If there is a space in the value likeSome Modethen the output will be:
"\"Some",
"Mode\""
- If you need quote stripping, modify the parsing logic in
extract_data(). - Error Handling: Basic mode validation is included; expand as needed for robustness.
Feel free to fork this project, submit pull requests, or report issues if you encounter bugs or have suggestions!
