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.
- Forum
- Discussions
- QuickOPC-Classic in COM
- Reading, Writing, Subscriptions, Property Access
- QuickOPC install in Visual Studio 2010 C++. ReadMultipleItems example
QuickOPC install in Visual Studio 2010 C++. ReadMultipleItems example
Please Log in or Create an account to join the conversation.
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
Please Log in or Create an account to join the conversation.
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.
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.
Best regards
Please Log in or Create an account to join the conversation.
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.
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.
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.
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.
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.
- Forum
- Discussions
- QuickOPC-Classic in COM
- Reading, Writing, Subscriptions, Property Access
- QuickOPC install in Visual Studio 2010 C++. ReadMultipleItems example