Domanda

I am trying to create an opc client which connects to ofs opc server.

The code for client is below.

This code successfully creates a group in the server but fails to create any items and gives no error.

    hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_IUnknown, (LPVOID*)&pUnkn);

    if(SUCCEEDED(hr))
    {
        hr = pUnkn->QueryInterface(IID_IOPCServer, (LPVOID*)&m_pOpcServer);
        hr = pUnkn->QueryInterface(IID_IOPCBrowseServerAddressSpace,       (LPVOID*)&m_pOpcBrowse);   
        hr = m_pOpcServer->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);

        OPCHANDLE hClientGroup = 0;
        DWORD dwUpdateRate = 0;
        hr = m_pOpcServer->AddGroup(L"Group1", true, dwUpdateRate, hClientGroup, 0,0, 0, &hClientGroup, &dwUpdateRate, IID_IOPCGroupStateMgt, (IUnknown**)&pInterface);


        OPCITEMDEF idef[1] = {{ /*szAccessPath*/ L"",
                                /*szItemID*/ ITEM_ID,
                                /*bActive*/ FALSE,
                                /*hClient*/ 1,
                                /*dwBlobSize*/ 0,
                                /*pBlob*/ NULL,
                                /*vtRequestedDataType*/ VT,
                                /*wReserved*/0
                             }};

        hr=0;
        hr = pInterface->QueryInterface(IID_IOPCItemMgt,  reinterpret_cast<LPVOID*>(&ptrItMgm));
        if(SUCCEEDED(hr))
        {
            hr = ptrItMgm->AddItems(1, idef, &pResults, &pErrors);
        }

'''

È stato utile?

Soluzione

Have you configured a symbol table file with alias information for your Schnider OPC Factory Server? If you try to add items which aren't configured on the server you will get errors (if your checking for them). If you're not checking for errors, you won't see anything happen. Make sure your alias definitions match the items your trying to add.

Altri suggerimenti

There are 3 ways to create the items in the OPC Server :

1.Using the Dll

2.Using the Data Logging

3.Using Programming in C#,VB.NET

Dll has to be used :(Use any one) 1.opcdaauto.dll 2.ClientAce from Kepware Technologies 3.Use dll which is provided by Hardware OPC vendor

Please provide the OPC Server Name .I will provide you the solution in detail.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top