AdsWrite[Datatype]Req

AdsWriteIntegerReq

AdsWriteLongReq

AdsWriteSingleReq

AdsWriteDoubleReq

AdsWriteStringReq

Issues a read request for a data item of type integer, long, single, double or string.

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

Parameter

nInvokeId

[in] Job number for identification of the response

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 from which the data is written into the ADS variable

Return value

See ADS error codes

Comments

Once the write request has been sent to the ADS device, execution of the Visual Basic program continues. As soon as the data has been written, the ADS-OCX triggers the AdsWriteConf() event function.

When a write request is issued, an identification number, which is later returned when the event function is called, must also be provided. This makes it possible to assign the event function to the appropriate write request.

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 VBVar As Integer
Dim nInvokeId As Long
VBVar = 100
nInvokeId = 1
Call AdsOcx1.AdsWriteIntegerReq(nInvokeId, &H4020&, 0&, 2&, VBVar)

Private Sub AdsOcx1_AdsWriteConf(ByVal nInvokeId As Long, ByVal nResult As Long)
    If (nResult <> 0) Then MsgBox ("Error AdsWriteConf " & nResult)
End Sub
Dim VBVar As String
Dim InvokeId As Long
VBVar = "TwinCAT"
InvokeId = 1
Call AdsOcx1.AdsWriteStringReq(InvokeId, &H4020&, 0&, LenB(VBVar), VBVar)

Private Sub AdsOcx1_AdsWriteConf(ByVal nInvokeId As Long, ByVal nResult As Long)
    If (nResult <> 0) Then MsgBox ("Error AdsWriteConf " & nResult)
End Sub