How to append data to an TXT file during acquisition?
I have a question: how can I simply append data to a TXT file, similar to how the "Latch Value Math" function works, during data acquisition? The reason is that I need to log values from different measurements into a single file.
The Problem:
Here is my current workflow: I am performing data acquisition on a vehicle using only generic analog sensors (the specific type doesn't matter much). The client does not want us to acquire CAN or GPS data (due to internal policies). Instead, they want us to log specific details — such as: the acquisition file name, start time, initial tachograph distance, end time, and final tachograph distance (using PC time) — as a simple note. Currently, I do this manually in Notepad.
So, I set up the following in parallel:
1. Added the TimeDecode plugin to obtain PC time channels.
2. Created a global variable called "tacho distance" (see image below).
3. Created an "append" channel under "User inputs" to act as a trigger (see image below).
4. Created a "Latch Value Math" channel to log the data to a table (see image below).
Result (partial solution): example_video_latch_value.mp4
Thus, the problem was 50% solved. Missing:
- Record this table in a single file. Where, in next acquisitions, it will be appended to the end of the file, without replacing the previous content (- I tried using the ExcelWriter plugin, but it replaces the previous content of the file.)
- Record in the text file: the acquisition file name and table latch values.
Can you help me do this?
++ edit
Is there any recommended way to access Latch Value Math table values from a C++ Math script, or should I instead pass the same source channels directly to the C++ Math and implement my own rising-edge trigger + file append logic?
Thank you for reaching out and providing such a detailed description of your issue.
To achieve what you're looking for, I highly recommend using our Sequencer tool. We have a helpful guide on our support page that explains exactly how to write to a .txt file: How to write to .txt - Dewesoft Support
To help you get started, I've attached a couple of files to this post:
- Your updated setup file: I needed to modify your setup to include some channels.
- A custom Sequencer file: This is built to fit your core request. Note that you will need to adjust it to match your specific format and change where the file will be saved to
Please let me know if you have any questions!
Attached files:
Hi, @Staš Jevševar
I am very grateful for your help. It helped solve my problem, and I was able to further improve the sequencer.
I ran into some issues with your setup file. It couldn't find a "custom math" plugin. But it wasn't a problem for me. When I analyzed the sequencer, it was easy to find a replacement solution. I improved the sequencer to be a bit more flexible and stable. I'll share the modifications. Maybe someone in the future will read this issue and solve their problem.
Files:
How it works:
Why a setup math channel?
because use a sequencer variable and calculate their value with "Storing" function results an error.
Global variables setup:
global_variables-OBS.png - I only use it to save user input.
OBS: I set the variable ID to be the same as the variable name ("tacho_distance"). because IDs like "VARIABLE0", "VARIABLE1", and "VARIABLE[.. N]" can cause conflicts with the sequencer if you use them in an existing project that already contains other variables.
Sequencer variables setup:
filename - used by sequencer to record data file name on the output TXT file.
header - It is the first thing the sequencer will record if it detects that the file is empty. (i use is as a "table header", but you can add dynamic content on the sequencer)
OutputTablePath - defines the path for the output TXT file (but is not accepted by the TXT Device as a parameter 😢). It is used for some sequencer processing tasks.
eval_output - It is the output result of the script that detects whether or not the output TXT file has a header.
0 = no header
1 = has a header
Sequencer starter blocks:
- 1: Load Setup
- 2: Maximize window (personal config)
- 3: Waits for the measurement storing to start
TXT file header initialization:
- 4: It is a PowerShell script that checks if the TXT file has a header. The output is stored in the variable eval_output: 0=no header; 1= has a header
- 5: Evaluates the variable eval_output. If a header already exists, it skips the block 6 below; otherwise, it executes block 6 to insert a header.
- 6: Insert a header.