Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
Macros: Var0-VarZ, VarClr, A-Z
Just like main Daqarta control values, macro variables can be set, tested in IF statements or WHILE loops, or used in expressions for various calculations. They can also be used as string variables in messages, Labels, Fields, file names, Notes, Custom Meters Mtr0-Mtr3, or log text.
There are two main types of simple macro variables: Fixed-point (Var0 through Var9 and VarA through VarZ), which are the only variables persistent across Daqarta sessions, and floating-point (A through Z). In addition, macros have access to all MIDI Changes Script User Variables. Each variable type is discussed below.
There are also special Macro Arrays Buf0-Buf7 which can be used as collections of 64-bit fixed-point variables for many purposes. Memory Arbs are arrays of 16-bit signed integers that can be up to 16384 elements long.
All macro and MIDI variables can be directly set using constants, variables, or expressions. In addition, you can scroll by +/-1.00 using the form A=>X, where X is a constant, variable, or expression. If X is positive then A is incremented by 1. If negative it is decremented by 1, and if 0 it is unchanged.
In addition, you can set these same variables using quoted strings, as in VarA="PASSED" or UZ="FAIL". These strings can be displayed or sent to a Log file using the alphanumeric (A) string expression format, as in Msg=UZ(A). Integer (MIDI) variables U0-UZ and Q0-QZ can hold up to 4 characters, while floating-point A-Z and 64-bit fixed-point Var0-VarZ can hold up to 8. (32-bit MIDI fixed-point variables Ua-Uz and Qa-Qz can only hold 2 characters.)
All macro and MIDI variables are global. This allows macros to pass information (such as between a Custom Controls macro and a multitasking macro), but it also requires that you specifically initialize variables... you can't depend upon them being zero by default.
However, Macro Arrays can be used to save and restore all floating-point and MIDI variables to preserve them during MIDI performances and multitasking macros, providing local variables when needed.
Also, Miscellaneous macros Posn#0 to Posn#9 and Posn#i to Posn#o can be dedicated to local variable use in many cases. See the Special Macro-MIDI Variables subtopic.
Macro variables A through Z are 80-bit floating-point real numbers with 64-bit precision (equivalent to about 18 digits) over a range from about 10^4932 down to 10^-4932.
Use these as working variables in math calculations. They are always cleared at the start of each Daqarta session.
To send A to a Remote Control client, use A=>> and A=>* to send the integer and fraction parts, respectively. (The float is automatically converted to fixed-point.) These will be sent as 32-bit lParam values, with 'intA' and 'frcA' as wParam identifiers.
Macro variables Var0-Z are signed real numbers with 32-bit integer and 32-bit fraction parts, for 64-bit overall precision. The integer range is approximately +/-2 billion, while the fraction resolution is about 9 decimal places.
These variables are retained across Daqarta sessions.
Var0=x toggles Var0 between 0 and 1. If the initial value is zero the result is 1.00; otherwise the result is zero.
Note that Var0-Z macro variables are retained across sessions by default, independent of any .MAC file. You can use this property to set persistent macro preferences. But this also means you may need to explicitly clear some variables at the start of a session. For a single variable such as VarA, you can just use VarA=0. The VarClr command allows you to clear a range of variables, or all variables:
VarClr=AD sets VarA through VarD to zero.
VarClr= sets all variables Var0 through VarZ to zero.
There are no analogous clear commands for clearing a range of floating-point variables A-Z. They all default to 0 at the start of each session. Likewise, all elements in macro arrays Buf0-Buf7 default to zero. However, you can set all 1024 elements in any BufN array to zero via BufN="<=(0)". (You can use any value you choose. See Macro Array Copy/Swap Operations.)
To send VarA to a Remote Control client, use VarA=>> and VarA=>* to send the integer and fraction parts, respectively. These will be sent as 32-bit lParam values, with 'VarA' and 'varA' as wParam identifiers.
You can preset Fields to display Var0-Z macro variables (but not A-Z) when they are changed. For example Field1=?VarN will cause the value of VarN to be shown in Field 1 whenever VarN is modified. Use VarN=>0 to force the Field to show the current value without changing it.
Suppose you have a complicated test suite, all run by macros, and want to provide a series of prompt messages to help train new operators. You can use VarA to tell if the prompts will be shown, so that they can be turned off when they are not needed. A macro called PromptTog will simply toggle VarA:
A macro called _Prompt will be called at various points in the test sequence, indicating what to do next. Each stage of the series will be run by its own macro, which will set VarB to a unique value before calling the _Prompt macro via @_Prompt.
The _Prompt macro will test VarA and show no message if VarA is zero. Otherwise, it will test VarB and show the appropriate message.
IF.VarA=0 Msg= ELSE. IF.VarB=0 Msg="Hit Test1 to start 1st test." ENDIF. IF.VarB=1 Msg="Hit Stop1 to halt 1st test." ENDIF. IF.VarB=2 Msg="Hit Save1 to save Test1 results." ENDIF. IF.VarB=3 Msg="Hit Test2 to start 2nd test." ENDIF. ENDIF.
If your test suite saves a lot of different files that are all derived from the same subject or device under test, you will probably want to use the Auto-Increment Filenames option. You need to provide an initial base name for the first file saved, but not for subsequent saves which will append an incrementing value to the base name.
The initial setup macro (typically the '!' automatic startup macro) can prompt the operator to enter a subject ID to a Field before starting the test, by including the following commands:
C=0 Msg="Enter Subject ID" WaitChange=Field5 Msg=
You may want to precede this by a MsgPosFix command set to show the Msg right over Field5.
The contents of Field5 (such as "Rat123") can then be used as the base file name. The following file save macro uses variable C as a flag, so that the base name will only be entered on the first save of the session:
AutoInc=1 IF.C=0 A.SaveDQA=Field5 C=1 ELSE. A.SaveDQA= ENDIF.
The first time this is run in any session, it will save Rat123-000.DQA (or whatever name was entered instead of "Rat123") and set C to 1. The next time, it will save Rat123-001.DQA, incrementing on each subsequent save. (The A. prefix means that SaveDQA won't show a Save As dialog, it will just save the file directly.)
The fact that C starts out at zero insures that the initial save always sets the subject ID as the base name. Simple variables A-Z are automatically set to zero when Daqarta starts, so it isn't strictly necessary to set C to zero when the subject ID is entered, but this allows for cases when multiple subjects are tested in one session.
Suppose you want to set a particular default position for a draggable Msg, but once the user drags it, that new position should be used in future sessions. You can use an IF statement like this:
IF.VarD=12345 ;Do nothing ELSE. MsgPos="100,200" VarD=12345 ENDIF.
The first time the macro runs, VarD will be 0 so the position will be set. Later in this session or future sessions, VarD will be 12345 so the MsgPos will not be run. If you have different .MAC files for different applications, you can use specific values to tell which .MAC set ran last, to have different positions for each.
As noted earlier, macros have access to all MIDI Changes Script User Variables. Besides using these with macros to control MIDI performances, you can use them as extra macro variables if you are not using MIDI. U0 through U9 and UA through UZ, as well as Q0-9 and QA-Z, are signed integers whose values may range from -2147483648 to +2147483647 (+/- 2^31).
Ua through Uz and Qa through Qz are unsigned fixed-point decimals with a range from 0 to 65535.9999.
Note that all MIDI variables are cleared when Pitch-to-MIDI is toggled on, or when any script or control changes are made that require it to be restarted. (But see Special Macro-MIDI Variables, below.)
There will rarely be a need for the Ua-z or Qa-z fixed-point MIDI variables in macros, since they have only 32-bit resolution compared to the 64-bit resolution of A-Z floats or Var0-Z fixed-point macro variables.
But the integer MIDI variables are especially useful in macros as index values and loop counters, and any other place where you specifically want an integer result. They don't require an explicit conversion function like int() or cint(); any assignment to a MIDI integer is automatically converted via rounding.
Integer MIDI variables also stand out in macro listings due the U or Q prefix, and they allow you to have more total variables... handy if you are using the letters as mnemonics.
To send a MIDI integer such as UA to a Remote Control client, use UA=>>. This will be sent as a 32-bit lParam value, with 'MvUA' as the wParam identifier. This does not apply to fixed-point MIDI variables.
There are 10 integer variables that, unlike the above U- and Q-type User Variables, are not cleared at the start of each MIDI performance. These "special" integers can be set by main Daqarta macros before or during a performance, and the MIDI Changes script can read or set them at any time. They are a bit more awkward to use because they have different read and write commands, which are also different between the macro version and the Changes script version.
Miscellaneous macros Posn#0 to Posn#9 write the integers, and Posn?0 to Posn?9 read them.
MIDI Changes script commands ?0 to ?9 write these same variables, and they can be read as Miscellaneous Position read-only values m0 to m9.
Similarly, there are 7 "special" fixed-point variables with 32-bit integer and 32-bit fraction resolution that are written as Posn#i to Posn#o and read as Posn?i to Posn?o in macros.
These same variables are written in MIDI Changes scripts as ?i to ?o and read as mi to mo. (Though note that the MIDI script will limit these to unsigned values with 16-bit integer and 16-bit fraction resolution when used internally.)
Note that since Daqarta variables are global and can be accessed directly by subroutines, these special variables are convenient to use for parameters that are passed to or received from subroutines, or used for their internal calculations. This helps to avoid accidentally re-using U0-Z and Q0-Z integers or A-Z floating-point variables that are being used elsewhere.
The fact that these variables have different forms when read and written requires care in crafting macro statements. In general, the 'write' form using # normally appears on the left side, and the 'read' form using ? normally appears only on the right side. So, for example, to increment Posn#0 you would use Posn#0=Posn?0 + 1. (You can alternatively "scroll" by +/-1 only, using Posn#0=>1 or Posn#0=>-1 without needing to use the read form.)
Memory Arbs MemArb0 to MemArb7 can serve as arrays of integers in the range of +/-32767. These arrays can be in sizes of 1024, 2048, 4096, 8192, or 16384 values each. You refer to individual array elements by index, such as MemArb0[UA]=X to write value X to element UA of MemArb0, or X=MemArb0 * 2 to set X to twice the value of element 123.
See also Macro Overview
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 35 Years of Innovative Instrumentation
© Copyright 2007 - 2021 by Interstellar Research
All rights reserved