Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
Macros: LogTxt, LogName
The LogTxt macro is used to append text to the end of the current log file, which by default is DqaLog.TXT.
The text to be written can be a simple string, as in LogTxt="Test PASSED", or it can be a multiple-item string expression that includes variables and formatting.
The first LogTxt command of a Daqarta session always starts a new line in the log file. After that, each command starts from the current position. You can thus build up a line from multiple commands, if desired. You can use the p (position) or P (padding) multi-item string options to start at specified columns, to control formatting. Normally, however, you will probably want to start or end each command with an 'n' to advance to a new line, as in:
LogTxt=n + "Test PASSED"
A typical use of the log file is to maintain an ongoing record of what tests were run from day to day, possibly including details of test parameters, device or subject name or number, and date and time of test.
The default DqaLog.TXT file is a good choice to keep everything in one place. But if you want to use different files for different purposes, you can set the current file name using the LogName command.
The LogName= macro has no effect if any File Open or Save As dialog is already active.
LogName= without a name will open the Save As dialog showing all .TXT files in the Daqarta - User_Data folder, with the default set to DqaLog.
LogName="MyFile" will open the Save As dialog with the default name set to MyFile. (Note that quotes are needed around all filenames in macros.) If you accept this by hitting Enter or the Save button in that dialog, Daqarta will assume you want to use a file named MyFile.TXT. If that file already exists, you will be prompted to replace it. But since LogTxt always appends to the specified log file, there is no actual replacement... to do that, see Creating Arbitrary Text Files, below.
After either of the above commands, you may use IF.Posn?f=0 to see if the user has hit Cancel in the Save As dialog instead of choosing a file name. This allows your macro to exit gracefully or take other action. (See the EQ_Curve macro listing for an example.)
A.LogName="MyFile" will directly set MyFile.TXT as the log file, without any Save As dialog.
Like all macros that set file names, LogName accepts string expressions with multiple items and variables. So, for example, if you want a log dedicated to each test, and the test number is in (say) VarA, you could use LogName="Test"+VarA to set the name to "Test000.TXT", then increment VarA before the next test. (Note that these VarX macro variables are retained across Daqarta sessions until specifically set or cleared.)
Integer macro variables also allow simple text strings of up to 4 characters. You can use these to hold test type, or pass/fail results. For example, a prior IF statement can set Var0 to "PASS" or "FAIL", perhaps based upon the results of a Spectrum Limits test. Then you can use LogName=Var0(A)+"_Log" to direct the subsequent LogTxt to either PASS_Log.TXT or FAIL_Log.TXT. The Var0(A) tells the string handler to use the ASCII (or alpha-numeric) interpretation for Var0 instead of treating it as an integer.
You can change log files as often as desired in a single session. The specified file will be created, if it doesn't already exist, and subsequent LogTxt entries will be appended (but see below) to that file. That name will be used until the end of the Daqarta session unless a new LogName is given. When the next Daqarta session begins, it again starts with the DqaLog.TXT default.
You can read the current LogName as a string by using it on the right side of a string command, such as Msg=LogName. This will display "DqaLog.TXT" if the default name is in use, otherwise the full path and file name if any other has been set. This command allows a macro to save the current name and path to a Macro String Array as in Str0=LogName or to Buf0-7 String Storage as in Buf0#aC=LogName, for restore after the macro has temporarily switched to some other name. (The #aC form used here holds up to 512 characters, since path strings may be up to 260 characters long.)
You can read just the name and extension, without the rest of the path, by appending ?N as in Str0=LogName?N. You can read the name only, without path or extension, by appending ?n instead.
You can use LogName and LogTxt to create arbitrary text files, as in the EQ_Curve macro that creates spectrum Weighting Curve text files. You can use LogName="MyFile" to change to the new file, write it, and then use A.LogName="DqaLog" to restore the default log file.
However, note that LogTxt commands always append to a file, they never replace existing data. In the case of the EQ_Curve macro, that would work fine as long as you didn't specify a file name that is already in use. Otherwise, the Windows Save As dialog would ask you to confirm that you want to replace it, but even if you agreed the LogTxt commands would still default to appending. If that happened, the combined file that resulted would surely not describe the intended curve.
To get around this, EQ_Curve uses LogName#0 instead of the ordinary LogName. The #0 tells it to erase a non-empty file (fill it with nulls) before proceeding to write new data. (Note that EQ_Curve does not use the #0 form when restoring the default DqaLog file afterward, so subsequent LogTxt commands will append there as usual.)
By default, LogName appends a .TXT extension to whatever name you use in the command, or enter from the Save As dialog. For example, if you want to create a Spectrum Curve file and you enter "MyFile.CRV", you'll actually get "MyFile.CRV.TXT".
In addition, LogName defaults to files in the Daqarta - User_Data folder, while Spectrum Curve files are expected to be found in the Daqarta - App_Data folder. (Note: In a standard Daqarta installation, the Daqarta folder will be under Documents. In a custom installation, it would typically be under Programs.)
You can resolve both of these issues by telling LogName what file extension you want, and what folder it should go into. You do that with a variant of the LogName#0 form:
LogName#B = .TBL file in App_Data LogName#C = .CAL file in App_Data LogName#F = .FRD file in App_Data LogName#L = .LIM file in App_Data LogName#T = .TXT file in App_Data LogName#V = .CRV file in App_Data
You can alternatively specify User_Data by using a lowercase letter to designate the extension.
If you want to also erase a same-named existing file, put 0 after the extension letter: LogName#V0="MyCurve" will (if accepted in the Save As dialog) create or replace MyCurve.CRV in App_Data.
As noted above under Changing the Log File Name, you can force the above without any Save As dialog by using an A. prefix: A.LogName#V0="MyCurve". There will be no overwrite warning, so use caution with any of these file extensions to prevent accidentally overwriting one of Daqarta's standard weighting curves or thermocouple tables, or some other important file you may have created or installed.
The above list includes all the text file types that you might normally use with Daqarta. If you need a different file extension for some other purpose, it's probably simplest to just create it with the default .TXT format and rename it manually later.
Each LogTxt command opens the log file, appends the given text, and closes the file again. This allows a custom remote control program to read the contents of the file immediately after it receives notification that the command was successful. (Since Windows file sharing is enabled for reading, in principle the remote program can read at any time. But waiting for the notification assures that the data reflects the command just given.)
Please see Remote Control Tips under Data Logging for other notification ideas.
Special log commands may also be used in MIDI Changes scripts to write performance data (or many other things) to the log file. These special commands are part of the Changes Script Output Display set. See the Log File Output subtopic under that section for full details.
Because the MIDI command is actually a variant of LogTxt, it can handle any string expression that can be used there. That includes display of macro and internal Daqarta variables, including read-only variables like Volts, SPL, Freq, date, time, and many more.
Note, however, that while a MIDI script can send these variables to the log file, it doesn't have a way to use most of them in computations.
To control the logging rate, you use the Tempo control. Create a MIDI script with a Wait command set to some sub-multiple of the BPM. For example, if the Tempo is 200 BPM and you want to write to the log file every 15 seconds, that's 50 beats, so you set the Wait to 50. Alternatively, you can use the Tempo msec value, which in this case is 300 msec per beat, and divide it into the desired interval: 15 / 0.300 = 50.
Although this approach is not as versatile as a "real" Daqarta macro, it has the advantage that unlike normal macro commands, you don't need a Professional license (or indeed any license) to save Changes scripts as MIDI setup (.DQM) files for later load and use.
See also Macro Overview
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2020 by Interstellar Research
All rights reserved