Method ITcIoCyclicCaller:AddIoDriver

Logs the ITcIoCyclic interface of a module to a cyclic I/O caller, e.g. a TwinCAT task.

Syntax

virtual HRESULT TCOMAPI AddIoDriver(STcIoCyclicEntry* 
pEntry, ITcIoCyclic* ipDrv, ULONG_PTR context=0, ULONG sortOrder=0)=0;

Method ITcIoCyclicCaller:AddIoDriver 1: Return value

If successful, S_OK ("0") or another positive value will be returned, cf. Return values. Extended messages refer in particular to the column HRESULT in ADS Return Codes.

Parameter

Name

Type

Description

pEntry

STcIoCyclicEntry

Pointer to a list item that is inserted into the internal list of the cyclic I/O caller; see also description.

ipDrv

ITcIoCyclic

[in] interface pointer used by the cyclic I/O caller.

context

ULONG_PTR

[optional] a context value that is transferred to the ITcIoCyclic::InputUpdate() and ITcIoCyclic::OutputUpdate methods with each call.

sortOrder

ULONG

[optional] The sort order can be used for controlling the order of execution if various module instances are executed by the same cyclic caller.

Description

A TwinCAT module class normally uses a Smart Pointer to refer to the cyclic I/O caller of type ITcIoCyclicCallerPtr. The object ID of the cyclic I/O caller is stored in this Smart Pointer and a reference can be obtained via the TwinCAT object server. In addition, the Smart Pointer class already contains a list item. Therefore the Smart Pointer can be used as the first parameter for the AddIoDriver method.

The following code sample illustrates the login of the ITcIoCyclicCaller interface.

HRESULT hr = S_OK;
if ( m_spIoCyclicCaller.HasOID() )
{
if ( SUCCEEDED_DBG(hr = m_spSrv->TcQuerySmartObjectInterface(m_spIoCyclicCaller))
)
{
if ( FAILED(hr = m_spIoCyclicCaller->AddIoDriver(m_spIoCyclicCaller,
THIS_CAST(ITcIoCyclic))) )
{
m_spIoCyclicCaller = NULL;
}
}
}