Update cookies preferences
Promotic

Object PmBuffer (Binary data memory)

Description:
The object represents binary values in the data block.
Data block (buffer) is a continuous area in the memory.
For reading/writing of individual value it is necessary to know its position (offset) in the data block and also the data type (size).
General properties and methods:
AutoOffsetInternal automated position in the data block
SetSize()Setting the data block size
GetSize()Detects data block size
Insert()Inserts a new empty space inside an existing data block and enlarges the data block
Remove()Removes existing space from inside an existing data block and shrinks the data block
GetLastError()Returns the flag of the last error
FindBuffer()Returns the position of the first byte of the occurrence of the searched data block in the data block
FindReplaceBuffer()Replaces the occurrences of the searched data block in the data block with another data block
SetBuffer()Writing data block in the form of the PmBuffer object
GetBuffer()Reading the data block in the form of the PmBuffer object
SetPtr()Writing pointer (address) to another data block in the form of the PmBuffer object
GetPtr()Mock reading (skipping) of pointer to another data block
LoadFromFile()Reading values from binary file into the data block
SaveToFile()Writing values from data block into a binary file
CalcCheckSum()Returns the data block checksum (hash)
Methods for writing and reading numeric value:
SetBit()Writing a single bit
GetBit()Reading the value of one bit
SetInt8()Writing 1-byte integer value
GetInt8()Reading the 1-byte integer value
SetInt16()Writing 2-byte integer value
GetInt16()Reading the 2-byte integer value
SetInt32()Writing 4-byte integer value
GetInt32()Reading the 4-byte integer value
SetUint8()Writing 1-byte unsigned integer value
GetUint8()Reading integer 1-byte unsigned value
SetUint16()Writing 2-byte unsigned integer value
GetUint16()Reading 2-byte unsigned integer value
SetUint32()Writing 4-byte unsigned integer value
GetUint32()Reading 4-byte unsigned integer value
SetFloat32()Writing real 4-byte value
GetFloat32()Reading the real 4-byte value
SetFloat64()Writing real 8-byte value
GetFloat64()Reading the real 8-byte value
Methods for writing and reading String type value:
SetStringFix()Writing the text string of fixed length
GetStringFix()Reading the text string of fixed length
SetStringVar()Writing the text string of variable length (terminated by the NULL character)
GetStringVar()Reading the text string of variable length (terminated by the NULL character)
SetHexaString()Writing data block in the form of HexaString
GetHexaString()Reading the data block in the form of HexaString
SetBase64String()Writing the data block in the form of a text string in Base64 encoding
GetBase64String()Reading the data block in the form of a text string in the Base64 encoding
Note:
- The object can be created by the Pm.CreatePmBuffer method.
- This object is functional also in Web panels.

Comparison of objects used for data storage:
The following object types can be used for holding values (of any data type). Each of these objects has certain advantages and disadvantages and the choice depends on the desired usage.
PmArray: This object contains values that are accessible by index into the array - it is possible to read any value at any time in this object. Reading and writing values is very fast, but adding is slow.
This object is functional only for JavaScript language. For the VBScript language the array is represented by Array data type.
PmMap: This object contains values that are addressed by name (text identifier). Value names represent object properties. The advanatege is the "clarity" of usage in the script code. The disadvantage is the inability to access the values in cycle by index.
PmBuffer: This object contains binary values in the data block. For reading/writing of individual value it is necessary to know its position (offset) in the data block and also the data type (size).
See also:
- An example that uses the PmBuffer object to create, edit and save into a file a table in the dbf format.
Example1:
JavaScriptSelect and copy to clipboard

var oBuf = Pm.CreatePmBuffer();
// Setting the whole content of the data block as HexaString and partial reading of its content into 3 variables of different types
var s1 = "40302010605070";   // HexaString contains 7 bytes with values 0x40,0x30,0x20,0x10,0x60,0x50,0x70
oBuf.SetHexaString(-2, s1);   // Filling the data block with data from HexaString
oBuf.AutoOffset = 0;   // Setting the automatic position back to the beginning
var i32 = oBuf.GetInt32(-4);   // Reading the value into the variable: 0x10203040
var i16 = oBuf.GetInt16(-4);   // Reading the value into the variable: 0x5060
var ui8 = oBuf.GetUint8(-4);   // Reading the value into the variable: 0x70
// Continuous creation of the data block by writing 3 variables and then obtaining the whole content as HexaString
oBuf.SetSize(0);   // Setting the new size to 0 and deleting (resetting) of existing content of the data block
oBuf.SetInt32(-2, i32);   // Adds the value from the variable to the end: 0x10203040
oBuf.SetInt16(-2, i16);   // Adds the value from the variable to the end: 0x5060
oBuf.SetUint8(-2, ui8);   // Adds the value from the variable to the end: 0x70
var s2 = oBuf.GetHexaString(0);   // Reading the data block as HexaString. The read value s2 is the same as the original input value s1
Example2:
Reading 4 bytes of the data block by bytes as HexaString or in decimal
JavaScriptSelect and copy to clipboard

var oBuf = Pm.CreatePmBuffer();
oBuf.SetSize(4);
oBuf.SetInt32(0, 1020304050, 0);

Pm.Debug("HexaString = " + oBuf.GetHexaString());

oBuf.AutoOffset = 0;
var h0 = oBuf.GetHexaString(-4, 1);
var h1 = oBuf.GetHexaString(-4, 1);
var h2 = oBuf.GetHexaString(-4, 1);
var h3 = oBuf.GetHexaString(-4, 1);
Pm.Debug("HexaString = " + h0 + ", " + h1 + ", " + h2 + ", " + h3);

oBuf.AutoOffset = 0;
var v0 = oBuf.GetUint8(-4);
var v1 = oBuf.GetUint8(-4);
var v2 = oBuf.GetUint8(-4);
var v3 = oBuf.GetUint8(-4);
Pm.Debug("GetUint8=" + v0 + ", " + v1 + ", " + v2 + ", " + v3);

History:
Pm9.00.05:
- LoadFromFile and SaveToFile new methods: These methods allow to read/write from/into a binary file. These methods replace methods Pm.FileBinaryRead and Pm.FileBinaryWrite that are not functional in the JavaScript language and therefore considered obsolete.
- GetBit and SetBit new methods: Methods allow bit access into a data block.
Pm9.00.04: Created
PROMOTIC 9.0.31 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.