5,386
社区成员
发帖
与我相关
我的任务
分享
var
Group:OPCGroup;
testItem:OPCItem;
OPCItems:string;
OPCItemsValues:string;
OPCServer1.Connect1('OPC服务名称(Intellution.OPCiFIX.1)','结点名称(OPC主机名称)');//连接OPC服务器
OPCServer1.OPCGroups.DefaultGroupUpdateRate:=500;//设置更新频率
Group:=OPCServer1.OPCGroups.Add('MyGroup'); //添加Group
testItem:=Group.OPCItems.AddItem('SCADA.YPA1_SILO_CHARGEWEIGHTACT.F_CV',1);//添加OPC数据项
var
myvalue,myquality,mytimestamp:OleVariant;
testItem.Read(OPCDevice,myvalue,myquality,mytimestamp);
Edit1.Text:=myvalue;
var
myvalue:OleVariant;
testItem.Write(myvalue);
OPCServer1.OPCGroups.RemoveAll;
OPCServer1.Disconnect;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OPCSiemensDAAutomation_TLB, OleServer;
type
TForm1 = class(TForm)
OPCGroup1: TOPCGroup;
OPCGroups1: TOPCGroups;
OPCServer1: TOPCServer;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Group:OPCGroup;
testItem:OPCItem;
OPCItems:string;
OPCItemsValues:string;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
//连接OPC
OPCServer1.Connect1('Intellution.OPCiFIX.1','OPSServer01');
OPCServer1.OPCGroups.DefaultGroupUpdateRate:=500;
Group:=OPCServer1.OPCGroups.Add('MyGroup');
testItem:=Group.OPCItems.AddItem('SCADA.YPA1_SILO_CHARGEWEIGHTACT.F_CV',1);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
//断开OPC
OPCServer1.OPCGroups.RemoveAll;
OPCServer1.Disconnect;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
myvalue,myquality,mytimestamp:OleVariant;
begin
//读OPC数据项
testItem.Read(OPCDevice,myvalue,myquality,mytimestamp);
Edit1.Text:=myvalue;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
myvalue:OleVariant;
begin
//写OPC数据项
testItem.Write(myvalue);
end;
end.