
Version 1.14 of the prOpcKit includes a unit which implements a very easy to use OPC client, which I call the 'Very Simple Client'. This page describes its use.
The very simple client is appropriate in the common situation when you know the name of the server to which you want to connect, and you know the names of the tags that you wish to access. This is typical of many practical applications. Generic clients, which can browse for servers and tags are great as tools, but are not particularly useful as control applications.
We need to add the unit prOpcVSC to the 'uses' clause of unit in which we intend to use the client.
|
It is also necessary to declare a variable to in which to store the client. This can be of type Variant or IOpcClient. We will use a Variant which makes the client a bit easier to use.
|
The client must be initialised before it can be used. To do this, use the function 'OpcClient' exported by prOpcVSC.
|
The first parameter is the name of the computer on which the server runs; we can pass a null string to indicate the local machine. The second parameter is the 'ProgId' of the server. There is a third, optional, parameter which indicates the rate at which you want the data polled on the server, and hence the maximum rate at which updates will be sent to the client. You can omit this parameter if you don't want updates sent from the server; which is fine if you don't mind making a round trip to the server every time you want to read a tag.
The 'Wizzy1.TWizzyServer.1' exports two tags - FormWidth and FormHeight - representing the size of the server's main form. For the source code to this server see 'An Introduction to the Opc Server Wizard'.
We will use our client application to adjust the size of the server's main form, using four buttons, arranged like this.

To increase the width of the server form by 20 pixels (demonstrating both a syncnronous read and a synchronous write) we can write.
|
When you are using a Variant to store your client connection, you can read or write to any tag on the server by using the notation ClientConnection.TagName, where ClientConnection is the initialised variant and TagName is the actual name of the tag on the server. This only works if the TagNames are valid pascal identifiers; if this is not the case then you should declare your ClientConnection as IOpcClient and access the tags using the properties of that interface.
'On click' handlers for the remaining buttons are similar. The finished unit is as follows.
|
If you want the source code to this example, it is included in the prOpcKit evaluation download.
Return to prOpcKit
Return to PREL Home