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.

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
Required. Any numeric expression giving the number of digits in each datum. It has a different meaning for each option as indicated:

Option

Size Meaning

Size Range

Binary types 

Number of bits 

The following values are supported: 1 (in unsigned mode), 4, 8, 16, 32 and 64

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
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.

BadData

Handled

0

Output to buffer as invalid values

1

Causes buffer to be invalid

2

Output to buffer as valid 0s

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