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.

Sample c++ code (subscribe, error handling, MFC)

More
11 Sep 2014 06:11 #2267 by support
I am sorry, we do not have such example; you will be on your own if you want to go this way.

In my view, however, if you have a MFC application, you can use the code we provided just well - that is, combine the code from the example with your existing MFC code. MFC and ATL are now considered a single library by Microsoft, and the reason we chose the "ATL" approach for our examples is because it works best (I am not sure if it can be done the "pure MFC" way).

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

More
11 Sep 2014 06:06 #2266 by support
From: OPC Labs Contact Form - R.
Sent: Thursday, September 11, 2014 2:10 AM
To: Zbynek Zahradnik
Subject: OPC Labs Contact Form - MFC Event handling

[...]
Please provide sample code that demonstrates how to set up asynchronous event messages using MFC. The sample code that I have seen up to this point is ATL based. It is slightly different in syntax from that of MFC. The sample code should have the following components:

1. Syntax for coding the message map

2. Syntax for initiating the asynchronous updates (advise method)

3. Syntax showing how to declare the class

4. Syntax showing how to declare the constructor

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

More
10 Sep 2014 08:20 - 10 Sep 2014 08:23 #2261 by support
Dear Sir,

I have created a project that demonstrates the proper error handling and OPC quality recognition in the event handler.

The project file (SubscribeErrorHandling.zip) is attached to this post, and the most important part of the code (the ItemChanged event handler with the exception handling) is listed here:
    // The handler for EasyDAClient.ItemChanged event
    STDMETHOD(ItemChanged)(VARIANT varSender, VARIANT varEventArgs)
    {
        _tprintf(_T("\n"));
 
        // Obtain the event arguments
        IEasyDAItemChangedEventArgsPtr EasyDAItemChangedEventArgsPtr(varEventArgs);
 
        // Display the item identification
        IDAItemDescriptorPtr DAItemDescriptorPtr(EasyDAItemChangedEventArgsPtr->ItemDescriptor);
        _tprintf(_T("Item ID: %s\n"), COLE2CT(_bstr_t(DAItemDescriptorPtr->ItemId)));
 
        // Test exception
        ICOMExceptionPtr ExceptionPtr(EasyDAItemChangedEventArgsPtr->Exception);
        if (ExceptionPtr != NULL)
        {
            _tprintf(_T("*** Error\n"));
 
            // Display the message and error code
            _tprintf(_T("Message: %s\n"), COLE2CT(_bstr_t(ExceptionPtr->Message)));
            _tprintf(_T("Error code: %d\n"), ExceptionPtr->ErrorCode);
 
            return S_OK;
        }
 
        // At this point, we know then there was no exception, and therefore the VTQ (value/timestamp/quality) will be present.
        IDAVtqPtr VtqPtr(EasyDAItemChangedEventArgsPtr->Vtq);
        _tprintf(_T("Timestamp: %s\n"), COleDateTime(VtqPtr->Timestamp).Format());
        _tprintf(_T("Quality: %d\n"), VtqPtr->Quality);
 
        // A valid VTQ may contain no value, e.g. when the OPC quality is Bad.
        if (!VtqPtr->HasValue())
        {
            _tprintf(_T("*** No value\n"));
            return S_OK;
        }
 
        // We can now access the value (as a VARIANT), in Vtq->Value. 
        // This example just formats and displays the value using a function provided on the DAVtq object.
        _tprintf(_T("Value: %s\n"), COLE2CT(_bstr_t(VtqPtr->DisplayValue())));
 
        return S_OK;
    }

I am not sure about the other parts of your question. Our events are not Windows messages, and my understanding is that therefore the MFC message maps cannot directly handle them.


Best regards
Attachments:
Last edit: 10 Sep 2014 08:23 by support.

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

More
10 Sep 2014 08:17 - 10 Sep 2014 08:18 #2260 by support
From: OPC Labs Contact Form - R.
Sent: Wednesday, September 10, 2014 4:24 AM
To: Zbynek Zahradnik
Subject: OPC Labs Contact Form - Sample c++ code

[...]
Subject:
Sample c++ code

Note
Sample MFC code for Advise(Subscribe) with event notification(MESSAGE_MAP).



Sample Advise callback function that uses Exception interface.(extract error codes)
Last edit: 10 Sep 2014 08:18 by support.

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

Moderators: support
Time to create page: 0.049 seconds