dOPC Client Toolkit
Close
Example

This example shows you how simple it is to connect to an OPC server with the dOPC Client Toolkit. It is based on our dOPC Simulation Server, but it's a trivial matter to change to any other OPC Server. You will find this example program also in our example programs, folder "verySimple". 

If you want to add a huge amount of OPC items to a OPC Group (TdOPCGroup) please look at the example program "BulkRead"

unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, dOPCDA, dOPCComn, dOPCIntf; type TForm1 = class(TForm) Memo1: TMemo; Panel1: TPanel; bStart: TButton; OPCClient: TdOPCDAClient; procedure OPCClientDatachange(Sender: TObject; ItemList: TdOPCItemList); procedure bStartClick(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.DFM} // connect to the OPC server procedure TForm1.bStartClick(Sender: TObject); var G : TdOPCGroup; begin OPCClient.Servername := 'dOPCSim.Kassl.Simulation'; // select your OPC Server G := OPCClient.OPCGroups.Add('testgroup'); // make your own new group G.OPCItems.AddItem('Random.String'); // add new OPC Item to group OPCClient.Active := true; // let's go end; // the OPC server sends OnDatachange events procedure TForm1.OPCClientDatachange(Sender: TObject; ItemList: TdOPCItemList); var i : integer; begin for i := 0 to Itemlist.Count-1 do // for all changed Items Memo1.Lines.Add(TimetoStr(Itemlist[i].TimeStamp)+': '+ Itemlist[i].ItemName +'->'+ Itemlist[i].ValueStr +' ('+ Itemlist[i].QualityAsString+')' ); // shows the changed OPC Item in the memo end; end.
Kassl GmbH Copyright © 2024. All rights reserved.