Description: This function returns a buffer containing the numeric data from an array.
Returns: Numeric Buffer
Usage: Script or Steady State
Format: ArrayToBuff(ArrayElem, N, Option, Size, Skip [,BadData])
Parameters: ArrayElem { numeric } { required } { no default: }
Any array element giving the starting point for the array conversion. The subscript for the array may be any numeric expression. Unless specified, the lowest dimension of a multidimensional array is used. Note: The array must contain numeric data only.
N { numeric } { required } { no default: }
Any numeric expression giving the number of array elements to convert starting at the element given by the first parameter. If N extends past the upper bound of the lowest array dimension, this computation will "wrap-around" and resume at element 0, until N elements have been processed.
Option { numeric } { required } { no default: }
Any numeric expression that specifies the format of the buffer write.
|
Option |
Buffer Format |
|
0 |
Unsigned binary (low byte first) |
|
1 |
Signed binary (low byte first) |
|
2 |
BCD (binary coded decimal - low byte first) |
|
3 |
ASCII octal (high byte first) |
|
4 |
ASCII decimal (high byte first) |
|
5 |
ASCII hex (high byte first) |
|
6 |
ASCII floating point (high byte first) |
|
7 |
IEEE float/double (low byte first) |
|
8 |
<obsolete> |
|
9 |
Allen-Bradley PLC/3 floating point |
|
10 |
VAX single precision floating point |
For Options 7 and 9, the data is written as appropriate binary format.
Size { numeric } { required } { no default: }
Any numeric expression giving the number of digits in each datum; it has a different meaning for each option as indicated below:
|
Size |
Size Meaning |
Size Range |
|
Binary types |
Number of bits |
1 – 32 bits |
|
BCD |
Number of 4-bit digits |
1 – 8 digits |
|
ASCII types |
Number of bytes |
1 – 32 bytes |
|
Float types |
Precision |
1 for single precision, 2 for double precision. |
Skip { numeric } { required } { no default: }
Any numeric expression giving the number of buffer bits/digits/bytes to skip after writing each non-floating point element. For floating point types, this parameter must be set to 0.
BadData { numeric } { optional } { default: 0 }
An optional parameter that designates how invalid data is to be handled, according to the following table:
|
BadData |
Invalid Data Type |
|
0 |
Output to buffer as invalid values |
|
1 |
Causes buffer to be invalid |
|
2 |
Output to buffer as valid 0s |
If this parameter is not present, the default will be the 0 option.
Comments: This function may only be used with arrays containing numeric data. It is useful for writing I/O drivers and saving arrays of data in RAM with a fraction of the memory requirement.
Example:
In the example below, assume that array x is a one-dimensional array containing the values 4.5, invalid, and 200:
If ! Valid(buff);
[
buff = ArrayToBuff(x[0] { Starting element },
3 { Number of elements to process },
7 { Type - IEEE floating point },
1 { Single precision },
0 { Skip is ignored },
2 { Use 0 for each invalid value });
BuffRead(buff { Buffer to read },
0 { Starting offset },
"%3b%3b%3b" { Type IEEE floating point binary },
a1, a2, a3 { Variables to hold the values });
]
This code produces a formatted buffer called buff that holds 3 float values (written in binary format), each corresponding to an element in the array. The second value in the array is invalid - in the buffer, it will be a valid 0. The values of a1, a2 and a3 then will be 4.5, 0 and 200 respectively.
See Also:
ArrayStart | ArraySize | BuffRead | BuffToArray | BuffToParm | BuffToPointer | BuffWrite | GetByte | MakeBuff | ParmToBuff | PointerToBuff | SetByte| Array Functions