AdsReadVarConnectEx2

Creates a fixed connection between a Visual Basic variable and a data item from an ADS device.

object.AdsReadVarConnectEx2(nIndexOffset As String,
  nRefreshType As ADSOCXTRANSMODE,
  nCycleTime As Long,
  phConnect    As Long 
  hUser As Variant
) As Long

Parameter

adsVarName

[in] Name of the ADS variable

nRefreshType

[in] Type of data exchange between VB variable and ADS variable (see the ADSOCXTRANSMODE data type)

nCycleTime

[in] Read cycle in ms

phConnect

[out] Contains a unique handle for the connection that has been established (this is not the handle of the ADS variable!).

hUser

[in] Optional: This value is passed when the AdsReadConnectUpdateEx2() event is called.

Return value

See ADS error codes

Comments

If the connection to an ADS variable is no longer required, it should be released using the AdsDisconnectEx() method. If only certain values are required in a form, the connection should only be created when the form is loaded and released again when the form is closed.
Note on PLC: Ensure that Symbol download is enabled in PLC Control under Project / Options / TwinCAT. More detailed information can be found in the PLC Control manual.
The first parameter of the method consists of the POE name and the PLC variable to be addressed. If, for instance, the variable 'SPSVar1' from the function 'Funk1' is to be accessed, then 'Funk1.SPSVar1' must be supplied as the first parameter. When global variables are being accessed, the POE name is omitted, as, for instance, in '.SPSGlobVar'. The parameter adsVarName does not distinguish between upper and lower case letters.
Note on NC: Symbol download must be enabled for each axis in the System Manager. This can be specified in the configuration dialog for the axis under General. The Create symbols box must be checked. See System Manager manual.
The symbolic names of the individual NC parameters have a fixed specification, and can be found in the NC documentation.

Note for use under Borland Delphi: When calling the AdsReadConnectUpdateEx() event function, the OleVariant parameters are not passed to the Delphi application correctly.  Please use the method AdsReadVarConnectEx2 and the corresponding event in Delphi applications. In Visual Basic applications both methods/events can be used.

Example

Visual Basic: 'Event-driven reading'