OPC DA

This section will show you how to create an OPC DA Client with 4DIAC and how to use it with FORTE. Download the following packages:

Prepare and compile OPC Client Toolkit

VS Properties VS Include Directories
void COPCClient::init() { HRESULT result = CoInitialize(NULL); if (FAILED(result)) { throw OPCException("CoInitialize failed"); } CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); result = CoGetMalloc(MEMCTX_TASK, &iMalloc); if (FAILED(result)) { throw OPCException("CoGetMalloc failed"); } }
to:
void COPCClient::init() { CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); HRESULT result = CoGetMalloc(MEMCTX_TASK, &iMalloc); if (FAILED(result)) { throw OPCException("CoGetMalloc failed"); } }

Compile FORTE with OPC DA Client Support

Create OPC Client

Start the 4DIAC-IDE and create a new System with a new Application for one Device. Add a CLIENT_1 Function Block to the Application, set the following input values, and map it to the hardware.

whereas the ID input has the following format:

opc[host:serverName:updateRate:deadBand:fbInputItems:fbOutputItems]

Change to the Deployment perspective, start Forte and download the Application. Switch the System into online mode and start watching the in- and outputs. For further information about Monitoring functionalities follow the link.

After triggering the INIT event, the OPC-client tries to connect with the OPC-server. In this example the OPC-server is "FestoDidactic.EzOPC.2". It is a tool from Festo and can be downloaded here.

4DIAC Trigger

When the connection is established, a window of the server pops up.

Festo OPC Server

Now trigger the REQ event to send the data from client to server. "BYTE#210" should be send to the server's port "VirtualPLC.EB0". Click to "Virtual Controller" tab to check if the OPC server has received the information.

Festo OPC Server IO