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
- OPCData-COM WriteMultipleItems
OPCData-COM WriteMultipleItems
I also don't see anything inherently wrong with the code line you have sent, so if the new example does not help you, please provide more details about where does the exceptino occur, what kind of exception it is, and also a broader piece of your code.
Please Log in or Create an account to join the conversation.
- bcook@c3i-usa.com
- Offline
- New Member
- Thank you received: 0
Please Log in or Create an account to join the conversation.
The correct code is below.
Some notes:
1. When certain argument that is supposed to be an array contains same value for all elements, it can be passed as a single value. I have used this simplification with MachineNames and ServerClasses arguments. It would of course be possible to turn them into arrays as well.
2. The code has been tested with our simulation server. The 4th item is invalid, on purpose, to show how the error handling works and can be coded.
3. In methods that have “Multiple” in their names, no OPC-related errors will cause the whole method to fail – all such failures are reported on item level, by element in the Results array. The try/catch around isn’t therefore needed, at least not for this purpose.
I understand that there are very few examples in C++ and that coding this in C++ isn’t easy; this is not specific to our component but applies in general. I have no problem providing the C++ examples “on demand” for specific user issues.
Here is the code:
<span style="font-family: "Courier New"; font-size: 10pt"> CComVariant vMachineNames(OLESTR(""));
<span style="font-family: "Courier New"; font-size: 10pt"> CComVariant vServerClasses(OLESTR("OPCLabs.KitServer.2"));
<span style="font-family: "Courier New"; font-size: 10pt">
<span style="font-family: "Courier New"; font-size: 10pt"> CComSafeArray saItemIds(4);
<span style="font-family: "Courier New"; font-size: 10pt"> saItemIds.SetAt(0, OLESTR("Simulation.Register_I4"));
<span style="font-family: "Courier New"; font-size: 10pt"> saItemIds.SetAt(1, OLESTR("Simulation.Register_R8"));
<span style="font-family: "Courier New"; font-size: 10pt"> saItemIds.SetAt(2, OLESTR("Simulation.Register_BSTR"));
<span style="font-family: "Courier New"; font-size: 10pt"> saItemIds.SetAt(3, OLESTR("UnknownItem"));
<span style="font-family: "Courier New"; font-size: 10pt"> CComVariant vItemIds(saItemIds);
<span style="font-family: "Courier New"; font-size: 10pt">
<span style="font-family: "Courier New"; font-size: 10pt"> CComSafeArray saValues(4);
<span style="font-family: "Courier New"; font-size: 10pt"> saValues.SetAt(0, CComVariant(23456));
<span style="font-family: "Courier New"; font-size: 10pt"> saValues.SetAt(1, CComVariant(2.34567890));
<span style="font-family: "Courier New"; font-size: 10pt"> saValues.SetAt(2, CComVariant(OLESTR("ABC")));
<span style="font-family: "Courier New"; font-size: 10pt"> saValues.SetAt(3, CComVariant(OLESTR("ABC")));
<span style="font-family: "Courier New"; font-size: 10pt"> CComVariant vValues(saValues);
<span style="font-family: "Courier New"; font-size: 10pt">
<span style="font-family: "Courier New"; font-size: 10pt"> CComSafeArray saResults;
<span style="font-family: "Courier New"; font-size: 10pt"> saResults.Attach(
<span style="font-family: "Courier New"; font-size: 10pt"> m_EasyDAClientPtr->WriteMultipleItemValues(vMachineNames, vServerClasses, vItemIds, vValues).parray);
<span style="font-family: "Courier New"; font-size: 10pt">
<span style="font-family: "Courier New"; font-size: 10pt"> for (int i = saResults.GetLowerBound(); i <= saResults.GetUpperBound(); i++)
<span style="font-family: "Courier New"; font-size: 10pt"> {
<span style="font-family: "Courier New"; font-size: 10pt"> IOperationResultPtr OperationResultPtr;
<span style="font-family: "Courier New"; font-size: 10pt"> saResults.pdispVal->QueryInterface(&OperationResultPtr);
<span style="font-family: "Courier New"; font-size: 10pt"> if (OperationResultPtr->Succeeded)
<span style="font-family: "Courier New"; font-size: 10pt"> {
<span style="font-family: "Courier New"; font-size: 10pt"> // Handle success here
<span style="font-family: "Courier New"; font-size: 10pt"> }
<span style="font-family: "Courier New"; font-size: 10pt"> else
<span style="font-family: "Courier New"; font-size: 10pt"> {
<span style="font-family: "Courier New"; font-size: 10pt"> ICOMExceptionPtr COMExceptionPtr = OperationResultPtr->Exception;
<span style="font-family: "Courier New"; font-size: 10pt"> // Handle failure here: you can use properties such as COMExceptionPtr->HResult, COMExceptionPtr->Message.
<span style="font-family: "Courier New"; font-size: 10pt"> }
<span style="font-family: "Courier New"; font-size: 10pt"> }
<span style="font-family: "Courier New"; font-size: 10pt">
Best regards,
Zbynek Zahradnik
Please Log in or Create an account to join the conversation.
Sent: Wednesday, May 18, 2011 4:10 PM
Subject: OPCData-COM WriteMultipleItems
Zbynek,
I have been working with a customer using OPCData-Com in VC++. He is trying to use the WriteMultipleItemValues. It only seems to write the first element of the array. I have reproduced his problem using the code he sent (attached) with our Top Server and some demo tags. We also looked at the diagnostics (attached) in the Top Server. It appears that the call is only sending one item. We have verified that it is not a problem with write access to the tag itself by switching the order of the tags- it still only writes to the first one.
Is this a bug, or are we missing something?
I have had a couple of requests from customer regarding proper use of the WriteMultipleItemValues method. Do you have an example of proper use of this is VC++ that you could send to me?
Thanks,
R.
Please Log in or Create an account to join the conversation.
- Forum
- Discussions
- QuickOPC-Classic in COM
- Reading, Writing, Subscriptions, Property Access
- OPCData-COM WriteMultipleItems