AdsWrite[Datatype]VarConnect

AdsWriteBoolVarConnect

AdsWriteIntegerVarConnect

AdsWriteLongVarConnect

AdsWriteSingleVarConnect

AdsWriteDoubleVarConnect

Creates a fixed connection between a Visual Basic variable of type boolean, integer, long, single or double and an ADS device.

object.AdsWrite[Datatype]VarConnect(
  adsVarName As String,
  cbLength As Long,
  nRefreshType As Integer,
  nCycleTime As Integer,
  pData As [Datatype]
) As Long

Parameter

adsVarName

[in] Name 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] Write cycle in ms

pData

[in] Visual Basic variable from which the data is written into 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 AdsWrite[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 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.

Example

Dim VBVar As Integer

'wird beim Starten des Programms aufgerufen
Private Sub Form_Load()
    'Verbindung zur Variable in der SPS herstellen
    Call AdsOcx1.AdsWriteIntegerVarConnect("MAIN.PLCVar", 2&, 1, 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.AdsWriteIntegerDisconnect(VBVar)
End Sub

'wird vom Bediener aufgerufen
Private Sub cmd_write_Click()
    VBVar = CInt(Text1.Text)
End Sub