Professional OPC
Development Tools

logos

connect the c++ to quickopc

More
04 May 2017 13:36 - 04 May 2017 14:11 #5136 by TONY CHIAM
Hi, i already change back to libid and try to connect to the matrikonopc server for omron plc. When i put the server class and item id into my coding, it comes out some error and i dont know how to solve it. Sorry, i am the newbie for opc and c++. Thank.


*******************************************************************
#include "stdafx.h"
#include <atlsafe.h>
#include <comutil.h>
#include <Windows.h>
 
#import "libid:BED7F4EA-1A96-11D2-8F08-00A0C9A6186D"    // mscorlib
using namespace mscorlib;
 
// OpcLabs.BaseLib
#import "libid:ecf2e77d-3a90-4fb8-b0e2-f529f0cae9c9" \
	rename("value", "Value")
using namespace OpcLabs_BaseLib;
 
// OpcLabs.EasyOpcClassic
#import "libid:1F165598-2F77-41C8-A9F9-EAF00C943F9F" \
	rename("machineName", "MachineName") \
	rename("serverClass", "ServerClass")
using namespace OpcLabs_EasyOpcClassic;
 
int _tmain(int argc, _TCHAR* argv[])
{
    // Initialize the COM library. Note: If you choose STA, you will be responsible for pumping messages.
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
 
    // Instatiate the EasyOPC-DA client object
    _EasyDAClientPtr ClientPtr(__uuidof(EasyDAClient));
 
    _DAReadItemArgumentsPtr ReadItemArguments1Ptr(_uuidof(DAReadItemArguments));
    ReadItemArguments1Ptr->ServerDescriptor->ServerClass = L"Matrikon.OPC.OMRON.1";
	ReadItemArguments1Ptr->ItemDescriptor->ItemId = L"first/PLC1/#OfflineMode";
 
 
    CComSafeArray<VARIANT> ArgumentsArray(1);
    ArgumentsArray.SetAt(0, _variant_t((IDispatch*)ReadItemArguments1Ptr));
 
    LPSAFEARRAY pArgumentsArray = ArgumentsArray.Detach();
    CComSafeArray<VARIANT> ResultArray;
	ResultArray.Attach(ClientPtr->ReadMultipleItems(&pArgumentsArray));
    ArgumentsArray.Attach(pArgumentsArray);
 
    for (int i = ResultArray.GetLowerBound(0); i <= ResultArray.GetUpperBound(0); i++)
    {
        _DAVtqResultPtr DAVtqResultPtr(ResultArray[i]);
 
		_ExceptionPtr ExceptionPtr(DAVtqResultPtr->Exception);
		if (ExceptionPtr != NULL)
		{
	        _variant_t exceptionAsString(ExceptionPtr->ToString);
	        _tprintf(_T("results(%d).Exception.ToString(): %s\n"), i, exceptionAsString.bstrVal);
			continue;
		}
 
        _DAVtqPtr DAVtqPtr(DAVtqResultPtr->Vtq);
        _variant_t vtqAsString(DAVtqPtr->ToString);
        _tprintf(_T("results(%d).Vtq.ToString(): %s\n"), i, vtqAsString.bstrVal);
    }
 
    // Release all interface pointers BEFORE calling CoUninitialize()
    ResultArray.Destroy();
    ClientPtr = NULL;
 
    CoUninitialize();
 
    TCHAR line[80];
    _putts(_T("Press Enter to continue..."));
    _fgetts(line, sizeof(line), stdin);
    return 0;
}
*****************************************************************************************************
error C2039: 'ItemId' : is not a member of 'OpcLabs_EasyOpcClassic::_DAItemDescriptor'
1> c:\users\user\documents\visual studio 2010\projects\opctest3\opctest3\debug\opclabs.easyopcclassic.tlh(2350) : see declaration of 'OpcLabs_EasyOpcClassic::_DAItemDescriptor'
Last edit: 04 May 2017 14:11 by support.

Please Log in or Create an account to join the conversation.

More
04 May 2017 09:19 #5134 by support
Replied by support on topic connect the c++ to quickopc
I do not understand why you have replaced the #import-s with "libid:" with absolute file paths.

Use the #import-s precisely as in our example. If that gives a problem, tell me what the problem is.

Best regards

Please Log in or Create an account to join the conversation.

More
04 May 2017 07:44 - 04 May 2017 09:16 #5133 by TONY CHIAM
// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.
// ReadMultipleItems.cpp : Defines the entry point for the console application.
//
 
 
#include "stdafx.h"
#include <atlsafe.h>
#include <comutil.h>
#include <Windows.h>
 
// mscorlib
#import "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll"    
using namespace mscorlib;
 
 //OpcLabs.BaseLib
#import "C:\Program Files (x86)\OPC Labs QuickOPC 2016.2\Lib\OpcLabs.BaseLib.tlb" \
	rename("value", "Value")
using namespace OpcLabs_BaseLib;
 
// OpcLabs.EasyOpcClassic
#import "C:\Users\User\Documents\visual studio 2010\Projects\opctest3\OpcLabs.EasyOpcClassic.tlb" \
	rename("machineName", "MachineName") \
	rename("serverClass", "ServerClass")
using namespace OpcLabs_EasyOpcClassic;
 
 
int _tmain(int argc, _TCHAR* argv[])
{
    // Initialize the COM library. Note: If you choose STA, you will be responsible for pumping messages.
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
 
    // Instatiate the EasyOPC-DA client object
    _EasyDAClientPtr ClientPtr(__uuidof(EasyDAClient));
 
    _DAReadItemArgumentsPtr ReadItemArguments1Ptr(_uuidof(DAReadItemArguments));
    ReadItemArguments1Ptr->ServerDescriptor->ServerClass = L"Matrikon.OPC.OMRON.1";
    ReadItemArguments1Ptr->ItemDescriptor->ItemId = L"Test1/Test/P_MAX_CYCLE_TIME";
 
 
    CComSafeArray<VARIANT> ArgumentsArray(1);
    ArgumentsArray.SetAt(0, _variant_t((IDispatch*)ReadItemArguments1Ptr));
 
    LPSAFEARRAY pArgumentsArray = ArgumentsArray.Detach();
    CComSafeArray<VARIANT> ResultArray;
	ResultArray.Attach(ClientPtr->ReadMultipleItems(&pArgumentsArray));
    ArgumentsArray.Attach(pArgumentsArray);
 
    for (int i = ResultArray.GetLowerBound(0); i <= ResultArray.GetUpperBound(0); i++)
    {
        _DAVtqResultPtr DAVtqResultPtr(ResultArray[i]);
 
		_ExceptionPtr ExceptionPtr(DAVtqResultPtr->Exception);
		if (ExceptionPtr != NULL)
		{
	        _variant_t exceptionAsString(ExceptionPtr->ToString);
	        _tprintf(_T("results(%d).Exception.ToString(): %s\n"), i, exceptionAsString.bstrVal);
			continue;
		}
 
        _DAVtqPtr DAVtqPtr(DAVtqResultPtr->Vtq);
        _variant_t vtqAsString(DAVtqPtr->ToString);
        _tprintf(_T("results(%d).Vtq.ToString(): %s\n"), i, vtqAsString.bstrVal);
    }
 
    // Release all interface pointers BEFORE calling CoUninitialize()
    ResultArray.Destroy();
    ClientPtr = NULL;
 
    CoUninitialize();
 
    TCHAR line[80];
    _putts(_T("Press Enter to continue..."));
    _fgetts(line, sizeof(line), stdin);
    return 0;
}
Last edit: 04 May 2017 09:16 by support.

Please Log in or Create an account to join the conversation.

More
03 May 2017 20:19 #5131 by support
Replied by support on topic connect the c++ to quickopc
Please post your project (zipped) here.

Please Log in or Create an account to join the conversation.

More
03 May 2017 15:41 #5130 by TONY CHIAM
i import the mscorlib.dll into the programming and start debug, it come out the error -

fatal error C1083: Cannot open type library file: 'c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.6.1\mscorlib.dll': Error loading type library/DLL.

Thank for replying

Please Log in or Create an account to join the conversation.

More
03 May 2017 08:55 #5129 by support
Replied by support on topic connect the c++ to quickopc
Please describe the problem - the error message, and any other available details.

Please Log in or Create an account to join the conversation.

More
03 May 2017 06:08 #5128 by TONY CHIAM
when i copy the readmultipleitem file to a new file and try to debug, the import of the mscorlib have the problem. How i can solve the problem?? THANK

Please Log in or Create an account to join the conversation.

More
01 May 2017 07:26 #5123 by support
Replied by support on topic connect the c++ to quickopc
For information about the libraries that need to be referenced, see e.g.:

- opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...ame.html#COM%20Components.html
- opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...pment%20Libraries%20(COM).html
- opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...0the%20Components%20(COM).html
- opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...nts%20for%20OPC%20Classic.html

In C++, after having installed QuickOPC, you basically just need to add the #import directives to the code, as shown in the code samples.

For example, from EasyOPCDADemoDlg.h file in the EasyOPCDADemo project:

#import "libid:BED7F4EA-1A96-11D2-8F08-00A0C9A6186D"    // mscorlib
using namespace mscorlib;
 
#import "System.Drawing.tlb"
using namespace System_Drawing;
 
#import "System.Windows.Forms.tlb"
using namespace System_Windows_Forms;
 
// OpcLabs.BaseLib
#import "libid:ecf2e77d-3a90-4fb8-b0e2-f529f0cae9c9" \
	rename("value", "Value")
using namespace OpcLabs_BaseLib;
 
#import "libid:A0D7CA1E-7D8C-4D31-8ECB-84929E77E331"    // OpcLabs.BaseLibForms
using namespace OpcLabs_BaseLibForms;
 
// OpcLabs.EasyOpcClassic
#import "libid:1F165598-2F77-41C8-A9F9-EAF00C943F9F" \
	rename("machineName", "MachineName") \
	rename("serverClass", "ServerClass")
using namespace OpcLabs_EasyOpcClassic;
 
#import "libid:E15CAAE0-617E-49C6-BB42-B521F9DF3983"    // OpcLabs.EasyOpcUA
using namespace OpcLabs_EasyOpcUA;
 
#import "libid:2C654FA0-6CD6-496D-A64E-CE2D2925F388"    // OpcLabs.EasyOpcForms
using namespace OpcLabs_EasyOpcForms;

Regarding connection to your specific server, I suggest that you start by determining its ProgID and then an ItemID of some "tag" in the server, and modify our example(s) with this information.

Best regards

Please Log in or Create an account to join the conversation.

More
29 Apr 2017 17:11 #5121 by TONY CHIAM
i using the classic data access. What dll. or lib. should i add to the c++ in order to make it success. Besides, i need to do what process in the quickopc part?

Please Log in or Create an account to join the conversation.

More
29 Apr 2017 17:06 #5120 by TONY CHIAM
Hi, i doing a project related to connect the visual studio c++ with the CP1E Omron PLC. How do i using quickopc as client to connect the c++?

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.220 seconds

      

 Recommend this on Google