Description: This function returns a buffer of formatted numeric parameter values.
Returns: Buffer
Usage: Script
Format: ParmToBuff(Object, Index, N, Option, Size, Skip [, BadData])
Parameters: Object { object value } { required } { no default }
Any object (the object value of any running module instance).
Index { numeric } { required } { no default }
Any numeric expression giving the first parameter to format, starting from 1.
N { numeric } { required } { no default }
Any numeric expression giving the number of parameters to format. If there are fewer actual parameters than N + Index, this statement stops at the last parameter.
Option { numeric } { required } { no default }
Any numeric expression which specifies the format of the buffer read.
|
Option |
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 |
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:
|
Option |
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 |
For Options 7 and 9 the data is written as appropriate binary format.
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 |
Handled |
|
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 parameters containing numeric data. It is useful for encoding serial port data when writing I/O drivers.
Example:
If a module call looks like:
Write(1, 2, 3, x, y, z);
And there is a statement in module Write that looks like:
If ! Valid(writePacket);
[
writePacket = ParmToBuff(Self(){ Current module },
4 { Skip first 3 parameters },
NParm(Self()) - 3
{ Use rest of parameters },
0 { Unsigned binary format },
16 { Bits },
0 { No skip });
]
Since this statement encodes x, y, and z as 16 bit unsigned integers, the returned buffer will be 16 bytes long, byte-ordered as follows:
|
Byte |
Description |
|
0 |
Low byte of x |
|
1 |
High byte of x |
|
2 |
Low byte of y |
|
3 |
High byte of y |
|
4 |
Low byte of z |
|
5 |
High byte of z |
See Also: