Access to the ADS devices

There are several methods of accessing the data of an ADS device:

Depending on the application environment (communication medium, quantity of data, data transmission rate,...) each method has certain advantages, and these are explained in detail further below. There are two further variations that can be used to identify a variable in an ADS device.

By address

An address is given. The address is composed of the index group and the index offset. The address assignment is described in the corresponding documentation for the ADS device.

By variable name

As an alternative, the name of an ADS variable can be given when accessing an ADS device.

Synchron

Once the write/read method has been called, the execution of the Visual Basic program is interrupted until the requested data is available. In the following instructions it is possible to continue working with the data immediately. The advantage of this access method is that very little programming effort has to be carried out in the Visual Basic program.
This access method is recommended if the Visual Basic program and the ADS device are on the same computer or are connected via a fast network so that the waiting time is very short.
Example: The operator is to enter various parameters in an input window. The data is to be written to the PLC when a button is clicked. Since the writing of the values is not performed cyclically, but in a manner that depends on the user's behavior, a synchronous write command should be used in this case.

Asynchron

In the case of asynchronous access, the execution of the Visual Basic program is not interrupted, but continues immediately with the next command. When the requested data arrive at the ADS-OCX, an event function is triggered in the Visual Basic program, in which the value is passed as a parameter. By the fact that the Visual Basic program can receive its data at any time, a larger programming effort is necessary there than with the synchronous access method.
If the ADS server and the Visual Basic program are spatially separated from each other and the data transmission medium is very slow, e.g. modem or ISDN, then the asynchronous mode of operation makes sense.

Connect

If values are to be transmitted continuously to a Visual Basic program, cyclical access, also known as 'by connect', is the easiest and most effective method. Calling the method results in the data from the ADS device being sent to the Visual Basic program cyclically or when there is a change, using an event function.

Example: The positions of multiple axes are to be shown in a display window, updated every 250 ms. Use the AdsReadVarConnectEx() method, so that every 250 ms the AdsReadConnectUpdateEx() event is triggered for each axis position. This principle can be further optimized, so that values are only transferred if the position of the axis changes (server on change)! There is a simple sample of this under 'Event-driven reading'.

Return values

All these methods return a value indicating whether the operation was carried out successfully, or whether an error occurred. It can generally be said that a return value of 0 indicates error-free execution. A detailed list of the possible return values and their meanings can be found under ADS error codes.
Alternatively the ADS-OCX can trigger an exception in case of an error. This requires the EnableErrorHandling property to be set to TRUE. The cause of the error can then be determined via the Err object. The Err object is described in the Visual Basic documentation.

Method summary

 

by address

by variable name

synchron

Reading

AdsSyncReadReq()
AdsSyncReadBoolReq()
AdsSyncReadIntegerReq()

AdsSyncReadLongReq()
AdsSyncReadSingleReq()
AdsSyncReadDoubleReq()
AdsSyncReadStringReq()

-
AdsSyncReadBoolVarReq()AdsSyncReadIntegerVarReq()AdsSyncReadLongVarReq()AdsSyncReadSingleVarReq()AdsSyncReadDoubleVarReq()AdsSyncReadStringVarReq()

Writing

AdsSyncWriteReq()
AdsSyncWriteBoolReq()
AdsSyncWriteIntegerReq()
AdsSyncWriteLongReq()
AdsSyncWriteSingleReq()
AdsSyncWriteDoubleReq()
AdsSyncWriteStringReq()

-
AdsSyncWriteBoolVarReq()
AdsSyncWriteIntegerVarReq()
AdsSyncWriteLongVarReq()
AdsSyncWriteSingleVarReq()
AdsSyncWriteDoubleVarReq()AdsSyncWriteStringVarReq()

asynchron

Reading

AdsReadIntegerReq()
AdsReadLongReq()
AdsReadSingleReq()
AdsReadDoubleReq()
AdsReadStringReq()

-

Writing

AdsWriteIntegerReq()
AdsWriteLongReq()
AdsWriteSingleReq()
AdsWriteDoubleReq()
AdsWriteStringReq()

-

connect

Reading

AdsReadConnect()
AdsReadBoolConnect()
AdsReadIntegerConnect()
AdsReadLongConnect()
AdsReadSingleConnect()
AdsReadDoubleConnect()

AdsReadStringConnect()

AdsReadVarConnectEx()

Writing

AdsWriteConnect()
AdsWriteBoolConnect()
AdsWriteIntegerConnect()
AdsWriteLongConnect()
AdsWriteSingleConnect()
AdsWriteDoubleConnect()

AdsWriteVarConnect()
AdsWriteBoolVarConnect()
AdsWriteIntegerVarConnect()
AdsWriteLongVarConnect()
AdsWriteSingleVarConnect()
AdsWriteDoubleVarConnect()