ParmToBuff
(Engine-Level Function)
Description: | Returns a buffer of formatted numeric parameter values. |
Returns: | Buffer |
Usage: | Script Only. |
Function Groups: | Advanced Module, String and Buffer |
Related to: | ArrayToBuff | BuffToArray | BuffToParm |
Format: | ParmToBuff(Object, Index, N, Option, Size, Skip [, BadData]) |
Parameters: |
Object | ||||||||||||||||||||||||
Required. Any object (the object value of any running module instance). | ||||||||||||||||||||||||
Index | ||||||||||||||||||||||||
Required. Any numeric expression giving the first parameter to format, starting from 1. | ||||||||||||||||||||||||
N | ||||||||||||||||||||||||
Required. 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 | ||||||||||||||||||||||||
Required. Any numeric expression which specifies the format of the buffer read.
|
Size | |||||||||||||||
Required. Any numeric expression giving the number of digits in each datum. It has a different meaning for each option as indicated:
For Options 7 and 9 the data is written as appropriate binary format. |
Skip | ||||||||
Required. Any numeric expression giving the number of buffer bits/digits/bytes to skip after writing each non-floating point element. In binary modes, the following values are supported: 8, 16, 32, and 64. For floating point types, this parameter must be set to 0. | ||||||||
BadData | ||||||||
An optional parameter that designates how invalid data is to be handled, according to the following table: Defaults to 0 if missing or invalid.
|
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. In binary modes, for the Size parameter, the following values are supported: 1 (in unsigned mode), 4, 8, 16, 32 and 64. For the Skip parameter, the following values are supported: 8, 16, 32, and 64. Size and Skip values not in those ranges will only work if their combined value is a multiple of 8. For instance, a Size of 12 and a Skip of 4 will work. A Size of 48 and a Skip of 0 will work. When Skip + Size is not a multiple of 8, the behavior of this function is undefined. If your values are of Size 1 (i.e. a single bit), use unsigned mode. A Size of 1 is not supported for signed values. |
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 }); ]
Because 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 |