AdsSyncRead[Datatype]Req

AdsSyncReadBoolReq

AdsSyncReadIntegerReq

AdsSyncReadLongReq

AdsSyncReadSingleReq

AdsSyncReadDoubleReq

AdsSyncReadStringReq

Reads data synchronously from an ADS device, and writes it into a Visual Basic variable of type boolean, integer, long, single, double or string.

object.AdsSyncRead[Datatype]Req(
  nIndexGroup As Long,
  nIndexOffset As Long,
  cbLength As Long,
  pData As [Datatype]
) As Long

Parameter

nIndexGroup

[in] Index group of the ADS variable

nIndexOffset

[in] Index offset of the ADS variable

cbLength

[in] Length of the data in bytes (see VB variable lengths)

pData

[in] Visual Basic variable into which the data is written from the ADS variable

Return value

See ADS error codes

Attention: In case of an error the VB variable (pData), whose value should be written, is set to "0".

Comments

The execution of the Visual Basic program is stopped until the data from the ADS device is available or until the time in the property AdsAmsCommTimeout is exceeded.
Note on the String data type: When specifying the length of the data, note that it refers to the length of the variable in the Visual Basic program. Since Visual Basic represents a character with 2 bytes, the length of the variable must be determined with LenB(), not with Len().

VB sample

Dim VBVar As Long
'Wert auslesen
Call AdsOcx1.AdsSyncReadLongReq(&H4020&, 0&, 8&, VBVar)
'Variablen anzeigen
Label1.Caption = VBVar
Dim VBVar As String
'Visual Basic Variable initialisieren
VBVar = Space(10)
"Wert aus Variable auslesen
Call AdsOcx1.AdsSyncReadStringReq(&H4020&, 0&, LenB(VBVar), VBVar)
'Variablen in Form anzeigen
Label1.Caption = VBVar

Delphi sample

procedure TForm1.Button2Click(Sender: TObject);
var     res :integer;
    //read buffer
    vWordBool : WordBool;
    vSmallint : Smallint;
    vLongint : Longint;
    vSingle : Single;
    vDouble : Double;
    vString : WideString;
begin
    res :=  AdsOcx1.AdsSyncReadBoolReq( $4020, 0, sizeof(vWordBool), vWordBool );
    Label1.Caption := Format('res: %d,  Value: %s', [res, BoolToStr(vWordBool, TRUE)]);

    res :=  AdsOcx1.AdsSyncReadIntegerReq( $4020, 2, sizeof(vSmallint), vSmallint );
    Label2.Caption := Format('res: %d,  Value: %d', [res, vSmallint]);

    res :=  AdsOcx1.AdsSyncReadLongReq( $4020, 4, sizeof(vLongint), vLongint );
    Label3.Caption := Format('res: %d,  Value: %d', [res, vLongint]);

    res :=  AdsOcx1.AdsSyncReadSingleReq( $4020, 16, sizeof(vSingle), vSingle );
    Label4.Caption := Format('res: %d,  Value: %f', [res, vSingle]);

    res :=  AdsOcx1.AdsSyncReadDoubleReq( $4020, 32, sizeof(vDouble), vDouble );
    Label5.Caption := Format('res: %d,  Value: %f', [res, vDouble]);

    SetLength(vString,80{standard length of the PLC string variable});
    res :=  AdsOcx1.AdsSyncReadStringReq( $4020, 64, Length(vString)*2{byte length!}, vString );
    Label6.Caption := Format('res: %d,  Length: %d, Value: %s', [res, Length(vString), vString]);
end;