- Posts: 11
- Thank you received: 0
Online Forums
Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.
Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.
Do not use the Contact page for technical issues.
connect the c++ to quickopc
- TONY CHIAM
- Offline
- Premium Member
*******************************************************************
#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'
Please Log in or Create an account to join the conversation.
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.
- TONY CHIAM
- Offline
- Premium Member
- Posts: 11
- Thank you received: 0
// $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;
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
- TONY CHIAM
- Offline
- Premium Member
- Posts: 11
- Thank you received: 0
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.
Please Log in or Create an account to join the conversation.
- TONY CHIAM
- Offline
- Premium Member
- Posts: 11
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- 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.
- TONY CHIAM
- Offline
- Premium Member
- Posts: 11
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- TONY CHIAM
- Offline
- Premium Member
- Posts: 11
- Thank you received: 0
Please Log in or Create an account to join the conversation.