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
(5,167 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
(5,147 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
(5,142 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
(5,123 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
(5,120 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
(5,117 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
(5,110 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
(5,098 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
(5,096 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
(5,086 Views)