📄 opc.~pas
字号:
unit opc;
interface
uses ShareMem, Windows, OPCDA;
const MaxTagCount=32;
type
WRITENOTIFYPROC = procedure(handle: THandle; pNewValue: PVARIANT;pDeviceError: PDWORD); stdcall;
DISCONNECTPROC = procedure(Numbr: DWORD); stdcall;
TTag = record
TagID : string;
TagHandle : THandle;
TagType : TVarType;
Value : OleVariant;
Quality: WORD;
TagFt: _FileTime;
Active : boolean;
lvIndex: integer;
end;
TTags = array[0..65535] of TTag;
PTags = ^TTags;
function InitOPCSvr(pCLSID_Svr: LPCSTR; ServerRate: UINT): BOOL; stdcall;external 'opcdll.dll';
procedure UninitOPCSvr; stdcall;external 'opcdll.dll';
function RegServer(pCLSID_Svr: LPCSTR; Name: LPCSTR; Descr: LPCSTR;
ExePath: LPCSTR): BOOL; stdcall;external 'opcdll.dll';
function UnregServer(pCLSID_Svr: LPCSTR; Name: LPCSTR): BOOL; stdcall;external 'opcdll.dll';
function RunSvr: BOOL; stdcall; external 'opcdll.dll';
function CreateTag (Name: LPCSTR; Value: VARIANT; InitialQuality: WORD;
IsWriteable: BOOL): THandle;stdcall; external 'opcdll.dll';
function SetTagProperties(TagHandle: THandle; PropertyID: DWORD;
Description: LPCSTR; Value: VARIANT): BOOL; stdcall;external 'opcdll.dll';
function UpdateTagWithTimeStamp(TagHandle: THandle; Value: VARIANT;
Quality: WORD; timestamp: FILETIME): BOOL; stdcall;external 'opcdll.dll';
function UpdateTag(TagHandle: THandle; Value: VARIANT;
Quality: WORD): BOOL; stdcall;external 'opcdll.dll';
function UpdateTagByName(Name : LPCSTR; Value: VARIANT; Quality: WORD): BOOL; stdcall;external 'opcdll.dll';
function EnableWriteNotification(lpCallback: WRITENOTIFYPROC): BOOL; stdcall;external 'opcdll.dll';
procedure WriteTag(Handle: THandle; pNewValue: PVARIANT;pDeviceError: PDWORD); stdcall;
function EnableDisconnectNotification(lpCallback: DISCONNECTPROC): BOOL; stdcall;external 'opcdll.dll';
procedure SetServerState(SvrState: OPCSERVERSTATE); stdcall;external 'opcdll.dll';
var
tCount : integer=-1;
ppTags : array[0..MaxTagCount-1] of TTag;
SvrNum : Integer=0;
SvrClsID : string= '{87A8CF77-32A4-44B0-B8ED-147B176C96F4}';
SvrName : string='DPDEMO.OPCTOOLKIT.1';
SvrDesc : string='OPC Server By Delphi';
SvrPath : string;
ScanRate: integer=2000;
implementation
procedure WriteTag(Handle: THandle; pNewValue: PVARIANT;pDeviceError: PDWORD); stdcall;
var
i : integer;
ft: TFileTime;
st : TSystemTime;
begin
pDeviceError^ := 1;
for i:=0 to tCount do
begin
if ppTags[i].TagHandle = Handle then
begin
ppTags[i].Value:=pNewValue^;
pDeviceError^ := 0;
GetSystemTime(st);
SystemTimeToFileTime(st,ft);
UpdateTagWithTimeStamp(Handle,pNewValue^,192,ft);
Break;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -