AdsReadConnect
Creates a fixed connection between a Visual Basic variable and a data item from an ADS device.
object.AdsReadConnect(
nIndexGroupAs Long,
nIndexOffset As Long,
cbLength As Long,
nRefreshType As ADSOCXTRANSMODE,
nCycleTime As Integer,
pData As Variant
) 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)
nRefreshType
[in] Type of data exchange between VB variable and ADS variable (see the ADSOCXTRANSMODE data type)
nCycleTime
[in] Read cycle in ms
pData
[in] Visual Basic variable into which the data is written from the ADS variable
Return value
See ADS error codes
Comments
If the connection to an ADS variable is no longer required, it should be released using the AdsReadDisconnect() method. If only certain specific values are required in a form, the connection should only be created when the form is loaded, and should be released again when the form is closed. The variable type string is not supported by the AdsReadConnect() method.
Example
Dim VBVarInteger(0) As Integer
Dim VBVarSingle(0) As Single
Dim VBVarBoolean(0) As Boolean
'wird beim Starten des Programms aufgerufen
Private Sub Form_Load()
'Verbindung zu den Variablen in der SPS herstellen
Call AdsOcx1.AdsReadConnect(&H4020&, 0&, 2&, ADSTRANS_SERVERONCHA, 55, VBVarInteger)
Call AdsOcx1.AdsReadConnect(&H4020&, 2&, 4&, ADSTRANS_SERVERONCHA, 55, VBVarSingle)
Call AdsOcx1.AdsReadConnect(&H4021&, 48&, 2&, ADSTRANS_SERVERONCHA, 55, VBVarBoolean)
End Sub
'wird beim Beenden des Programms aufgerufen
Private Sub Form_Unload(Cancel As Integer)
'Verbindungen zu den Variablen in der SPS beenden
Call AdsOcx1.AdsReadDisconnect(VBVarInteger)
Call AdsOcx1.AdsReadDisconnect(VBVarSingle)
Call AdsOcx1.AdsReadDisconnect(VBVarBoolean)
End Sub
'wird nach Änderung einer SPS-Variablen vom ADS-OCX aufgerufen
Private Sub AdsOcx1_AdsReadConnectUpdate(ByVal nIndexGroup As Long, ByVal nIndexOffset As Long)
If (nIndexGroup = &H4020&) Then
Select Case nIndexOffset
Case 0: lblInteger.Caption = VBVarInteger(0)
Case 2: lblSingle.Caption = VBVarSingle(0)
End Select
End If
If (nIndexGroup = &H4021&) Then
Select Case nIndexOffset
Case 48: Shape1.BackColor = IIf(VBVarBoolean(0) = True, &HFF00&, &H8000&)
End Select
End If
End Sub