AdsSyncWrite[Datatype]VarReq
AdsSyncWriteBoolVarReq
AdsSyncWriteIntegerVarReq
AdsSyncWriteLongVarReq
AdsSyncWriteSingleVarReq
AdsSyncWriteDoubleVarReq
AdsSyncWriteStringVarReq
Requests data synchronously from an ADS device, and writes it into a Visual Basic variable of type boolean, integer, long, single, double or string.
object.AdsSyncWrite[Datatype]VarReq(
hVar As Long,
length As Long,
pData As [Datatype]
) As Long
Parameter
hVar
[in] Handle of the ADS variable (see the AdsCreateVarHandle() method)
length
[in] Length of the data in bytes (see VB variable lengths)
pData
[in] Visual Basic variable from which the data is written into the ADS variable
Return value
See ADS error codes
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().
Example
Dim hVar As Long
Dim VBVar As Double
Call AdsOcx1.AdsCreateVarHandle("MAIN.PLCVar", hVar)
VBVar = 3,1415
Call AdsOcx1.AdsSyncWriteDoubleVarReq(hVar, 8&, VBVar)
Call AdsOcx1.AdsDeleteVarHandle(hVar)
Dim hVar As Long
Dim VBVar As String
'Handle holen
Call AdsOcx1.AdsCreateVarHandle("MAIN.PLCVar", hVar)
VBVar = "TwinCAT"
Call AdsOcx1.AdsSyncWriteStringVarReq(hVar, LenB(VBVar), VBVar)
'Handle freigeben
Call AdsOcx1.AdsDeleteVarHandle(hVar)