Creating an FB which likewise offers this functionality there as a simple proxy in the second PLC,
- 1. Create a PLC and append a new function block there.
- This proxy function block should provide the functionality which was programmed in the first PLC. It does this via an interface pointer of the type of the global interface I_Calculation.
- 2. In the declaration part of the function block declare as an output an interface pointer to the global interface which later provides the functionality outward.
- 3. In addition create the object ID and the interface ID as local member variables.
While the interface ID is already available via a global list, the object ID is assigned via a link in the process image. - 4. Implement the PLC proxy function block. First add the GetInterfacePointer() method to the function block.
The interface pointer is fetched to the specified interface of the specified TcCOM object with the help of the FW_ObjMgr_GetObjectInstance() function. This will only be executed if the object ID is valid and the interface pointer has not already been allocated. The object itself increments a reference counter. - 5. It is imperative to release the used reference again. To this end call the FW_SafeRelease() function in the FB_exit destructor of the function block.
- This completes the implementation of the Proxy function block.
- 6. Instantiate the Proxy function block FB_CalculationProxy in the application and call its method GetInterfacePointer() to get a valid interface pointer.
An instance of the proxy block is declared in the application to call the methods provided via the interface. The calls themselves take all place over the interface pointer defined as output of the function block. As is typical for pointers a prior null check must be made. Then the methods can be called directly, also via Intellisense.
- The sample is ready for testing.
Order irrelevant The sequence in which the two PLCs start later is irrelevant in this implementation. |