[Company Logo Image]

Home AR4 Palletiser OPC Programming Wintek32 Delphi Downloads

The Opc Server Wizard

How to create a Working server in 4 really easy steps and 1 slightly more demanding step


This page demonstrates the Opc Server Wizard which is part of the prOpcKit for OPC server and client programming using Borland Delphi. The source code to this example is included in the prOpcKit evaluation download.

Step 1: Create a new project

Start off with an empty project. Save the project as Wizzy1.dpr and Unit1.pas as MainUnit.pas. Rename Form1 to 'MainForm'.

Step 2: Open the Opc Server Wizard

Select New | Other from the 'File' Menu. This opens the 'Object Repository'.

Select the OpcServer wizard and click OK.

Step 3: Fill in the Wizard Form

For this simple example, all we need do is fill in the Name, Description and Vendor fields. Click OK. This will generate a new unit called 'Unit1'. Save this unit as 'OpcServerUnit'. The resultant code is shown below.

unit OpcServerUnit;

interface

uses
  SysUtils, Classes, prOpcRttiServer, prOpcServer, prOpcTypes;

type
  TWizzyServer = class(TRttiItemServer)
  private
  protected
  public
  published
    {declare your Opc Items in here}
  end;

implementation
uses
  prOpcError;

const
  ServerGuid: TGUID = '{F1B1B47F-BC2C-4E88-A579-F24125855B9B}';
  ServerVersion = 1;
  ServerDesc = 'Simple but Wizzy Server';
  ServerVendor = 'Wizzy Vendor';

initialization
  RegisterOPCServer(ServerGUID, ServerVersion, ServerDesc, ServerVendor, TWizzyServer.Create)
end.

Step 4: Declare Tag Variables

The point of an Opc server is to publish named tags to Opc clients. To do this we declare our tags as published properties of the 'nameserver' object declared for us by the Opc Server Wizard. In this example we are going to publish the height and width of the main form as our tags. Declare two properties called 'FormHeight' and 'FormWidth' and implement them exactly as you would for any object properties. You can use the 'Code Completion' feature of the IDE to create the declarations and stubs of the property 'getter' and 'setter' procedures. This is the only step that actually involves any work.

unit OpcServerUnit;

interface

uses
  SysUtils, Classes, prOpcRttiServer, prOpcServer, prOpcTypes;

type
  TWizzyServer = class(TRttiItemServer)
  private
    function GetFormHeight: Integer;
    function GetFormWidth: Integer;
    procedure SetFormHeight(const Value: Integer);
    procedure SetFormWidth(const Value: Integer);
  protected
  public
  published
    {declare your Opc Items in here}
    property FormHeight: Integer read GetFormHeight write SetFormHeight;
    property FormWidth: Integer read GetFormWidth write SetFormWidth;
  end;

implementation
uses
  MainUnit, prOpcError;

const
  ServerGuid: TGUID = '{F1B1B47F-BC2C-4E88-A579-F24125855B9B}';
  ServerVersion = 1;
  ServerDesc = 'Simple but Wizzy Server';
  ServerVendor = 'Wizzy Vendor';

{ TWizzyServer }

function TWizzyServer.GetFormHeight: Integer;
begin
  Result:= MainForm.Height
end;

function TWizzyServer.GetFormWidth: Integer;
begin
  Result:= MainForm.Width
end;

procedure TWizzyServer.SetFormHeight(const Value: Integer);
begin
  MainForm.Height:= Value
end;

procedure TWizzyServer.SetFormWidth(const Value: Integer);
begin
  MainForm.Width:= Value
end;

initialization
  RegisterOPCServer(ServerGUID, ServerVersion, ServerDesc, ServerVendor, TWizzyServer.Create)
end.

In order to get this code to compile we need to add 'MainUnit' to the implementation uses clause. Compile the program. 'Wizzy1.TWizzyServer.1' is finished.

Step 5 Register and Test

Register the server, as you would with any COM server by running it with a command-line parameter of /regserver.

Open your favourite OpcClient to test the server. Mine is 'Visual Opc Tracer' from Terravic.

Connect to the Wizzy1.TWizzyServer.1 server on the local machine. Resize the main form of the server and notice that the values of FormHeight and FormWidth displayed in the client will update. Do a write to either of these variables and notice that the size of the Server's main form changes.

If you want the source code to this example, it is included in the prOpcKit evaluation download. For an explanation of how to build a simple client to connect to the server see Using the Very Simple Client.


Return to prOpcKit

Return to PREL Home