next up previous contents
Next: Building OPC XML-DA Clients Up: Client Functionality Previous: Client Functionality   Contents

Building OPC XML-DA Clients with the PyOPC XDAClient class

Listing 7 shows example code of a PyOPC XDAClient-based client12that first retrieves the server status, browses the root item and reads an item:

language=C
\begin{lstlisting}[caption={Sample client code based on the PyOPC XDAClient
mod...
...er(ItemName='simple_item',
MaxAge=500)],
LocaleID='en-us'))
\end{lstlisting}

Line 1 and 2 import the needed PyOPC modules. In Line 4 a simple function is defined that prints a list of ItemContainer objects (ilist) and the global options Python dictionary (Options).

In line 9, the client object is created: As global options, the server address is specified and ReturnErrorText = True denotes that the client requests verbose error descriptions.

Lines 12, 13 and 14 show the three different OPC operations. The return parameters of these operations are a list of ItemContainer objects and the global options (a Python dictionary), which are both handled by the function print_options.



Hermann Himmelbauer 2006-11-07