Creating and Running Algorithms 197Chapter 6
NOTE For Block Program Data, the Algorithm Parser requires that the source_code
data end with a null (0) byte. The null byte must be appended to the end of
the block's <data byte(s)>. If the null byte is not included within the block,
the error "Algorithm Block must contain termination '\0'" will be generated.
Indefinite Length Block Data Example
Retrieve algorithm source code from file and send to VT1422A in indefinite
length format using VTL/VISA instrument I/O libraries:
int byte_count, file_handle;
char source_buffer[8096], null = 0;
file_handle = open( "<filename>", O_RDONLY + O_BINARY);
byte_count = read( file_handle, source_buffer, sizeof( source_buffer ) );
close( file_handle );
source_buffer[ byte_count ] = 0; /* null to terminate source buffer string */
viPrintf( VT1422A, "ALG:DEF 'ALG8',#0%s%c\n", source_buffer, null );
See the section "Running the Algorithm" later in this chapter for more
information on loading algorithms from files.
Changing aRunning Algorithm
The VT1422A has a feature that allows for a given algorithm to be swapped
with another even while it is executing. This is useful if, for instance, it is
necessary to alter the function of an algorithm that is currently controlling a
process and it would be undesirable for that process to be uncontrolled. In
this case, when the original algorithm is defined, enable it to be swapped.

Defining an

Algorithm for Swapping

The ALG:DEF command has an optional parameter that is used to enable
algorithm swapping. The command's general form is:
ALG:DEF '<alg_name>'[,<swap_size>],'<source_code>'
Note the parameter <swap_size>. With <swap_size>, the amount of
algorithm memory is specified to allocate for algorithm <alg_name>. Make
sure to allocate enough space for the largest algorithm expected to be
defined for <alg_name>. Here is an example of defining an algorithm for
swapping:
define ALG3 so it can be swapped with an algorithm as large as 1000 words
ALG:DEF 'ALG3',1000,#41698<1698char_alg_source>
NOTE The number of characters (bytes) in an algorithm's <source_code>
parameter is not well related to the amount of memory space the algorithm
requires. Remember this parameter contains the algorithm's source code, not
the executable code it will be translated into by the ALG:DEF command.
The algorithm's source might contain extensive comments, none of which
will be in the executable algorithm code after it is translated.