Professional OPC
Development Tools

logos

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.

QuickOPC install in Visual Studio 2010 C++. ReadMultipleItems example

More
28 May 2014 06:31 #2006 by support
I do not see a product related question here, sorry.

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

More
27 May 2014 07:18 - 27 May 2014 07:22 #2003 by forestro
Hello,

I created an OPC class to acess OPC server which is used in another class. I don't use the main function and I would like to use a signal when there is an itemchanged event.

In attachments : OPC_Client.h (header file) and OPC_Client.cpp
Attachments:
Last edit: 27 May 2014 07:22 by forestro.

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

More
27 May 2014 06:28 #2001 by support
The example in C++ I referred to (www.opclabs.com/forum/com-reading-writing-subscriptions-prop...scribemultipleitems-in-vc#1996 ) does almost exactly the same thing as the C# example you listed, i.e. it subscribes to multiple OPC items, and prints out the values as they come in.

The other C++ example in this thread reads the values explicitly, and also prints them out.
If needed, the two examples can be combined together.

What precisely is it that you don't understand?

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

More
26 May 2014 13:32 #1999 by forestro
Hello,

Thanks you for this example but I need an example in c++ as C# example :

// This example shows how subscribe to changes of multiple items and display the value of the item with each change.
2
3using JetBrains.Annotations;
4using OpcLabs.EasyOpc.DataAccess;
5using System;
6using System.Threading;
7
8namespace DocExamples
9{
10 namespace _EasyDAClient
11 {
12 partial class SubscribeMultipleItems
13 {
14 public static void Main()
15 {
16 using (var easyDAClient = new EasyDAClient())
17 {
18 easyDAClient.ItemChanged += easyDAClient_ItemChanged;
19
20 easyDAClient.SubscribeMultipleItems(
21 new[] {
22 new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, null),
23 new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, null),
24 new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, null),
25 new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, null)
26 });
27
28 Console.WriteLine("Processing item changed events for 1 minute...");
29 Thread.Sleep(60 * 1000);
30 }
31 }
32
33 // Item changed event handler
34 static void easyDAClient_ItemChanged([NotNull] object sender, [NotNull] EasyDAItemChangedEventArgs e)
35 {
36 Console.WriteLine("{0}: {1}", e.ItemDescriptor.ItemId, e.Vtq);
37 }
38 }
39 }
40}

I created an OPC client class which use subscribe and read item. I would like to read item when it changes. I don't understand your example and how to add it in my class.

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

More
26 May 2014 08:47 #1997 by support

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

More
26 May 2014 08:36 #1995 by support
Hello.

Regarding instantiating the EasyDAClient in a file different from the declaration: Not sure what you mean - can you describe the problem in more detail?

Regarding "ReadItems" example: under the QuickOpcComCppExamples solution, there is Win32\ReadMultipleItems example. Its main part looks like this:

 
// 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>
 
#import "libid:FAB7A1E3-3B79-4292-9C3A-DF39A6F65EC1" version(5.2)	// EasyOpcLib
using namespace EasyOpcLib;
 
int _tmain(int argc, _TCHAR* argv[])
{
	// Initialize the COM library
	CoInitialize(NULL);
 
	// Instatiate the EasyOPC-DA client object
	IEasyDAClientPtr EasyDAClientPtr(__uuidof(EasyDAClient));
 
	CComSafeArray<BSTR> ItemIdArray(4);
	ItemIdArray[0] = _T("Simulation.Random");
	ItemIdArray[1] = _T("Trends.Ramp (1 min)");
	ItemIdArray[2] = _T("Trends.Sine (1 min)");
	ItemIdArray[3] = _T("Simulation.Register_I4");
 
	CComVariant vMissing;
	vMissing.vt = VT_ERROR;
 
	CComVariant vResults(EasyDAClientPtr->ReadMultipleItems(_T(""), _T("OPCLabs.KitServer.2"), 
		CComVariant(ItemIdArray.Detach()), vMissing));
 
	CComSafeArray<VARIANT> ResultArray(vResults.parray);
	for (int i = ResultArray.GetLowerBound(0); i <= ResultArray.GetUpperBound(0); i++)
	{
		IDAVtqResultPtr DAVtqResultPtr(ResultArray[i]);
		IDAVtqPtr DAVtqPtr(DAVtqResultPtr->Vtq);
		_tprintf(_T("results(%d).Vtq.ToString(): %s\n"), i, DAVtqPtr->ToString().bstrVal);
	}
 
	// Release all interface pointers BEFORE calling CoUninitialize()
	ResultArray.Destroy();
	vResults.Clear();
	EasyDAClientPtr = NULL;
 
	CoUninitialize();
 
	TCHAR line[80];
	_putts(_T("Press Enter to continue..."));
	_fgetts(line, sizeof(line), stdin);
	return 0;
}
 

An example with ItemChanged event: will be in a separate post.

Best regards

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

More
22 May 2014 08:57 #1988 by forestro
Hello,

I need an example of using of itemChanged event for one item in Visual Studio c++ COM project.

Thanks you.

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

More
21 May 2014 08:57 #1986 by forestro
Hello,

I referred to erros generated by IntelliSense. This problem is resolved.
I have a lot of problems to program with QuickOPC-COM. Do you have an example to Instatiate the EasyOPC-DA client object in a file different of the declaration. And examples with ReadItems, subsribeitem using std::string and an example with itemchanged event.

Thanks you.

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

More
19 May 2014 21:03 #1982 by support
Are you referring to errors generated by IntelliSense, or actual build errors?

If you are describing IntelliSense, the solution is: ignore them.
If you are dealing with build errors, can you do a Rebuild of our original project, and post a full content of the Output windows here?

Thank you.

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

More
19 May 2014 08:57 #1978 by forestro
Hello,

I have used the second possibility with the "COM Visual C++ Example (VS 2008).
I copied these sentences and paste in my header file :

#import "libid:FAB7A1E3-3B79-4292-9C3A-DF39A6F65EC1" version(5.2) exclude("_IEasyDAClientEvents") // EasyOpcDALib
#import "libid:965A3842-AEEA-4DF9-9241-28B963F76E24" version(5.2) // OPCUserObjects

using namespace EasyOpcLib;
using namespace OPCUserObjects;

There are the same error in my project and in your project : "impossible to open the source file".

Are there files to add in my project ?

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

Moderators: support
Time to create page: 0.067 seconds