From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

write OPC client with LabWindows/CVI

I'm working on a project that requires communicating with Unidrive through OPC Server. I'm programming with LabWindows/CVI.

I cannot make those function calls work that require SAFEARRAY parameter to be passed in. For example, IOPCGroupAsyncRead( )...

Want to know if anybody has done the same thing successfully. I need your help. Thanks.

0 Kudos
Message 1 of 17
(4,380 Views)

Hi Marg SZ,

 

What version of  LabWindows/CVI are you using? Are you seeing any specific errors when trying to use the function calls? 

 

Perry S.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 17
(4,360 Views)

Hi Perry,

 

I'm using LabWindows/CVI 6.0. There is no error messages. I can only read/write item successfully because they do not require SAFEARRAY parameters.

I would appreciate if you can help.

 

Margaret

0 Kudos
Message 3 of 17
(4,355 Views)

Hi Margaret,

 

How are you creating the safe arrays? Is your array 1D or 2D? Are you using the conversion functions in LabWindows/CVI?

 

Regards,

 

Perry S.

Applications Engineer
National Instruments
0 Kudos
Message 4 of 17
(4,336 Views)

My code is as follows. Some of the variables are global. Thanks.

 

void GroupAsyncRead(void)
{
   OPCAutomationObj_OPCItems ppItems;
   OPCAutomationObj_OPCItem  ppItem;
   long numItems, hvalue, i;
   SAFEARRAY *serverHandles, *errors;  SAFEARRAYBOUND rgsabound[1];

   OPCAutomation_IOPCGroupGetOPCItems(OPCGroupHandle, &Error_Info, &ppItems);  
   OPCAutomation_OPCItemsGetCount(ppItems, &Error_Info, &numItems);
   rgsabound[0].lLbound = 0;
   rgsabound[0].cElements = numItems;

   serverHandles = SafeArrayCreate(VT_I8, 1, rgsabound);
   for(i=0; i < numItems; i++)
   {
      OPCAutomation_OPCItemsItem(ppItems, &Error_Info, CA_VariantInt(i+1), &ppItem);
      OPCAutomation_OPCItemGetServerHandle(ppItem, &Error_Info, &hvalue);
      SafeArrayPutElement(serverHandles, &i, &hvalue);
   }
   OPCAutomation_IOPCGroupAsyncRead(OPCGroupHandle, &Error_Info, numItems, &serverHandles,
                                                  errors, GetTransactionID(), &cancelID);
   asyncReadInProgress = 1;
   OPCAutomation_DIOPCGroupEventRegOnAsyncReadComplete(OPCServerHandle, ProcessGroupAsyncReadComplete, NULL, 1, NULL);
   SafeArrayDestroy(serverHandles);
   SafeArrayDestroy(errors);
}

0 Kudos
Message 5 of 17
(4,333 Views)

Sorry, I pasted it wrongly in the previous post. "errors" is passed by reference as follows.


   OPCAutomation_IOPCGroupAsyncRead(OPCGroupHandle, &Error_Info, numItems, &serverHandles,
                                                  &errors, GetTransactionID(), &cancelID);

0 Kudos
Message 6 of 17
(4,330 Views)

Hi Margaret,

 

I think that you are using the wrong functions to create your safe arrays. Please use the functions that are located in the ActiveX Library, Array section. 

 

Perry S.

Applications Engineer
National Instruments
0 Kudos
Message 7 of 17
(4,323 Views)

Hi Margaret,

 

Where did you get the functions that you are using to create the safearrays? Which CVI library?

 

Perry S.

Applications Engineer
National Instruments
0 Kudos
Message 8 of 17
(4,311 Views)

Perry,

 

Those are functions of Windows SDK. I haven't tried your suggestion on using ActiveX Array functions.

Thank you for following on this.

 

Margaret

0 Kudos
Message 9 of 17
(4,309 Views)

Hi Margaret,

 

Let me know how it works when you try it.

 

Perry S.

Applications Engineer
National Instruments
0 Kudos
Message 10 of 17
(4,299 Views)