AdsRead[Datatype]Connect
AdsReadBoolConnect
AdsReadIntegerConnect
AdsReadLongConnect
AdsReadSingleConnect
AdsReadDoubleConnect
AdsReadStringConnect
Creates a cyclic connection between a Visual Basic variable of type boolean, integer, long, single, double or string and a data item from an ADS device.
object.AdsRead[Datatype]Connect(
nIndexGroupAs Long,
nIndexOffset As Long,
cbLength As Long,
nRefreshType As Integer,
nCycleTime As Integer,
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)
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 the ADS variable is no longer required, it should be released using the AdsRead[Datatype]Disconnect() 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 the data type String: It should be noted that the length of the data 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
'wird beim Starten des Programms aufgerufen
Private Sub Form_Load()
'Verbindung zwischen Merkerwort 0 der SPS und VBVar herstellen
Call AdsOcx1.AdsReadIntegerConnect(&H4020&, 0&, 2&, 1, 110, VBVar)
End Sub
'wird beim Beenden des Programms aufgerufen
Private Sub Form_Unload(Cancel As Integer)
'Verbindung zwischen den Variablen trennen
Call AdsOcx1.AdsReadIntegerDisconnect(VBVar)
End Sub
'wird nach jedem Lesen vom ADS-OCX aufgerufen
Private Sub AdsOcx1_AdsReadConnectUpdate(ByVal nIndexGroup As Long, ByVal nIndexOffset As Long)
'Variablen am Bildschirm anzeigen
Label1.Caption = VBVar
End Sub
Dim VBVar As String
'wird beim Starten des Programms aufgerufen
Private Sub Form_Load()
'Visual Basic Variable initialisieren
VBVar = Space(10)
'Verbindung zur Variable in der SPS herstellen
Call AdsOcx1.AdsReadStringConnect(&H4020&, 0&, LenB(VBVar), 4, 110, VBVar)
End Sub
'wird beim Beenden des Programms aufgerufen
Private Sub Form_Unload(Cancel As Integer)
'Verbindung zur Variable in SPS beenden
Call AdsOcx1.AdsReadStringDisconnect(VBVar)
End Sub
'wird bei Veränderung der SPS-Variablen vom ADS-OCX aufgerufen
Private Sub AdsOcx1_AdsReadConnectUpdate(ByVal nIndexGroup As Long, ByVal nIndexOffset As Long)
If (nIndexGroup = &H4020) And (nIndexOffset = 0) Then
'Variablen in Form anzeigen
Label1.Caption = VBVar
End If
End Sub