Update cookies preferences
Promotic

FindBuffer - method of the PmBuffer object

Description:
Returns the position of the first byte of the occurrence of the searched data block in the data block.
Syntax:
Long FindBuffer(Long nOffset, Object oFind)
Parameters:
nOffset(Long) Specifies the position of read value in the data block.
The read value must be inside the data block. The item is read either whole or not read at all.
>= 0 - Index (in bytes, zero-based index) in the data block.
-4 - The internal automatic position is used (see the AutoOffset property). It points behind the last read or written value.
This operation shifts the internal automatic position behind the read/written value.
If the items are read/written one by one then it is not necessary to define the position manually, but it is better to use this automated positioning.
oFind(Object) The searched data block in the form of the PmBuffer object.
Return value:
Returns the position of the first byte of the occurrence of the searched data block in the data block (zero-based index). If not found, then returns the -1 value.
Note:
This method is not functional yet in Web panels.
This operation shifts the internal automatic position behind the last byte of the found data block.
See also:
Example1:
JavaScriptSelect and copy to clipboard

var oBuf = Pm.CreatePmBuffer();
oBuf.SetUint8(-2, 0x10);   // Offset: 0
oBuf.SetUint8(-2, 0x20);   // Offset: 1
oBuf.SetUint8(-2, 0x30);   // Offset: 2
oBuf.SetUint8(-2, 0x40);   // Offset: 3
oBuf.SetUint8(-2, 0x10);   // Offset: 4
oBuf.SetUint8(-2, 0x20);   // Offset: 5
oBuf.SetUint8(-2, 0x30);   // Offset: 6
oBuf.SetUint8(-2, 0x40);   // Offset: 7
var oFind = Pm.CreatePmBuffer();
oFind.SetUint8(-2, 0x20);
oFind.SetUint8(-2, 0x30);
var s0 = oBuf.GetHexaString(0);   // The result will be "1020304010203040"
oBuf.AutoOffset = 0;
var iFind0 = oBuf.FindBuffer(-4, oFind);   // The result will be 1
var iFind1 = oBuf.FindBuffer(-4, oFind);   // The result will be 5
Example2:
JavaScriptSelect and copy to clipboard

var oBuf = Pm.CreatePmBuffer();
oBuf.SetUint8(-2, 0x10);   // Offset: 0
oBuf.SetUint8(-2, 0x20);   // Offset: 1
oBuf.SetUint8(-2, 0x30);   // Offset: 2
oBuf.SetUint8(-2, 0x40);   // Offset: 3
oBuf.SetUint8(-2, 0x10);   // Offset: 4
oBuf.SetUint8(-2, 0x20);   // Offset: 5
oBuf.SetUint8(-2, 0x30);   // Offset: 6
oBuf.SetUint8(-2, 0x40);   // Offset: 7
var oFind = Pm.CreatePmBuffer();
oFind.SetUint8(-2, 0x20);
oFind.SetUint8(-2, 0x30);
var s0 = oBuf.GetHexaString(0);   // The result will be "1020304010203040"
oBuf.AutoOffset = 0;
while (1)
{
var iFind = oBuf.FindBuffer(-4, oFind);
if (iFind < 0)
{
break;
}
Pm.Debug(iFind);   // The result will be 1 and 5
}

History:
Pm9.00.25: Created
PROMOTIC 9.0.28 SCADA system documentation MICROSYS, spol. s r.o.

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