Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE® and XFC® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH & Co. KG, Germany.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


Introduction

The ADS-OCX provides methods, events and properties in order to be able to exchange information with other ADS devices via the TwinCAT Router. The ADS-OCX is implemented as an ActiveX control element, and is based on Microsoft's COM technology. Any programming environment that supports ActiveX controls can use the ADS-OCX. Visual Basic * (see below) is the programming environment most often used for ActiveX controls.

All the examples used for illustration in this guide are implemented in Visual Basic 6, Service Pack 3. None of the examples is particularly complicated, so very advanced knowledge of Visual Basic is not needed.


Access to the ADS devices

There are several methods of accessing the data of an ADS device:
· synchronous
· asynchronous
· cyclical

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.

Synchronous

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 type of access is that very little programming is called for in the Visual Basic program.
This kind of access is recommended if the Visual Basic program and the ADS device are located in the same computer, or if they are linked by a fast network, so that the waiting time is very short.
Example: The user is to enter various parameters via 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 behaviour, a synchronous write command should be used in this case.

Asynchronous

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. Because the time at which the Visual Basic program receives its data is not determined, the programming required there is more complex than is the case for the synchronous type of access.
If the ADS server and the Visual Basic program are at different physical locations, and the data transfer medium, such as a modem or ISDN connection, is very slow, then asynchronous working is appropriate.

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 several 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 optimised, so that values are only transferred if the position of the axis changes (server on change)! There is a simple example 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. There is a full listing of the possible return values and their meanings under 'ADS Error Codes'.
Alternatively, the ADS-OCX can trigger an exception in the event of an error . This requires the EnableErrorHandling property to be set to TRUE. The cause of the error can then be determined from the Err object. The Err object is described in the Visual Basic documentation.

Method summary

by address by variable name
synchronous Read AdsSyncReadReq()
AdsSyncReadBoolReq()
AdsSyncReadIntegerReq()

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

 -
AdsSyncReadBoolVarReq() AdsSyncReadIntegerVarReq() AdsSyncReadLongVarReq() AdsSyncReadSingleVarReq() AdsSyncReadDoubleVarReq() AdsSyncReadStringVarReq()
Write AdsSyncWriteReq()
AdsSyncWriteBoolReq()
AdsSyncWriteIntegerReq()
AdsSyncWriteLongReq()
AdsSyncWriteSingleReq()
AdsSyncWriteDoubleReq()
AdsSyncWriteStringReq() 		-
AdsSyncWriteBoolVarReq()
AdsSyncWriteIntegerVarReq()
AdsSyncWriteLongVarReq()
AdsSyncWriteSingleVarReq()
AdsSyncWriteDoubleVarReq() AdsSyncWriteStringVarReq()
asynchron Read AdsReadIntegerReq()
AdsReadLongReq()
AdsReadSingleReq()
AdsReadDoubleReq()
AdsReadStringReq() 		-
Write AdsWriteIntegerReq()
AdsWriteLongReq()
AdsWriteSingleReq()
AdsWriteDoubleReq()
AdsWriteStringReq() 		-
connect Read AdsReadConnect()
AdsReadBoolConnect()
AdsReadIntegerConnect()
AdsReadLongConnect()
AdsReadSingleConnect()
AdsReadDoubleConnect()

AdsReadStringConnect()

AdsReadVarConnectEx()
Write AdsWriteConnect()
AdsWriteBoolConnect()
AdsWriteIntegerConnect()
AdsWriteLongConnect()
AdsWriteSingleConnect()
AdsWriteDoubleConnect() 		AdsWriteVarConnect()
AdsWriteBoolVarConnect()
AdsWriteIntegerVarConnect()
AdsWriteLongVarConnect()
AdsWriteSingleVarConnect()
AdsWriteDoubleVarConnect()


ADS Return Codes

Error codes: 0x000..., 0x500..., 0x700..., 0x1000..., 0x274C...

Global Error Codes

Hex | Dec | Description | Possible Causes | Solution
0x0 | 0 | no error |  |
0x1 | 1 | Internal error |  |
0x2 | 2 | No Rtime |  |
0x3 | 3 | Allocation locked memory error |  |
0x4 | 4 | Insert mailbox error | No ADS mailbox was available to process this message. | Reduce the number of ADS calls (e.g ADS-Sum commands or Max Delay Parameter)
0x5 | 5 | Wrong receive HMSG |  |
0x6 | 6 | target port not found | ADS Server not started |
0x7 | 7 | target machine not found | Missing ADS routes |
0x8 | 8 | Unknown command ID |  |
0x9 | 9 | Bad task ID |  |
0xA | 10 | No IO |  |
0xB | 11 | Unknown ADS command |  |
0xC | 12 | Win 32 error |  |
0xD | 13 | Port not connected |  |
0xE | 14 | Invalid ADS length |  |
0xF | 15 | Invalid ADS Net ID |  |
0x10 | 16 | Low Installation level |  |
0x11 | 17 | No debug available |  |
0x12 | 18 | Port disabled |  |
0x13 | 19 | Port already connected |  |
0x14 | 20 | ADS Sync Win32 error |  |
0x15 | 21 | ADS Sync Timeout |  |
0x16 | 22 | ADS Sync AMS error |  |
0x17 | 23 | ADS Sync no index map |  |
0x18 | 24 | Invalid ADS port |  |
0x19 | 25 | No memory |  |
0x1A | 26 | TCP send error |  |
0x1B | 27 | Host unreachable |  |
0x1C | 28 | Invalid AMS fragment |  |

Router Error Codes

Hex | Dec | Description | Possible Causes | Solution
0x500 | 1280 | ROUTERERR_NOLOCKEDMEMORY | No locked memory can be allocated |
0x501 | 1281 | ROUTERERR_RESIZEMEMORY | The size of the router memory could not be changed |
0x502 | 1282 | ROUTERERR_MAILBOXFULL | The mailbox has reached the maximum number of possible messages. The current sent message was rejected | Check the connection between the communication partners
0x503 | 1283 | ROUTERERR_DEBUGBOXFULL | The mailbox has reached the maximum number of possible messages. The sent message will not be displayed in the debug monitor | Check the connection to the debug monitor
0x504 | 1284 | ROUTERERR_UNKNOWNPORTTYPE | The port type is unknown |
0x505 | 1285 | ROUTERERR_NOTINITIALIZED | Router is not initialised |
0x506 | 1286 | ROUTERERR_PORTALREADYINUSE | The desired port number is already assigned |
0x507 | 1287 | ROUTERERR_NOTREGISTERED | Port not registered |
0x508 | 1288 | ROUTERERR_NOMOREQUEUES | The maximum number of Ports reached |
0x509 | 1289 | ROUTERERR_INVALIDPORT | The port is invalid. |
0x50A | 1290 | ROUTERERR_NOTACTIVATED | TwinCAT Router not active |
0x50B | 1291 | ROUTERERR_FRAGMENTBOXFULL |  |
0x50C | 1292 | ROUTERERR_FRAGMENTTIMEOUT |  |
0x50D | 1293 | ROUTERERR_TOBEREMOVED |  |

General ADS Error Codes

Hex | Dec | Description | Possible Causes | Solution
0x700 | 1792 | error class <device error> |  |
0x701 | 1793 | Service is not supported by server |  |
0x702 | 1794 | invalid index group |  |
0x703 | 1795 | invalid index offset |  |
0x704 | 1796 | reading/writing not permitted |  |
0x705 | 1797 | parameter size not correct |  |
0x706 | 1798 | invalid parameter value(s) |  |
0x707 | 1799 | device is not in a ready state |  |
0x708 | 1800 | device is busy |  |
0x709 | 1801 | invalid context (must be in Windows) |  |
0x70A | 1802 | out of memory |  |
0x70B | 1803 | invalid parameter value(s) |  |
0x70C | 1804 | not found (files, ...) |  |
0x70D | 1805 | syntax error in command or file |  |
0x70E | 1806 | objects do not match |  |
0x70F | 1807 | object already exists |  |
0x710 | 1808 | symbol not found |  |
0x711 | 1809 | symbol version invalid | Onlinechange | Release handle and get a new one
0x712 | 1810 | server is in invalid state |  |
0x713 | 1811 | AdsTransMode not supported |  |
0x714 | 1812 | Notification handle is invalid | Onlinechange | Release handle and get a new one
0x715 | 1813 | Notification client not registered |  |
0x716 | 1814 | no more notification handles |  |
0x717 | 1815 | size for watch too big |  |
0x718 | 1816 | device not initialized |  |
0x719 | 1817 | device has a timeout |  |
0x71A | 1818 | query interface failed |  |
0x71B | 1819 | wrong interface required |  |
0x71C | 1820 | class ID is invalid |  |
0x71D | 1821 | object ID is invalid |  |
0x71E | 1822 | request is pending |  |
0x71F | 1823 | request is aborted |  |
0x720 | 1824 | signal warning |  |
0x721 | 1825 | invalid array index |  |
0x722 | 1826 | symbol not active | Onlinechange | Release handle and get a new one
0x723 | 1827 | access denied |  |
0x724 | 1828 | missing license |  | Activate license for TwinCAT 3 function
0x72c | 1836 | exception occured during system start |  | Check each device transistions
0x740 | 1856 | Error class <client error> |  |
0x741 | 1857 | invalid parameter at service |  |
0x742 | 1858 | polling list is empty |  |
0x743 | 1859 | var connection already in use |  |
0x744 | 1860 | invoke ID in use |  |
0x745 | 1861 | timeout elapsed |  | Check ADS routes of sender and receiver and your firewall setting
0x746 | 1862 | error in win32 subsystem |  |
0x747 | 1863 | Invalid client timeout value |  |
0x748 | 1864 | ads-port not opened |  |
0x750 | 1872 | internal error in ads sync |  |
0x751 | 1873 | hash table overflow |  |
0x752 | 1874 | key not found in hash |  |
0x753 | 1875 | no more symbols in cache |  |
0x754 | 1876 | invalid response received |  |
0x755 | 1877 | sync port is locked |  |

RTime Error Codes

Hex | Dec | Description | Possible Causes
0x1000 | 4096 | RTERR_INTERNAL | Internal fatal error in the TwinCAT real-time system
0x1001 | 4097 | RTERR_BADTIMERPERIODS | Timer value not vaild
0x1002 | 4098 | RTERR_INVALIDTASKPTR | Task pointer has the invalid value ZERO
0x1003 | 4099 | RTERR_INVALIDSTACKPTR | Task stack pointer has the invalid value ZERO
0x1004 | 4100 | RTERR_PRIOEXISTS | The demand task priority is already assigned
0x1005 | 4101 | RTERR_NOMORETCB | No more free TCB (Task Control Block) available. Maximum number of TCBs is 64
0x1006 | 4102 | RTERR_NOMORESEMAS | No more free semaphores available. Maximum number of semaphores is 64
0x1007 | 4103 | RTERR_NOMOREQUEUES | No more free queue available. Maximum number of queue is 64
0x1008 | 4104 | TwinCAT reserved. |
0x1009 | 4105 | TwinCAT reserved. |
0x100A | 4106 | TwinCAT reserved. |
0x100B | 4107 | TwinCAT reserved. |
0x100C | 4108 | TwinCAT reserved. |
0x100D | 4109 | RTERR_EXTIRQALREADYDEF | An external synchronisation interrupt is already applied
0x100E | 4110 | RTERR_EXTIRQNOTDEF | No external synchronsiation interrupt applied
0x100F | 4111 | RTERR_EXTIRQINSTALLFAILED | The apply of the external synchronisation interrupt failed
0x1010 | 4112 | RTERR_IRQLNOTLESSOREQUAL | Call of a service function in the wrong context
0x1017 | 4119 | RTERR_VMXNOTSUPPORTED | Intel VT-x extension is not supported.
0x1018 | 4120 | RTERR_VMXDISABLED | Intel VT-x extension is not enabled in BIOS.
0x1019 | 4121 | RTERR_VMXCONTROLSMISSING | Missing feature in Intel VT-x extension.
0x101A | 4122 | RTERR_VMXENABLEFAILS | Enabling Intel VT-x fails.

TCP Winsock Error Codes

Hex | Dec | Description | Possible Causes | Solution
0x274c | 10060 | A socket operation was attempted to an unreachable host | Host unreachable | Check network connection via ping
0x274d | 10061 | A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. | Host unreachable | Check network connection via ping
0x2751 | 10065 | No connection could be made because the target machine actively refused it |  |
 |  | Further Winsock error codes: Win32 Error Codes |  |


Installing the ADS OCX

The ADS OCX can be installed with Regsvr32. The path to the file that is to be registered must be stated.

Open the Run shell (Start -->Run...); type Regsvr32 <path to adsocx.ocx>\adsocx.ocx; Enter

It is not necessary to reboot the computer.


AboutBox

Displays an information window with the current version number and the copyright declaration of the ADS-OCX.

object.AboutBox( )

Parameter

-

Return value

-

Comments

-

Example


AdsAmsDisconnect

This method is used to disconnect the ADS-OCX from the TwinCAT Router.

object.AdsAmsDisconnect() As Long

Parameter

-

Return value

-

Comments

All applications are closed when the present user logs out from Windows NT/2000. If the program contains the ADS-OCX connected to the router, the program must cancel its connection to the TwinCAT Router. If this is not done, the program cannot be completely unloaded, and will still be seen in the NT Task Manager after a new log-on.

Cancelling the connection to the TwinCAT Router is achieved through the AdsAmsDisconnect() method. This should be called in the Form_Unload() event.

Example

Private Sub Form_Unload(Cancel As Integer)
  Call AdsOcx1.AdsAmsDisconnect
End Sub


AdsAmsPortEnabled

This method can be used to determine whether the AMS port is available for communication.

object.AdsAmsPortEnabled() As Boolean

Parameter

-

Return value

-

Comments

-

Example

The following example illustrates a function in which messages are written to the Windows NT/2000 Event Viewer. The method AdsLogFmtString() is used for this. Since the access to the Event Viewer is made via the TwinCAT Router, the method should only be used if the AMS port is active.

'Write messages via ADS to the Event Viewer
Public Function LogMsg (MsgType As ADSLOGMSGTYPE, MsgStr As String)
  If (AdsOcx.AdsAmsPortEnabled = True) Then
    MsgStr = Left(MsgStr, 250)
    Call AdsOcx.AdsLogFmtString(MsgType, MsgStr, 0, 0, 0, 0)
  End If
End Function


AdsCreateVarHandle

Generates a unique handle for an ADS variable.

object.AdsCreateVarHandle(
  varName   As String,
  hVar      As Long)
As Long

Parameter

varName

[in] Name of the ADS variable

hVar

[out] Handle of the ADS variable

Return value

see ADS error codes.

Comments

Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The first parameter of the method is composed from the POE name and the PLC variable that is 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 'varName' does not distinguish between upper and lower case letters. If only certain specific PLC variables are required in a form, the handle should only be created when the form is loaded, and should be released again when the form is closed. See also the AdsDeleteVarHandle() method.
Note for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue 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

-


AdsDeleteVarHandle

Releases the handle of a PLC variable again.

object.AdsDeleteVarHandle(
  hVar     As Long)
As Long

Parameter

hVar

[in] Handle of the ADS variable

Return value

see ADS error codes.

Comments

If the ADS variable that is referred to by a handle is no longer required, it should be released once more by means of the AdsDeleteVarHandle() method. If only certain specific ADS variables are required in a form, the handle should only be created when the form is loaded, and should be released again when the form is closed. See also the AdsCreateVarHandle() method.

Example

-


AdsEnableLogNotification

Sets the filter for the reception of messages via the TwinCAT Router.

object.AdsEnableLogNotification(
  nBasePort       As Long,
  nPorts          As Long,
  dwCtrlMask      As Long)
As Long

Parameter

nBasePort

[in] First port number for which the AdsLogNotification() event is triggered

nPorts

[in] Number of ports starting from nBasePort for which the AdsLogNotification() event is triggered

dwCtrlMask

[in] Filter mask for the kinds of messages that are to be reported (see ADSLOGMSGTYPE data type)

Return value

see ADS error codes.

Comments

ADS devices are able to send messages to other ADS devices via the TwinCAT Router. Before an ADS device is able to receive messages with the aid of the ADS-OCX, the AdsEnableLogNotification() method must be used to define a filter. This defines which messages are to be reported.
One of a filter's functions is to define a range of port numbers. All the messages from the ADS devices that lie within this range of port numbers will be reported by the AdsLogNotification() event.
The second parameter with which messages can be filtered is the message type. A distinction is drawn between information, warning and error (see ADSLOGMSGTYPE). Various other types of message can be received by using a OR combination.

Example

see the example: 'Send/receive messages via the TwinCAT Router


AdsEnumSymbols

The list of declared variables can be read from an ADS device with this method.

object.AdsEnumSymbols(
  strSymbolName       As String,
  nSymbolType         As Long,
  cbSymbolSize        As Long,
  strComment          As String,
  nIndexGroup         As Long,
  nIndexOffset        As Long,
  bNext               As Boolean)
As Long

Parameter

strSymbolName

[out] Name of the ADS variable

nSymbolType

[out] Data type of the ADS variable (see the ADSDATATYPEID data type)

cbSymbolSize

[out] Data length of the ADS variable in bytes

strComment

[out] Comment following the ADS variable declaration

nIndexGroup

[out] Index group of the ADS variable

nIndexOffset

[out] Index offset of the ADS variable

bNext

[in] TRUE for the first ADS variable, FALSE for all those which follow

Return value

see ADS error codes.

Comments

When the AdsEnumSymbols() method is first called, you must set the bNext parameter to FALSE. This causes all the information about the first variable to be read. Every time AdsEnumSymbols() is called after this, the parameter must be TRUE. This causes the information about the following variable to be read.

Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
Note for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue for the axis under 'General'. The ‘Create symbols’ box must be checked. See System Manager manual.

Example

see the example: 'Read PLC variable declaration'


AdsSetFirstDynSymbol

The list of declared variables can be read from an ADS device with this method.

object.AdsSetFirstDynSymbol(
  bForceReload               As Boolean)
As Long

Parameter

bForceReload

[in] TRUE if a (new) loading of the symbol information is wanted by the server. If still no symbol information existent, they will be load independed from bForceReload .

Return value

see ADS error codes

Remarks

The method call from AdsSetFirstDynSymbol() resets the internal "Pointer" of the current symbol, which can be loaded with AdsGetNextDynSymbol(), to the beginning

Note about the PLC: Please attend to the PLC Control that the 'Symbol-Download' under Project / Options / TwinCAT is activated. For further information please see the manual TwinCAT PLC Control.
Note about NC: The Symbol download has to be activated at each axis. This can de done in the configuration dialog of the axis under ‚General'. The field ‚Create Symbols' has to be marked. See manual of the TwinCAT System Manager.

Example

see example: 'Read PLC variables declaration'


AdsGetNextDynSymbol

The list of declared variables can be read from an ADS device with this method.

object.AdsGetNextDynSymbol(
  navType	       		As ADSGETDYNSYMBOLTYPE,
  bstrName         	As String,
  bstrFullName        	As String,
  bstrType          	As String,
  bstrComment          	As String,
  adsType         		As Long,
  symbolSize         	As Long,
  nIndexGroup         	As Long,
  nIndexOffset        	As Long)
As Long

Parameter

navType

[in] Navigation specification in the symbol tree (see data type ADSGETDYNSYMBOLTYPE)

bstrName

[out] Name of symbol (short form without prefixed names of the parents)

bstrFullName

[out] Full name of the symbol

bstrType

[out] Name of the symbol data type

strComment

[out] Comment behind the ADS variables declaration

adsType

[out] Data type of the ADS variable (see data type ADSDATATYPEID)

symbolSize

[out] Byte length of the symbol

nIndexGroup

[out] Index group of the ADS variable

nIndexOffset

[out] Index offset of the ADS variable

Return value

see ADS error codes.

Remarks

With navType ADSDYNSYM_GET_NEXT can be navigated through the complete symbol tree. Herewith all symbols can be read in a simple way. The three other navTypes can be used to controlled navigation through the symbol tree.

Note about the PLC: Please attend to the PLC Control that the 'Symbol-Download' under Project / Options / TwinCAT is activated. For further information please see the manual TwinCAT PLC Control.
Note about NC: The Symbol download has to be activated at each axis. This can de done in the configuration dialog of the axis under ‚General'. The field ‚Create Symbols' has to be marked. See manual of the TwinCAT System Manager.

Example

see example: 'Read PLC variables declaration'


AdsLogFmtString

Issues a message via the TwinCAT Router.

object.AdsLogFmtString(
  nMsgType     As ADSLOGMSGTYPE,
  strFmt       As String,
  arg0         As Variant,
  arg1         As Variant,
  arg2         As Variant,
  arg3         As Variant)
As Long

Parameter

nMsgType

[in] Type of message (see the ADSLOGMSGTYPE data type)

strFmt

[in] The message text that is to be issued

arg0

[in] 1st Parameter in the message text

arg1

[in] 2nd Parameter in the message text

arg2

[in] 3rd Parameter in the message text

arg3

[in] 4th Parameter in the message text

Return value

see ADS error codes.

Comments

The issued message is reported to all the ADS devices in which the filter conditions are satisfied. The issued message is also written into the Windows NT/2000 Event Logger.

There are three kinds of message: note, warning and error. The message that is issued must belong to one of these three types. Up to four numerical parameters can be included in the message string. The following letters can be used as placeholders:

Placeholder | Meaning
%d | Placeholder for a variable of type long/integer
%f | Placeholder for a variable of type single/double
%x | Placeholder for a variable of type hexadecimal
%X | Placeholder for a variable of type hexadecimal

The first placeholder is then occupied by the first parameter (arg0), the second placeholder with the second parameter (arg1), and so on.

Make sure that not too many messages are transmitted in a short time, as this can cause the performance of the whole system to deteriorate.

Tip: If you want to keep a log of messages in your program (e.g. malfunctions in a machine) you should make use of the TwinCAT Event Logger. This is significantly more powerful than the Windows NT/2000 Event Logger, and is adapted to the requirements of automation technology.

Example

see the example: Send/receive messages via the TwinCAT Router


AdsReadSymbolDesc

The AdsReadSymbolDesc() method can be used to obtain information about the individual symbols (variables) in ADS devices.

object.AdsReadSymbolDesc(
  strSymbolName       As String,
  nSymbolType         As ADSDATATYPEID,
  cbSymbolSize        As Long,
  strComment          As String,
  nIndexGroup         As Long,
  nIndexOffset        As Long)
As Long

Parameter

strSymbolName

[in] Name of ADS variable from which the information is to be read

nSymbolType

[out] Data type of the ADS variable (see the ADSDATATYPID data type)

cbSymbolSize

[out] Data length of the ADS variable in bytes

strComment

[out] Comment following the ADS variable declaration

nIndexGroup

[out] Index group of the ADS variable

nIndexOffset

[out] Index offset of the ADS variable

Return value

see ADS error codes.

Comments

If you wish to read the information for all the ADS variables from a ADS device, you will find a relevant example under 'Read PLC variable declaration'.

Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
Note for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue for the axis under 'General'. The ‘Create symbols’ box must be checked. See System Manager manual.

Example

-


AdsReadSymbolInfo

The AdsReadSymbolInfo() method can be used to obtain information about the symbols (variables) in ADS devices.

object.AdsReadSymbolInfo(
  pSymbolsAvailable   As Long,
  pBufSizeNeeded      As Long)
As Long

Parameter

pSymbolsAvailable

[out] Number of symbols in the ADS device

pBufSizeNeeded

[out] Length of the data, in bytes, in which the symbol information is to be stored

Return value

see ADS error codes.

Comments

Before the AdsEnumSymbols() method can be used to read the symbol list, the method AdsReadSymbolInfo() must be used to find the number of symbols and the size of the symbol list.

Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
Note for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue for the axis under 'General'. The ‘Create symbols’ box must be checked. See System Manager manual.

Example

see the example: 'Read PLC variable declaration'


AdsSyncWriteControlReq

Changes the status of an ADS device.

object.AdsSyncWriteControlReq(
  ADSSTATE     As Long,
  deviceState  As Long,
  length       As Long,
  pData        As Integer)
As Long

Parameter

ADSSTATE

[in] New state of the ADS device (see the ADSSTATE data type)

deviceState

[in] Reserved

length

[in] Length of the data in bytes

pData

[in]Visual Basic variable from which the data is written into the ADS variable

Return parameter

see ADS error codes.

Comments

As well as changing the ADS status, it is also possible to send data to the ADS device. Whether such data is evaluated, and how, depends on the individual ADS devices. The ADS devices supplied with TwinCAT (PLC, NC/NCI, camshaft controller, ...) do not evaluate such information.

Example

see the example: 'Detect/alter status change in TwinCAT Router and the PLC'


AdsWriteControlReq

Changes the ADS status and the device status of the ADS server.

object.AdsWriteControlReq(
  nInvokeId     As Long,
  nAdsState     As Long,
  nDeviceState  As Long,
  cbLength      As Long,
  pData         As Integer)
As Long

Parameter

nInvokeId

[in] Job number for identification of the answer

nAdsState

[in] New ADS status (see the ADSSTATE data type)

nDeviceState

[in] New device status

cbLength

[in] Length of the data in bytes

pData

[in] Visual Basic variable from which the data is written into the ADS variable

Return value

see ADS error codes.

Comments

In addition to changing the ADS status and the device status, it is also possible to send data to the ADS server in order to transfer further information. In the current ADS devices (PLC, NC, ...) this data has no further effect.
Any ADS device can inform another ADS device of its current state. A distinction is drawn here between the status of the device itself (DeviceState) and the status of the ADS interface of the ADS device (AdsState). The states that the ADS interface can adopt are laid down in the ADS specification.

Example

-


ShowPropertyPages

Displays the ADS-OCX properties window.

object.ShowPropertyPages( ) As Long

Parameter

-

Return value

see ADS error codes.

Remarks

-

Example


AdsSyncReadBoolVarReq

AdsSyncReadIntegerVarReq

AdsSyncReadLongVarReq

AdsSyncReadSingleVarReq

AdsSyncReadDoubleVarReq

AdsSyncReadStringVarReq

Reads data synchronously from an ADS device, and writes it into a Visual Basic variable of type boolean, integer, long, single, double or string.

object.AdsSyncRead[Datatype]VarReq(
  hVar      As Long,
  cbLength  As Long,
  pData     As [Datatype])
As Long

Parameter

hVar

[in] Handle of the ADS variable (see the AdsCreateVarHandle() method)

cbLength

[in] Length of the data in bytes (see VB variable length)

pData

[in] Visual Basic variable into which the data is written from the ADS variable

Return value

see ADS error codes.

Warning: In case of an error, the value of the pData variable is set to "0".

Comments

Execution of the Visual Basic program is halted until the data from the ADS device has arrived, or until the time in the AdsAmsCommTimeout property has been exceeded.
Comment on the string data type: Note 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().

VB Example

Dim hVar As Long
Dim VBVar As Single
'Fetch handle for the PLC variable
Call AdsOcx1.AdsCreateVarHandle("MAIN.PLCVar", hVar)
'Read variable
Call AdsOcx1.AdsSyncReadSingleVarReq(hVar, 4&, VBVar)
'Display variable
Label1.Caption = VBVar
'Release handle again
Call AdsOcx1.AdsDeleteVarHandle(hVar)
Dim hVar As Long
Dim VBVar As String
'Fetch handle for the PLC variable
Call AdsOcx1.AdsCreateVarHandle("MAIN.PLCVar", hVar)
'Initialise Visual Basic
VBVar = Space(10)
'Read variable
Call AdsOcx1.AdsSyncReadStringVarReq(hVar, LenB(VBVar), VBVar)
'Display variable
Label1.Caption = VBVar
'Release handle again
Call AdsOcx1.AdsDeleteVarHandle(hVar)

Delphi Example

procedure TForm1.Button1Click(Sender: TObject);
var     res1, res2, res3 :integer;
        //handles
        hBoolean, hSmallint, hLongint, hSingle, hDouble, hString : integer;
        //read buffer
        vWordBool : WordBool;
        vSmallint : Smallint;
        vLongint : Longint;
        vSingle : Single;
        vDouble : Double;
        vString : WideString;
begin
        res1 := AdsOcx1.AdsCreateVarHandle( 'MAIN.vBOOL', hBoolean );
        res2 :=  AdsOcx1.AdsSyncReadBoolVarReq( hBoolean, sizeof(vWordBool), vWordBool );
        res3 := AdsOcx1.AdsDeleteVarHandle( hBoolean );
        Label1.Caption := Format('res1: %d, res2: %d, res3: %d,  Value: %s', [res1, res2, res3, BoolToStr(vWordBool, TRUE)]);

        res1 := AdsOcx1.AdsCreateVarHandle( 'MAIN.vINT', hSmallint );
        res2 :=  AdsOcx1.AdsSyncReadIntegerVarReq( hSmallint, sizeof(vSmallint), vSmallint );
        res3 := AdsOcx1.AdsDeleteVarHandle( hSmallint );
        Label2.Caption := Format('res1: %d, res2: %d, res3: %d,  Value: %d', [res1, res2, res3, vSmallint]);

        res1 := AdsOcx1.AdsCreateVarHandle( 'MAIN.vDINT', hLongint );
        res2 :=  AdsOcx1.AdsSyncReadLongVarReq( hLongint, sizeof(vLongint), vLongint );
        res3 := AdsOcx1.AdsDeleteVarHandle( hLongint );
        Label3.Caption := Format('res1: %d, res2: %d, res3: %d,  Value: %d', [res1, res2, res3, vLongint]);

        res1 := AdsOcx1.AdsCreateVarHandle( 'MAIN.vREAL', hSingle );
        res2 :=  AdsOcx1.AdsSyncReadSingleVarReq( hSingle, sizeof(vSingle), vSingle );
        res3 := AdsOcx1.AdsDeleteVarHandle( hSingle );
        Label4.Caption := Format('res1: %d, res2: %d, res3: %d,  Value: %f', [res1, res2, res3, vSingle]);

        res1 := AdsOcx1.AdsCreateVarHandle( 'MAIN.vLREAL', hDouble );
        res2 :=  AdsOcx1.AdsSyncReadDoubleVarReq( hDouble, sizeof(vDouble), vDouble );
        res3 := AdsOcx1.AdsDeleteVarHandle( hDouble );
        Label5.Caption := Format('res1: %d, res2: %d, res3: %d,  Value: %f', [res1, res2, res3, vDouble]);

        res1 := AdsOcx1.AdsCreateVarHandle( 'MAIN.vSTRING', hString );
        SetLength(vString,80{standard length of the PLC string variable});
        res2 :=  AdsOcx1.AdsSyncReadStringVarReq( hString, Length(vString)*2{byte length!}, vString );
        res3 := AdsOcx1.AdsDeleteVarHandle( hString );
        Label6.Caption := Format('res1: %d, res2: %d, res3: %d,  Length: %d, Value: %s', [res1, res2, res3, Length(vString), vString]);
end;


AdsSyncReadReq

Reads data of any type synchronously from an ADS device.

object.AdsSyncReadReq(
  nIndexGroup   As Long,
  nIndexOffset  As Long,
  cbLength      As Long,
  pData         As YY)
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 length)

pData

[in] Visual Basic variable into which the data is written from the ADS variable

Return value

see ADS error codes.

Warning: In case of an error, the value of the pData variable is set to "0".

Comment

Execution of the Visual Basic program is halted until the data from the ADS device has arrived, or until the time in the AdsAmsCommTimeout property has been exceeded.
The Visual Basic variable must be declared as an array. The whole array is passed to the method.
The string variable type is not supported.

Example

Dim VBVarInteger(0) As Integer
Dim VBVarLong(0) As Long
Dim VBVarSingle(0) As Single
Dim VBVarDouble(0) As Double
Dim VBVarByte(0) As Byte
Dim VBVarBool(0) As Boolean

'Read variable
Call AdsOcx1.AdsSyncReadReq(&H4020&, 0&, 2&, VBVarInteger)
Call AdsOcx1.AdsSyncReadReq(&H4020&, 2&, 4&, VBVarLong)
Call AdsOcx1.AdsSyncReadReq(&H4020&, 6&, 4&, VBVarSingle)
Call AdsOcx1.AdsSyncReadReq(&H4020&, 10&, 8&, VBVarDouble)
Call AdsOcx1.AdsSyncReadReq(&H4020&, 18&, 1&, VBVarByte)
Call AdsOcx1.AdsSyncReadReq(&H4021&, 152&, 2&, VBVarBool)

'Display variable
lblInteger.Caption = VBVarInteger(0)
lblLong.Caption = VBVarLong(0)
lblSingle.Caption = VBVarSingle(0)
lblDouble.Caption = VBVarDouble(0)
lblByte.Caption = VBVarByte(0)
lblBool.Caption = VBVarBool(0)


AdsSyncReadBoolReq

AdsSyncReadIntegerReq

AdsSyncReadLongReq

AdsSyncReadSingleReq

AdsSyncReadDoubleReq

AdsSyncReadStringReq

Reads data synchronously from an ADS device, and writes it into a Visual Basic variable of type boolean, integer, long, single, double or string.

object.AdsSyncRead[Datatype]Req(
  nIndexGroup     As Long,
  nIndexOffset    As Long,
  cbLength        As Long,
  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 length)

pData

[in] Visual Basic variable into which the data is written from the ADS variable

Return value

see ADS error codes.

Warning: In case of an error, the value of the pData variable is set to "0".

Comments

Execution of the Visual Basic program is halted until the data from the ADS device has arrived, or until the time in the AdsAmsCommTimeout property has been exceeded.
Comment on the string data type: Note 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().

VB Example

Dim VBVar As Long
'Read value
Call AdsOcx1.AdsSyncReadLongReq(&H4020&, 0&, 8&, VBVar)
'Display variable
Label1.Caption = VBVar
Dim VBVar As String
'Initialise Visual Basic variable
VBVar = Space(10)
'Read value from variable
Call AdsOcx1.AdsSyncReadStringReq(&H4020&, 0&, LenB(VBVar), VBVar)
'Display variables in a form
Label1.Caption = VBVar

Delphi Example

procedure TForm1.Button2Click(Sender: TObject);
var     res :integer;
        //read buffer
        vWordBool : WordBool;
        vSmallint : Smallint;
        vLongint : Longint;
        vSingle : Single;
        vDouble : Double;
        vString : WideString;
begin
        res :=  AdsOcx1.AdsSyncReadBoolReq( $4020, 0, sizeof(vWordBool), vWordBool );
        Label1.Caption := Format('res: %d,  Value: %s', [res, BoolToStr(vWordBool, TRUE)]);

        res :=  AdsOcx1.AdsSyncReadIntegerReq( $4020, 2, sizeof(vSmallint), vSmallint );
        Label2.Caption := Format('res: %d,  Value: %d', [res, vSmallint]);

        res :=  AdsOcx1.AdsSyncReadLongReq( $4020, 4, sizeof(vLongint), vLongint );
        Label3.Caption := Format('res: %d,  Value: %d', [res, vLongint]);

        res :=  AdsOcx1.AdsSyncReadSingleReq( $4020, 16, sizeof(vSingle), vSingle );
        Label4.Caption := Format('res: %d,  Value: %f', [res, vSingle]);

        res :=  AdsOcx1.AdsSyncReadDoubleReq( $4020, 32, sizeof(vDouble), vDouble );
        Label5.Caption := Format('res: %d,  Value: %f', [res, vDouble]);

        SetLength(vString,80{standard length of the PLC string variable});
        res :=  AdsOcx1.AdsSyncReadStringReq( $4020, 64, Length(vString)*2{byte length!}, vString );
        Label6.Caption := Format('res: %d,  Length: %d, Value: %s', [res, Length(vString), vString]);
end;


AdsSyncWriteBoolVarReq

TwinCAT ADS-OCX: Reference

AdsSyncWriteBoolVarReq
AdsSyncWriteIntegerVarReq
AdsSyncWriteLongVarReq
AdsSyncWriteSingleVarReq
AdsSyncWriteDoubleVarReq
AdsSyncWriteStringVarReq

Requests data synchronously from an ADS device, and writes it into a Visual Basic variable of type boolean, integer, long, single, double or string.

object.AdsSyncWrite[Datatype]VarReq(
  hVar    As Long,
  length  As Long,
  pData   As [Datatype])
As Long

Parameter

hVar

[in] Handle of the ADS variable (see the AdsCreateVarHandle() method)

length

[in] Length of the data in bytes (see VB variable length)

pData

[in] Visual Basic variable from which the data is written into the ADS variable

Return value

see ADS error codes.

Comments

Execution of the Visual Basic program is halted until the data from the ADS device has arrived, or until the time in the AdsAmsCommTimeout property has been exceeded.
Comment on the string data type: Note 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 hVar As Long
Dim VBVar As Double
Call AdsOcx1.AdsCreateVarHandle("MAIN.PLCVar", hVar)
VBVar = 3,1415
Call AdsOcx1.AdsSyncWriteDoubleVarReq(hVar, 8&, VBVar)
Call AdsOcx1.AdsDeleteVarHandle(hVar)
Dim hVar As Long
Dim VBVar As String
'Fetch handle
Call AdsOcx1.AdsCreateVarHandle("MAIN.PLCVar", hVar)
VBVar = "TwinCAT"
Call AdsOcx1.AdsSyncWriteStringVarReq(hVar, LenB(VBVar), VBVar)
'Release handle
Call AdsOcx1.AdsDeleteVarHandle(hVar)


AdsSyncWriteReq

Writes data of any type synchronously to an ADS device.

object.AdsSyncWriteReq(
  nIndexGroup    As Long,
  nIndexOffset   As Long,
  cbLength       As Long,
  pData          As YY)
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 length)

pData

[in] Visual Basic variable from which the data is written into the ADS variable

Return value

see ADS error codes.

Comments

Execution of the Visual Basic program is halted until the ADS device has received the data, or until the time in the AdsAmsCommTimeout property has been exceeded.
The Visual Basic variable must be declared as an array. The whole array is passed to the method.
The string variable type is not supported.

Example

Dim VBVarInteger(0) As Integer
Dim VBVarLong(0) As Long
Dim VBVarSingle(0) As Single
Dim VBVarDouble(0) As Double
Dim VBVarByte(0) As Byte
Dim VBVarBoolean(0) As Boolean

VBVarInteger(0) = 123
VBVarLong(0) = 456
VBVarSingle(0) = 3,1415
VBVarDouble(0) = 2,876
VBVarByte(0) = 7
VBVarBoolean(0) = False

'Write values to PLC
Call AdsOcx1.AdsSyncWriteReq(&H4020&, 0&, 2&, VBVarInteger)
Call AdsOcx1.AdsSyncWriteReq(&H4020&, 2&, 4&, VBVarLong)
Call AdsOcx1.AdsSyncWriteReq(&H4020&, 6&, 4&, VBVarSingle)
Call AdsOcx1.AdsSyncWriteReq(&H4020&, 10&, 8&, VBVarDouble)
Call AdsOcx1.AdsSyncWriteReq(&H4020&, 18&, 1&, VBVarByte)
Call AdsOcx1.AdsSyncWriteReq(&H4021&, 152&, 2&, VBVarBoolean)


AdsSyncWriteBoolReq

TwinCAT ADS-OCX: Reference

AdsSyncWriteBoolReq
AdsSyncWriteIntegerReq
AdsSyncWriteLongReq
AdsSyncWriteSingleReq
AdsSyncWriteDoubleReq
AdsSyncWriteStringReq

Writes data synchronously from a Visual Basic variable of type boolean, integer, long, single, double or string into a data item of an ADS device.

object.AdsSyncWrite[Datatype]Req(
  indexGroup   As Long,
  indexOffset  As Long,
  length       As Long,
  pData        As [Datatype])
As Long

Parameter

indexGroup

[in] Index group of the ADS variable

indexOffset

[in] Index offset of the ADS variable

length

[in] Length of the data in bytes (see VB variable length)

pData

[in] Visual Basic variable from which the data is written into the ADS variable

Return value

see ADS error codes.

Comments

Execution of the Visual Basic program is halted until the ADS device has received the data, or until the time in the AdsAmsCommTimeout property has been exceeded.
Comment on the string data type: Note 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 Boolean
VBVar = True
Call AdsOcx1.AdsSyncWriteBoolReq(&H4021&, 0&, 2&, VBVar)
Dim VBVar As String
VBVar = "TwinCAT"
Call AdsOcx1.AdsSyncWriteStringReq(&H4020&, 0&, LenB(VBVar), VBVar)


AdsReadIntegerReq

TwinCAT ADS-OCX: Reference

AdsReadIntegerReq
AdsReadLongReq
AdsReadSingleReq
AdsReadDoubleReq
AdsReadStringReq

Issues a read request for a data item of type integer, long, single, double or string.

object.AdsRead[Datatype]Req(
  nInvokeId     As Long,
  nIndexGroup   As Long,
  nIndexOffset  As Long,
  cbLength      As Long)
As Long

Parameter

nInvokeId

[in] Job number for identification of the answer

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 length)

Return value

see ADS error codes.

Comments

Once a read request has been sent to the ADS device, execution of the Visual Basic program continues. As soon as the data is present, the ADS-OCX issues the AdsRead[Datatype]Conf() event function, with which the requested data is transferred.
When a read request is issued, an identification number, which is later returned when the event function is called, must also be provided. This makes it possible to assign the event function to the appropriate read request.
Comment on the string data type: Note 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 nInvokeId As Long
nInvokeId = 1
'Read MW0 from the PLC
Call AdsOcx1.AdsReadIntegerReq(nInvokeId, &H4020&, 0&, 4&)

Private Sub AdsOcx1_AdsReadIntegerConf(ByVal nInvokeId As Long, ByVal nResult As Long, ByVal cbLength As Long, pData As Integer)
    If (nInvokeId = 1) And (nResult = 0) Then
        'Display data
        Label1.Caption = pData
    End If
End Sub
Dim nInvokeId As Long
nInvokeId = 1
'Read from the PLC
Call AdsOcx1.AdsReadStringReq(nInvokeId, &H4020&, 0&, 20&)

Private Sub AdsOcx1_AdsReadStringConf(ByVal nInvokeId As Long, ByVal nResult As Long, ByVal cbLength As Long, ByVal pData As String)
    If (nInvokeId = 1) And (nResult = 0) Then
        'Display data
        Label1.Caption = pData
    End If
End Sub


AdsWriteIntegerReq

TwinCAT ADS-OCX: Reference

AdsWriteIntegerReq
AdsWriteLongReq
AdsWriteSingleReq
AdsWriteDoubleReq
AdsWriteStringReq

Issues a read request for a data item of type integer, long, single, double or string.

object.AdsWrite[Datatype]Req(
  nInvokeId     As Long,
  nIndexGroup   As Long,
  nIndexOffset  As Long,
  cbLength      As Long,
  pData         As [Datatype])
As Long

Parameter

nInvokeId

[in] Job number for identification of the answer

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 length)

pData

[in] Visual Basic variable from which the data is written into the ADS variable

Return value

see ADS error codes.

Comments

Once a write request has been sent to the ADS device, execution of the Visual Basic program continues. As soon as the data has been written, the ADS-OCX triggers the AdsWriteConf() event function.
When a write request is issued, an identification number, which is later returned when the event function is called, must also be provided. This makes it possible to assign the event function to the appropriate write request.
Comment on the string data type:Note 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
Dim nInvokeId As Long
VBVar = 100
nInvokeId = 1
Call AdsOcx1.AdsWriteIntegerReq(nInvokeId, &H4020&, 0&, 2&, VBVar)

Private Sub AdsOcx1_AdsWriteConf(ByVal nInvokeId As Long, ByVal nResult As Long)
    If (nResult <> 0) Then MsgBox ("Error AdsWriteConf " & nResult)
End Sub
Dim VBVar As String
Dim InvokeId As Long
VBVar = "TwinCAT"
InvokeId = 1
Call AdsOcx1.AdsWriteStringReq(InvokeId, &H4020&, 0&, LenB(VBVar), VBVar)

Private Sub AdsOcx1_AdsWriteConf(ByVal nInvokeId As Long, ByVal nResult As Long)
    If (nResult <> 0) Then MsgBox ("Error AdsWriteConf " & nResult)
End Sub


AdsReadVarConnectEx

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

object.AdsReadVarConnectEx(
  adsVarName       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 AdsReadConnectUpdateEx() 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 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.
Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The method's first parameter is composed of the POE name and the PLC variable that is 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 for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue 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 Borland Delphi user: Method AdsReadVarConnectEx2() and event AdsReadConnectUpdateEx2() has the same functionality as the method AdsReadVarConnectEx() and event AdsReadConnectUpdateEx(). The OleVariant parameters of the event AdsReadConnectUpdateEx() are not passed correctly to the Delphi-Application. Please use the method AdsReadVarConnectEx2() in your Delphi-Applications.

Example

see the example: 'Event driven reading'


AdsReadVarConnectEx2

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

object.AdsReadVarConnectEx(
  adsVarName       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 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.
Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The method's first parameter is composed of the POE name and the PLC variable that is 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 for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue 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

See the Visual Basic sample: 'Event driven reading'


AdsReadVarConvertConnect

From TwinCAT 2.8 Build > 743 and above.

This method creates a fixed connection to a variable in an ADS device. The usrConvertType parameter can be used to specify which data type (format) the incoming variable data should have in the event function. The usrConvertType parameter is passed by value, which means that the data type passed is only used as a "template" for the conversion. During the conversion, the appropriate quantity of data bytes is copied into the data type specified by the user.

object.AdsReadVarConvertConnect(
  adsVarName       	As String,
  nRefreshType     	As ADSOCXTRANSMODE,
  nCycleTime       	As Long,
  phConnect       		As Long,
  usrConvertType  		As Variant,
  hUser            	As Variant)
As Long

Parameters

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!).

usrConverType

[in] Data type into which the event data is to be converted. The following table contains a list of the supported VB data types that can be passed as parameters.

Visual Basic data type | Equal to C++ VARTYPE | Equal to PLC data type (memory use)
Byte | VT_UI1 | BYTE (1 byte)
Integer | VT_I2 | INT (2 bytes) and enums
Long | VT_I4 | DINT (4 bytes)
Single | VT_R4 | REAL (4 bytes)
Double | VT_R8 | LREAL (8 bytes)
String* | VT_BSTR | STRING (declared string length + zero termination)
Boolean** | VT_BOOL | BOOL (1 byte)
Date*** | VT_DATE | DT; DATE_AND_TIME (4 bytes)
not supported in VB | VT_UI2 | WORD; UINT (2 bytes)
not supported in VB | VT_UI4 | DWORD; UDINT (4 bytes)
not supported in VB | VT_I1 | SINT (1 byte)
Variant**** VT_VARIANT -
Dim varArray() As <anything of above types> VT_ARRAY | <anything of above types> -

* The string length must be set to the maximum number of characters (including the closing NULL) that the string variable can adopt. (VB string length + 1 byte (for zero termination)) bytes are then copied from the event data into a string variable. After this, the length of the string is then shortened to the actual length. In other words, the string is truncated at the first null character. With appropriately set string lengths, string arrays can also be read from the PLC. E.g.:

VAR_GLOBAL
         plcStringArr    : ARRAY[ 1..2 ] OF STRING(30);
END_VAR

in VB:

Dim  vbStringArr( 1 To 2) As String
vbStringArr(1) = String( 31, "#")
vbStringArr(2) = String( 31, "#")
call AdsOcx1.AdsReadVarConvertConnect(".plcStringArr", ADSTRANS_SERVERONCHA, 300, hConnect, vbStringArr )

** At converting each byte event data is converted into a 2 byte OleVariant data type. It applies: TRUE at Data <> 0 and FALSE at Data = 0;

*** The OLE variant data type Date can only be used, for instance, to read PLC variables of type DATE_AND_TIME into a VB application. The local settings of the PC are taken into account during the conversion. Other PLC data types such as TIME or TOD are not supported, because they cannot be appropriately converted.

**** The variant variable must be initialised with a data type. VT_EMPTY or VT_NULL, for instance, are not allowed.

hUser

[in] Optional: This value is passed when the AdsReadConvertConnectUpdate() 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 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.
Note for PLC: Ensure that Symbol download is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The method's first parameter is composed of the POE name and the PLC variable that is 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 for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue 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

see the Visual Basic example: Event-driven reading (with conversion to another type)


AdsReadBoolVarConnect, AdsReadIntegerVarConnect, AdsReadLongVarConnect, AdsReadSingleVarConnect, AdsReadDoubleVarConnect, AdsReadStringVarConnect

TwinCAT ADS-OCX: Referenz

AdsReadBoolVarConnect
AdsReadIntegerVarConnect
AdsReadLongVarConnect
AdsReadSingleVarConnect
AdsReadDoubleVarConnect
AdsReadStringVarConnect

Creates a fixed 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]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 length)

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.

Comment

If the connection to an ADS variable is no longer required, it should be released using the AdsReadBoolDisconnect() 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.
Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The method's first parameter is composed of the POE name and the PLC variable that is 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.
If a variable from the PLC is linked to a Visual Basic variable you must enter 2 for the length, since Visual Basic manages boolean variables internally using 2 bytes.
Note for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue 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.

This method has been replaced by AdsReadVarConnectEx(). In future, use AdsReadVarConnectEx(), since AdsReadBoolVarConnect() will no longer be maintained, and will only be included for reasons of compatibility.

Example

-


AdsDisconnectEx

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

object.AdsDisconnectEx(
  hConnect As Long)
As Long

Parameter

hConnect

[in] Handle of the connection between the Visual Basic variable and the ADS variable

Return value

see ADS error codes.

Comments

If the connection to an ADS variable is no longer required, it should be closed using the AdsDisconnectEx() 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. See also the AdsReadVarConnectEx() method.

Example

see the example: 'Event driven reading'


AdsReadConnect

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

object.AdsReadConnect(
  nIndexGroup       As 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 length)

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

'is called at the start of the program
Private Sub Form_Load()
  'Create connection to the variables in the PLC
  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

'is called at the end of the program
Private Sub Form_Unload(Cancel As Integer)
  'End connections to the variables in the PLC
  Call AdsOcx1.AdsReadDisconnect(VBVarInteger)
  Call AdsOcx1.AdsReadDisconnect(VBVarSingle)
  Call AdsOcx1.AdsReadDisconnect(VBVarBoolean)
End Sub

'is called by the ADS-OCX after a PLC variable has changed
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


AdsReadDisconnect

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

object.AdsReadDisconnect(
  pData As Variant)
As Long

Parameter

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 closed 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. See also the AdsReadConnect() method.

Example

-


AdsReadBoolConnect

TwinCAT ADS-OCX: Reference

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(
  nIndexGroup       As 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 length)

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 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.
Comment on the string data type: Note 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

'is called at the start of the program
Private Sub Form_Load()
    'Create connection between PLC flag word 0 and VBVar
    Call AdsOcx1.AdsReadIntegerConnect(&H4020&, 0&, 2&, 1, 110, VBVar)
End Sub

'is called at the end of the program
Private Sub Form_Unload(Cancel As Integer)
    'Break connection between the variables
    Call AdsOcx1.AdsReadIntegerDisconnect(VBVar)
End Sub

'is called with every ADS-OCX read
Private Sub AdsOcx1_AdsReadConnectUpdate(ByVal nIndexGroup As Long, ByVal nIndexOffset As Long)
    'Display variables on the screen
    Label1.Caption = VBVar
End Sub
Dim VBVar As String

'is called at the start of the program
Private Sub Form_Load()
    'Initialise Visual Basic variable
    VBVar = Space(10)
    'Create connection to the variable in the PLC
    Call AdsOcx1.AdsReadStringConnect(&H4020&, 0&, LenB(VBVar), 4, 110, VBVar)
End Sub

'is called at the end of the program
Private Sub Form_Unload(Cancel As Integer)
    'End connection to the variable in the PLC
    Call AdsOcx1.AdsReadStringDisconnect(VBVar)
End Sub

'is called by the ADS-OCX after the PLC variable has changed
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


AdsReadBoolDisconnect

TwinCAT ADS-OCX: Reference

AdsReadBoolDisconnect
AdsReadIntegerDisconnect
AdsReadLongDisconnect
AdsReadSingleDisconnect
AdsReadDoubleDisconnect
AdsReadStringDisconnect

Ends a fixed 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]Disconnect(
  pData        As [Datatype])
As Long

Parameter

pData

[in] Visual Basic variable into which the data is written from the ADS variable

Return value

see ADS error codes.

Comments

If the value of an ADS variable is no longer required, the connection should be closed using the AdsReadBoolDisconnect() 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. See also the AdsRead[Datatype]VarConnect() and AdsRead[Datatype]Connect() method.

Example

-


AdsWriteDisconnect

Closes a fixed connection between a Visual Basic variable and the data item in an ADS device.

object.AdsWriteDisconnect(
  pData As Variant)
As Long

Parameter

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 of the ADS variable is no longer required, it should be released using the AdsWriteDisconnect() 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.

Example

-


AdsWriteBoolDisconnect

TwinCAT ADS-OCX: Reference

AdsWriteBoolDisconnect
AdsWriteIntegerDisconnect
AdsWriteLongDisconnect
AdsWriteSingleDisconnect
AdsWriteDoubleDisconnect

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

object.AdsWrite[Datatype]Disconnect(
  pData As [Datatype])
As Long

Parameter

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 of the ADS variable is no longer required, it should be released using the AdsWrite[Datatype]Disconnect() 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.

Example

-


AdsWriteVarConnect

Creates a fixed connection of a Visual Basic variable and a variable from an ADS device.

object.AdsWriteVarConnect(
  adsVarName     As String,
  cbLength       As Long,
  nRefreshType   As ADSOCXTRANSMODE,
  nCycleTime     As Integer,
  pData          As Variant)
As Long

Parameter

adsVarName

[in] Name of the ADS variable

cbLength

[in] Length of the data in bytes (see VB variable length)

nRefreshType

[in] Type of data exchange between VB variable and ADS variable (see the ADSOCXTRANSMODE data type). The method AdsWriteVarConnect supports (reasonable) only the mode ADSTRANS_CLIENTCYCLE. Thereby the value of the Visual Basic variable is written cyclically to the ADS device.

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 AdsWriteDisconnect() 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 string variable type is not supported.
Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The first parameter of the method is composed from the POE name and the PLC variable that is 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 for NC: Symbol download must be activated for each axis in the TwinCAT System Manager. This can be specified in the configuration dialogue 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 VBVarInteger(0) As Integer
Dim VBVarSingle(0) As Single
Dim VBVarBoolean(0) As Boolean

'is called at the start of the program
Private Sub Form_Load()
  'Create connection to the variables in the PLC
  Call AdsOcx1.AdsWriteVarConnect("MAIN.PLCVarInteger", 2&, 1, 110, VBVarInteger)
  Call AdsOcx1.AdsWriteVarConnect("MAIN.PLCVarSingle", 4&, 1, 110, VBVarSingle)
  Call AdsOcx1.AdsWriteVarConnect("MAIN.PLCVarBoolean", 2&, 1, 110, VBVarBoolean)
End Sub

'is called at the end of the program
Private Sub Form_Unload(Cancel As Integer)
  'End connection to the variables in the PLC
  Call AdsOcx1.AdsWriteDisconnect(VBVarInteger)
  Call AdsOcx1.AdsWriteDisconnect(VBVarSingle)
  Call AdsOcx1.AdsWriteDisconnect(VBVarBoolean)
End Sub

'is called by the user
Private Sub cmd_write_Click()
  VBVarInteger(0) = CInt(txt_int.Text)
  VBVarSingle(0) = CSng(txt_single.Text)
  VBVarBoolean(0) = IIf(chk_boolean.Value = 1, True, False)
End Sub


AdsWriteBoolVarConnect

TwinCAT ADS-OCX: Reference

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 length)

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 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.
Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The first parameter of the method is composed from the POE name and the PLC variable that is 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 for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue 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

'is called at the start of the program
Private Sub Form_Load()
    'Create connection to the variable in the PLC
    Call AdsOcx1.AdsWriteIntegerVarConnect("MAIN.PLCVar", 2&, 1, 110, VBVar)
End Sub

'is called at the end of the program
Private Sub Form_Unload(Cancel As Integer)
    'End connection to the variable in the PLC
    Call AdsOcx1.AdsWriteIntegerDisconnect(VBVar)
End Sub

'is called by the user
Private Sub cmd_write_Click()
    VBVar = CInt(Text1.Text)
End Sub


AdsWriteConnect

Creates a fixed connection of a Visual Basic variable and an ADS device.

object.AdsWriteConnect(
  nIndexGroup     As 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 length)

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 of the ADS variable is no longer required, it should be released using the AdsWriteDisconnect() 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 string variable type is not supported.

Example

Dim VBVarInteger(0) As Integer
Dim VBVarSingle(0) As Single
Dim VBVarBoolean(0) As Boolean

'is called at the start of the program
Private Sub Form_Load()
  'Create connection to the variables in the PLC
   Call AdsOcx1.AdsWriteConnect(&H4020&, 0&, 2&, ADSTRANS_CLIENTCYCLE, 55, VBVarInteger)
   Call AdsOcx1.AdsWriteConnect(&H4020&, 2&, 4&, ADSTRANS_CLIENTCYCLE, 55, VBVarSingle)
   Call AdsOcx1.AdsWriteConnect(&H4021&, 48&, 2&, ADSTRANS_CLIENTCYCLE, 55, VBVarBoolean)
End Sub

'is called at the end of the program
Private Sub Form_Unload(Cancel As Integer)
  'End connection to the variables in the PLC
  Call AdsOcx1.AdsWriteDisconnect(VBVarInteger)
  Call AdsOcx1.AdsWriteDisconnect(VBVarSingle)
  Call AdsOcx1.AdsWriteDisconnect(VBVarBoolean)
End Sub

'is called by the user
Private Sub cmd_write_Click()
  VBVarInteger(0) = CInt(txt_int.Text)
  VBVarSingle(0) = CSng(txt_single.Text)
  VBVarBoolean(0) = IIf(chk_boolean.Value = 1, True, False)
End Sub


AdsWriteBoolConnect

TwinCAT ADS-OCX: Reference

AdsWriteBoolConnect
AdsWriteIntegerConnect
AdsWriteLongConnect
AdsWriteSingleConnect
AdsWriteDoubleConnect

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

object.AdsWrite[Datatype]Connect(
  nIndexGroup      As 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 length)

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 of the ADS variable is no longer required, it should be released using the AdsWrite[Datatype]Disconnect() 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.

Example

Dim VBVar As Integer

'is called at the start of the program ---
Private Sub Form_Load()
    'Create connection to the variable
    Call AdsOcx1.AdsWriteIntegerConnect(&H4020&, 0&, 2&, 1, 110, VBVar)
End Sub

'is called at the end of the program
Private Sub Form_Unload(Cancel As Integer)
    'End connection to the variables in the PLC
    Call AdsOcx1.AdsWriteIntegerDisconnect(VBVar)
End Sub

'is called by the user
Private Sub Cmd_write_Click()
    VBVar = CInt(Text1.Text)
End Sub


AdsAmsConnectTimeout

This event is called, when the connection of a "by connect" linked varaiable gets a timeout.

object_AdsAmsConnectTimeout(
  indexGroup     As Long,
  indexOffset    As Long)

Parameter

indexGroup

[out] Index-group of the ADS-variable, which gets the timeout

indexOffset

[out] Index-offset of the ADS-variable, which gets the timeout

Comments

The event AdsAmsConnectTimeout is called only, if the ADSTRANSMODE is client cycled.

Example

-


AdsAmsTimeout

This event is called when an async read or write request gets a timeout.

object_AdsAmsTimeout(
  nInvokeId      As Long)

Parameter

nInvokeId

[out] Identification number of the request, which gets the timeout

Comments

-

Example

-


AdsConnectError

In case of an error in the server associated with an "by connect" connected variable, this event is called.

object_AdsAmsConnectTimeout(
  nIndexGroup    As Long,
  nIndexOffset   As Long,
  errorCode      As Long)

Parameter

indexGroup

[out] Index-group of the ADS-variable, where the error occured

indexOffset

[out] Index-offset of the ADS-variable, where the error occured

errorCode

[out] Codenumber of the error, which occured; see ADS Return Codes

Comments

-

Example

-


AdsLogNotification

This event is called as soon as an ADS device has issued a message and the previously defined filter conditions are satisfied.

object_AdsLogNotification(
  dateTime       As Date,
  nMs            As Long,
  dwMsgCtrl      As Long,
  nServerPort    As Long,
  szDeviceName   As String,
  szLogMsg       As String)

Parameter

dateTime

[out] Date and time at which the message was issued by the ADS device

nMs

[out] Milliseconds as the message was issued by the ADS device

dwMsgCtrl

[out] Filter mask for the kinds of messages that are to be reported (see ADSLOGMSGTYPE data type)

nServerPort

[out] Port number of the ADS device that issued the message

szDeviceName

[out] Name of the ADS device that issued the message

szLogMsg

[out] Message that was issued by the ADS device

Comments

As soon as an ADS device has issued a message, and the filter conditions defined by the AdsEnableLogNotificaion() method are satisfied, the AdsLogNotification() event is triggered. The message can be further evaluated by means of the parameters that are passed.

Example

see the example: 'Send/receive messages via the TwinCAT Router


AdsReadConnectUpdate

This event is called if the AdsReadYY(Var)Connect() method has been called, and the value from the ADS device has been read or has changed.

object_AdsReadConnectUpdate(
  nIndexGroup    As Long,
  nIndexOffset   As Long)

Parameter

nIndexGroup

[out] Date and time at which the message was issued by the ADS device

nIndexOffset

[out] Milliseconds as the message was issued by the ADS device

Comments

With the AdsReadConnectUpdate() event, it is not necessary that the value is transmitted at the same time, since the ADS-OCX will be updating the Visual Basic variable in the background. In order to optimise write accesses to display objects on the form, the event function should inquire which variable has changed, and only that element which displays this value should be updated on the form. If a VB variable is connected to an ADS variable by VarConnect, the handle of the variable is passed in the nIndexOffset parameter of the AdsReadConnectUpdate() event, while in this case the nIndexGroup parameter carries the constant value &HF005. In order to be able to evaluate the nIndexOffset, you must first use the AdsCreateVarHandle() method to fetch the handle of the ADS variable. This can be done, for instance, in the form's load event. The AdsReadConnectUpdate() event is then used to ask which variable handle was passed in the nIndexOffset parameter.
If the connection was not made with the variable name but with the variable address, then the address of the variable that has changed is passed in the nIndexGroup and nIndexOffset parameters.
If the connection between a VB variable and an ADS variable is closed, the handle should also be released using the AdsDeleteVarHandle() method.

Example

-


AdsReadConnectUpdateEx

This event is called if the AdsReadVarConnectEx() method has been called, and the value from the ADS device has been read or has changed.

object_AdsReadConnectUpdateEx(
  ByVal dateTime        As Date,
  ByVal nMs             As Long,
  ByVal hConnect        As Long,
  ByVal data            As Variant,
  Optional ByVal hUser  As Variant)

Parameter

dateTime

[out] Time stamp

nHs

[out] Milliseconds of time stamp

hConnect

[out] Handle of the connection; is created by the AdsReadVarConnectEx() method

data

[out] Value from the ADS device

hUser

[out] General purpose value; is passed when the AdsReadVarConnectEx() method is called

Comments

-

Example

see the example: 'Event driven reading'


AdsReadConnectUpdateEx2

This event is called if the AdsReadVarConnectEx2() method has been called, and the value from the ADS device has been read or has changed.

object_AdsReadConnectUpdateEx(
  ByVal dateTime        As Date,
  ByVal nMs             As Long,
  ByVal hConnect        As Long,
  ByRef data            As Variant,
  Optional ByRef hUser  As Variant)

Parameter

dateTime

[out] Time stamp

nHs

[out] Milliseconds of time stamp

hConnect

[out] Handle of the connection; is created by the AdsReadVarConnectEx2() method

data

[out] Value from the ADS device

hUser

[out] General purpose value; is passed when the AdsReadVarConnectEx2() method is called

Comments

Parameters data and hUser are send ByRef ( for Borland Delphi applications)

Example

see the example: 'Event driven reading'


AdsReadConvertConnectUpdate

From TwinCAT 2.8 Build > 743 and above.

This event is called if the AdsReadVarConvertConnect() method has been called, and the value from the ADS device has been read or has changed.

object_AdsReadConvertConnectUpdate(
      ByVal dateTime        As Date,
      ByVal nMs             As Long,
      ByVal hConnect        As Long,
      ByRef data            As Variant,
      Optional ByRef hUser  As Variant)

Parameters

dateTime

[out] Time stamp.

nHs

[out] Milliseconds of time stamp.

hConnect

[out] Handle of the connection; is created by the AdsReadVarConvertConnect() method

data

[out] Value from the ADS device. The data type of the variant variable is specified as a parameter when AdsReadVarConvertConnect() is called.

hUser

[out] General purpose value; it is passed when the AdsReadVarConvertConnect() method is passed.

Example

see the example: Event-driven reading (with conversion to another type)


AdsReadIntegerConf

AdsReadLongConf
AdsReadSingleConf
AdsReadDoubleConf
AdsReadStringConf
TwinCAT ADS-OCX: Reference

AdsReadIntegerConf
AdsReadLongConf
AdsReadSingleConf
AdsReadDoubleConf
AdsReadStringConf

Returns the result after the AdsRead[Datatype]Req() method has been called.

object_AdsRead[Datatype]Conf(
  nInvokeId        As Long,
  nResult          As Long,
  cbLength         As Long,
  pData            As [Datatype])

Parameter

nInvokeId

[out]

Job number for identification of the answer

nResult

[out] Error status; see ADS error codes

cbLength

[out] Length of the data in bytes

pData

[out] Data being read from the ADS device

Comments

Once a read request has been sent to the ADS device, execution of the Visual Basic program continues. As soon as the data is present, the ADS-OCX issues the AdsRead[ Datatype]Conf() event function, with which the requested data is transferred.
When a read request is issued, an identification number, which is later returned when the event function is called, must also be provided. This makes it possible to assign the event function to the appropriate read request. See also AdsRead[Datatype]Req().

Example

-


AdsRouterRemove

This event is triggered if the TwinCAT Router is completely removed from the operating system in the Windows NT/2000 Control Panel.

object_AdsRouterRemove()

Parameter

-

Comments

-

Example

see the example: 'Detect/alter status change in TwinCAT Router and the PLC'


AdsRouterShutdown

This event is triggered when the TwinCAT Router is stopped.

object_AdsRouterShutdown()

Parameter

-

Comments

-

Example

see the example: 'Detect/alter status change in TwinCAT Router and the PLC'


AdsRouterStart

This event is triggered when the TwinCAT Router is started.

object_AdsRouterStart()

Parameter

-

Comments

-

Example

see the example: 'Detect/alter status change in TwinCAT Router and the PLC'


AdsServerStateChanged

This event function is called when the state of the ADS device has changed.

object_AdsServerStateChanged(
  nAdsState      As ADSSTATE,
  nDeviceState   As Long)

Parameter

nAdsState

[out] New state of the ADS device (see the ADSSTATE data type)

nDeviceState

[out] (not presently supported)

Comments

-

Example

see the example: 'Detect/alter status change in TwinCAT Router and the PLC'


AdsServerSymChanged

This event function is triggered when the symbol table in the ADS device has changed.

object_AdsServerSymChanged()

Parameter

-

Comments

Every ADS device stores its symbol names in an internal table. Each symbol is assigned a handle that can be read with the AdsCreateVarHandle() method. This event is triggered if the symbol table changes, for instance because the number of variables has changed.

Example

see the example: 'Detect/alter status change in TwinCAT Router and the PLC'


AdsWriteConf

Confirms a write request.

object_AdsWriteConf(
  nInvokeId        As Long,
  nResult          As Long)

Parameter

nInvokeId

[out]

Job number for identification of the answer

nResult

[out] Error status; see ADS error codes

Comments

Once a write request has been sent to the ADS device, execution of the Visual Basic program continues. As soon as the data has been written into the device, the ADS-OCX issues the AdsWriteConf() event function.
When a write request is issued, an identification number, which is later returned when the event function is called, must also be provided. This makes it possible to assign the event function to the appropriate write request. See also AdsWrite[Datatype]Req().

Example

-


AdsAmsClientNetId

This property stores the NetId of the computer in which the Visual Basic program with the ADS-OCX is executing.

object.AdsAmsClientNetId As String

Comment

This is a read-only property, and can be changed neither within the Visual Basic development environment nor during the program's run-time.

The NetID can be set using the TwinCAT system control.


AdsAmsClientPort

The client port number is the port number with which other ADS devices can address the Visual Basic program.

object.AdsAmsClientPort As Long

Comment

If you do not prescribe a port number yourself, the ADS-OCX will automatically assign a port number. This will always be greater than 32767. Note that this port number is different after each start.

If your Visual Basic program is to receive a fixed port number, you must set the desired port number in the program using the AdsAmsClientPort property. In that case the value must be between 16000 and 32000.

You can also set the AdsAmsClientPort property by means of the ADS-OCX properties window during the development phase. SavePort must then be set to TRUE. This will cause the ADS-OCX not to change the port number.

See also the AdsAmsSaveClientPort property.


AdsAmsCommTimeout

AdsAmsCommTimeOut provides a time in milliseconds within which the communication partner is expected to answer.

object.AdsAmsCommTimeout As Long

Comment

Allowed values: 1 till 2147483647 milliseconds . Zero and negative values are unacceptable! Default value: 5000 milliseconds.


AdsAmsConnected

These properties can be used to verify, if the ADS-OCX is connected to the TC-AMS-Router.

object.AdsAmsConnected As Boolean

Comment

This is a read-only property.

If an connection to the TC-ADS-Router exists, the value of the property is "TRUE", otherwise the value is "FALSE".


AdsAmsSaveClientPort

Prevents the ADS-OCX from assigning the client's port dynamically.

object.AdsAmsSaveClientPort As Boolean

Comment

If you do not prescribe a port number yourself, the ADS-OCX will automatically assign a port number. This will always be greater than 32767. Note that this port number is different after each start.

If your Visual Basic program is to receive a fixed port number, you must set the desired port number in the program using the AdsAmsClientPort property. In that case the value must be between 16000 and 32000.

You can also set the AdsAmsClientPort property by means of the ADS-OCX properties window during the development phase. SavePort must then be set to TRUE. This will cause the ADS-OCX not to change the port number.

See also the AdsAmsClientPort property.


AdsAmsServerNetId

This property stores the NetId of the computer that the Visual Basic program with the ADS-OCX is to access.

object.AdsAmsServerNetId As String

Comment

ADS devices can be located on various computers within a network. Each computer must have a unique NetId within that network.

Enter the NetId of the computer in which the ADS device with which you want to communicate is located into this property. If this property contains an empty string, the ADS devices of the local computer are addressed. If, for instance, your Visual Basic program is always located on the same computer as the PLC, leave this property empty. This makes it easier for the Visual Basic program to be used on other computers, even when those computers have different NetIds.

The TwinCAT system control can be used to determine what NetID has been set.


AdsAmsServerPort

Contains the port number of the ADS device that is to be addressed with the ADS-OCX.

object.AdsAmsServerPort As Long

Comment

The port numbers of the individual ADS devices can be found in the corresponding documentation. The following table lists the most important ADS devices:

ADS device | Port number
NC / NCI | 501
PLC runtime system 1 | 801
PLC runtime system 2 | 811
PLC runtime system 3 | 821
PLC runtime system 4 | 831
Camshaft controller | 901


AdsClientAdsControl

Not supported at the moment, reserved for future use.


AdsClientAdsState

This property can be used to tell other communication partners what state the ADS device is in at the moment.

object.AdsClientAdsState As String

Comment

The states that are supported by an ADS device can be found in the documentation for the ADS device.


AdsClientBuild

Contains the build level of the ADS device.

object.AdsClientBuild As Integer

Comment

Every ADS device has properties from which the ADS device's version number and type identification can be read. The version number consists of:

Version (see the AdsClientVersion property)

Revision (see the AdsClientRevision property)

Build (see the AdsClientBuild property)

Whenever ADS devices are created you should ensure that these properties are set, so that the ADS device can be identified by other participating devices.


AdsClientDeviceControl

Not supported at the moment, reserved for future use.


AdsClientDeviceState

Not supported at the moment, reserved for future use.


AdsClientRevision

Contains the revision level of the ADS device.

object.AdsClientRevision As Integer

Comment

Every ADS device has properties from which the ADS device's version number and type identification can be read. The version number consists of:

  • Version (see the AdsClientVersion property)
  • Revision (see the AdsClientRevision property)
  • Build (see the AdsClientBuild property)

Whenever ADS devices are created you should ensure that these properties are set, so that the ADS device can be identified by other participating devices.


AdsClientType

Contains the type identification of the ADS device.

object.AdsClientType As String

Comment

The type identification consists of a character string of indeterminate length. Whenever ADS devices are created you should ensure that these properties are set, so that this ADS device can be identified by other participating devices.


AdsClientVersion

Contains the version number of the ADS device.

object.AdsClientVersion As Integer

Comment

Every ADS device has properties from which the ADS device's version number and type identification can be read. The version number consists of:

Version (see the AdsClientVersionproperty)

Revision (see the AdsClientRevisionproperty)

Build (see the AdsClientBuildproperty)

Whenever ADS devices are created you should ensure that these properties are set, so that the ADS device can be identified by other participating devices.


AdsServerAdsState

These properties can be used in order to establish the state of the ADS device that is presently being addressed.

object.AdsServerAdsState As String

Comment

The states that are indicated by an ADS device through this property can be found in the documentation for the ADS device.
This property is read-only.


AdsServerAdsControl

Not supported at the moment, reserved for future use.


AdsServerBuild

This property can be used in order to ask what is the version of the ADS device that is addressed.

object.AdsServerBuild As Integer

Comment

Every ADS device has properties from which the ADS device's version number and type identification can be read. The version number consists of:

  • Version (see the AdsServerVersion property)
  • Revision (see the AdsServerRevision property)
  • Build (see the AdsServerBuild property)


AdsServerDeviceControl

Not supported at the moment, reserved for future use.


AdsServerDeviceState

Not supported at the moment, reserved for future use.


AdsServerLastMessage

Not supported at the moment, reserved for future use.


AdsServerLastMessageNo

Not supported at the moment, reserved for future use.


AdsServerLastMessageSubNo

Not supported at the moment, reserved for future use.


AdsServerRefreshTimerInterval

Not supported at the moment, reserved for future use.


AdsServerRevision

This property can be used in order to ask what is the revision level of the ADS device that is addressed.

object.AdsServerRevision As Integer

Comment

Every ADS device has properties from which the ADS device's version number and type identification can be read. The version number consists of:

Version (see the AdsServerVersion property)

Revision (see the AdsServerRevision property)

Build (see the AdsServerBuild property)


AdsServerType

This property can be used in order to ask what is the type of the ADS device that is addressed.

object.AdsServerType As String

Comment

The table below lists the type identifications of the most important ADS devices:

ADS device | Description
IO | I/O server
PLC | PLC server
NC / NCI | NC-ADS server


AdsServerVersion

This property can be used in order to ask what is the version number of the ADS device that is addressed.

object.AdsServerVersion As Integer

Comment

Every ADS device has properties from which the ADS device's version number and type identification can be read. The version number consists of:

Version (see the AdsServerVersion property)

Revision (see the AdsServerRevision property)

Build (see the AdsServerBuild property)


AdsServerWatchDogEnable

Not supported at the moment, reserved for future use.


EnableErrorHandling

Switches on the exception handling.

object.EnableErrorHandling As Boolean

Comment

If this property is TRUE, and an error occurs within a method, an exception is triggered.Using the On Error Goto instruction it is possible to trap the exception at a defined jump label, and to examine the Err object to determine the cause.


Index

Index within a control array.

object.Index As Integer

Comment

It is possible to create an array of more than one ADS-OCX. For this purpose, each ADS-OCX that is to belong to the array is given the same name. The individual ADS-OCX devices are distinguished by their index property. The index normally begins with 0. The individual objects are addressed by the array name followed by the index in parenthesis, e.g. AdsOcxName(1).


Name

Unique name of the controller.

object.Name As String

Comment

The standard name for newly added ADS-OCX devices is the object type (AdsOcx) plus a unique integer. The first ADS-OCX, for example, has the name AdsOcx1, the second is AdsOcx2 and the third is AdsOcx3.
The name must start with a letter, and has a maximum length of 40 characters. Underscore characters (_) and numbers are permitted within the name. The names of global system objects (Clipboard, Screen or App) should not be used, as it would then no longer be possible to address them.


Object

With the aid of the object property of an OLE container you can also utilise the properties and methods of the linked or embedded object.

object.Object As Object

Comment

This property is used in association with OLE (Object Linking and Embedding). See the Visual Basic programming manual for further information.


Parent

Returns a form, object or a collection in which the ADS-OCX is contained.

object.Parent As Object

Comment

In order, for instance, to find the name of the container, you must enter the following instruction: AdsOcx1.Parent.Name


Tag

Contains a string for general purpose use.

object.Tag As String

Comment

Any data you wish may be stored in this property. Such data is neither evaluated by Visual Basic nor by the ADS-OCX.


ADSDATATYPEID

ADST_BIT             = 33 (&H21)
ADST_INT8            = 16 (&H10)
ADST_INT16           = 2
ADST_INT32           = 3
ADST_INT64           = 20 (&H14)
ADST_UINT8           = 17 (&H11)
ADST_UINT16          = 18 (&H12)
ADST_UINT32          = 19 (&H13)
ADST_UINT64          = 21 (&H15)
ADST_REAL32          = 4
ADST_REAL64          = 5
ADST_REAL80          = 32 (&H20)
ADST_BIGTYPE         = 65 (&H41)
ADST_VOID            = 0


ADSLOGMSGTYPE

ADSLOG_MSGTYPE_HINT         = 1
ADSLOG_MSGTYPE_WARN         = 2
ADSLOG_MSGTYPE_ERROR        = 4


ADSOCXTRANSMODE

ADSTRANS_CLIENTCYCLE      = 1
ADSTRANS_SERVERCYCLE      = 3
ADSTRANS_SERVERONCHA      = 4

Description

Parameter | Description
ADSTRANS_CLIENTCYCLE | The ADS-OCX executes a write / read command cyclically. The cycle time is rounded up to a multiple of 55. The shortest time is 55 ms. The timer that initiates the read / write runs in Windows NT/2000 user mode, which means that the time behaviour strongly depends on the loading of the system.
ADSTRANS_SERVERCYCLE (only when reading) | The ADS that has been addressed writes the data cyclically to the ADS-OCX. The smallest possible time is the cycle time of the ADS device; for the PLC, this is the task cycle time. The cycle time can be handled in 1 ms steps. If you enter 0 ms as the cycle time, then the data is sent to the ADS-OCX with every cycle of the ADS device task.
ADSTRANS_SERVERONCHA (only when reading) | The ADS device that has been addressed then only writes the data to the ADS-OCX if they have changed. The ADS device is sampled at the rate given by the cycle time. The cycle time can be handled in 1 ms steps. If you enter a cycle time of 0 ms, every change in the variables will be sent to the ADS-OCX. A longer cycle time can be used to reduce the number of data transmissions to the ADS-OCX.

The longest cycle time for all modes is 32767.

Warning: Too many write / read operations can load the system so heavily that the user interface becomes much slower.

Tip: Set the cycle time to the most appropriate values, and always close connections when they are no longer required.


ADSSTATE

ADSSTATE_INVALID         = 0
ADSSTATE_IDLE            = 1
ADSSTATE_RESET           = 2
ADSSTATE_INIT            = 3
ADSSTATE_START           = 4
ADSSTATE_RUN             = 5
ADSSTATE_STOP            = 6
ADSSTATE_SAVECFG         = 7
ADSSTATE_LOADCFG         = 8
ADSSTATE_POWERFAILURE    = 9
ADSSTATE_POWERGOOD       = 10 (&H0A)
ADSSTATE_ERROR           = 11 (&H0B)
ADSSTATE_SHUTDOWN        = 12 (&H0C)
ADSSTATE_SUSPEND         = 13 (&H0D)
ADSSTATE_RESUME          = 14 (&H0E)
ADSSTATE_CONFIG          = 15 (&H0F)'system is in config mode
ADSSTATE_RECONFIG        = 16 (&H10)'system should restart in config mode
ADSSTATE_MAXSTATES       = 17 (&H11)


ADSGETDYNSYMBOLTYPE

ADSDYNSYM_GET_NEXT 	= 1	// delivers next symbol( trys first ADSDYNSYM_GET_CHILD, then ADSDYNSYM_GET_SIBLING, then ADSDYNSYM_GET_PARENT)
ADSDYNSYM_GET_SIBLING 	= 2	// delivers the next symbol on the same level
ADSDYNSYM_GET_CHILD 	= 3	// delivers Child Symbol
ADSDYNSYM_GET_PARENT 	= 4	// delivers the next symbol on the parent level


AdsReadVarConnect

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

object.AdsReadVarConnect(
  adsVarName       As String,
  cbLength         As Long,
  nRefreshType     As ADSOCXTRANSMODE,
  nCycleTime       As Integer,
  pData            As Variant)
As Long

Parameter

adsVarName

[in] Name of the ADS variable

cbLength

[in] Length of the data in bytes (see VB variable length)

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.
This method does not support the string data type.
Note for PLC: Ensure that 'Symbol download' is activated in PLC Control under Project / Options / TwinCAT. You will find more detailed information in the PLC Control manual.
The method's first parameter is composed of the POE name and the PLC variable that is 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 for NC: Symbol download must be activated for each axis in the System Manager. This can be specified in the configuration dialogue 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.

This method has been replaced by AdsReadVarConnectEx(). In future, use AdsReadVarConnectEx(), since AdsReadVarConnect() will no longer be maintained, and will only be included for reasons of compatibility.

Example

-


AdsSyncReadStateReq

Reads the ADS status and the device status of the ADS device.

object.AdsSyncReadSateReq(
  pAdsState     As Long,
  pDeviceState  As Long)
As Long

Parameter

pAdsState

[in] Present ADS status (see the ADSSTATE data type)

pDeviceSatet

[in] (not presently supported)

Return value

see ADS error codes.

Comments

Any ADS device can inform another ADS device of its current state. A distinction is drawn here between the status of the device itself (DeviceState) and the status of the ADS interface of the ADS device (ADSSTATE). The states that the ADS interface can adopt are laid down in the ADS specification.

Example

-