⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u_public.pas

📁 OPC Client本软件是一个利用OPC协议通讯的实例。其中用到的驱动是非注册版
💻 PAS
字号:
unit U_Public;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls;

type
  FILETIME = Record
    dwLowDateTime:Integer;
    dwHighDateTime:Integer;
  end;

type
  PInteger = ^Integer;
  PBoolean = ^Boolean;
  PSingle = ^Single;
  PVariant = ^Variant;
  PFILETIME = ^FILETIME;
  PLongWord = ^LongWord;

type
  ItemInfo = Record
    Handle:Integer;
    Value:PVariant;
  end;
type
  KOC_Init = Function():Boolean;Stdcall;
  KOC_Uninit = Procedure();Stdcall;
  KOC_GetServerCount = Function(MachineName:String;Ver2:Boolean):Integer;Stdcall;
  KOC_GetServerCount_UseRegistry = Function(MachineName:Byte):Integer;Stdcall;
  KOC_GetServerName = Function(index:Integer;buf:PByte;BufSize:Smallint):Boolean;Stdcall;
  KOC_Connect = Function(MachineName:String;ServerName:String;Ver2:Boolean):Integer;Stdcall;
  KOC_Disconnect = Procedure(hConnect:Integer);Stdcall;
  KOC_AddGroup = Function(hConnect:Integer;Name:String;bActive:PBoolean;PRate:PInteger;PTimeBias:PInteger;PDeadBand:PSingle;DwLCID:PInteger):Integer;Stdcall;
  KOC_RemoveGroup = Procedure(hConnect:Integer;hGroup:Integer);Stdcall;
  KOC_GetItemCount = Function(hConnect:Integer):SmallInt;Stdcall;
  KOC_GetItemName = Function(hConnect:Integer;index:SmallInt;buf:PChar;BufSize:SmallInt):Boolean;Stdcall;
  KOC_AddItem = Function(hConnect:Integer;hGroup:Integer;ItemName:String):Integer;Stdcall;
  KOC_RemoveItem = Procedure(hConnect:Integer;hGroup:Integer;hItem:Integer);Stdcall;
  KOC_WriteItem = Function(hConnect:Integer;hGroup:Integer;hItem:Integer;PVar:Variant;DoAsync:Boolean):Integer;Stdcall;
  KOC_ReadItem = Function(hConnect:Integer;hGroup:Integer;hItem:Integer;PVar:PVariant;PTimeStamp:PFILETIME;PQuality:PLongWord):Boolean;Stdcall;
  KOC_Active = Procedure(regName:Byte;regCode:Byte);Stdcall;
  KOC_SetDataChangeProc = Function(hConnect:Integer;CallBack:Integer):Integer;Stdcall;
  KOC_SetShutdownProc = Function(hConnect:Integer;CallBack:Integer):Integer;Stdcall;

  var
    My_KOC_Init:KOC_Init;
    My_KOC_Uninit:KOC_Uninit;
    My_KOC_GetServerCount:KOC_GetServerCount;
    My_KOC_GetServerCount_UseRegistry:KOC_GetServerCount_UseRegistry;
    My_KOC_GetServerName:KOC_GetServerName;
    My_KOC_Connect:KOC_Connect;
    My_KOC_Disconnect:KOC_Disconnect;
    My_KOC_AddGroup:KOC_AddGroup;
    My_KOC_RemoveGroup:KOC_RemoveGroup;
    My_KOC_GetItemCount:KOC_GetItemCount;
    My_KOC_GetItemName:KOC_GetItemName;
    My_KOC_AddItem:KOC_AddItem;
    My_KOC_RemoveItem:KOC_RemoveItem;
    My_KOC_WriteItem:KOC_WriteItem;
    My_KOC_ReadItem:KOC_ReadItem;
    My_KOC_Active:KOC_Active;
    My_KOC_SetDataChangeProc:KOC_SetDataChangeProc;
    My_KOC_SetShutdownProc:KOC_SetShutdownProc;

    OPCServerHandle:Integer;     //OPC服务器连接句柄
    OPCGroupName:Integer;        //添加OPC组句柄

    My_ItemInfo:array of ItemInfo;
    ItemCount:Integer;

    My_Handle:Integer;
    My_CloaeThread:TThread;
  Procedure LoadFunction;
implementation

Procedure LoadFunction;
var
  i:Integer;
begin
  i:=LoadLibrary('KOCRDK.dll');    //导入OPC动态连接库
  if i<=0 then
  begin
      ShowMessage('未找到所需要的OPC动态链接库');
      PostQuitMessage(WM_QUIT);
  end;
  @My_KOC_Init:=GetProcAddress(i,'KOC_Init');
  @My_KOC_Uninit:=GetProcAddress(i,'KOC_Uninit');
  @My_KOC_GetServerCount:=GetProcAddress(i,'KOC_GetServerCount');
  @My_KOC_GetServerCount_UseRegistry:=GetProcAddress(i,'KOC_GetServerCount_UseRegistry');
  @My_KOC_GetServerName:=GetProcAddress(i,'KOC_GetServerName');
  @My_KOC_Connect:=GetProcAddress(i,'KOC_Connect');
  @My_KOC_Disconnect:=GetProcAddress(i,'KOC_Disconnect');
  @My_KOC_AddGroup:=GetProcAddress(i,'KOC_AddGroup');
  @My_KOC_RemoveGroup:=GetProcAddress(i,'KOC_RemoveGroup');
  @My_KOC_GetItemCount:=GetProcAddress(i,'KOC_GetItemCount');
  @My_KOC_GetItemName:=GetProcAddress(i,'KOC_GetItemName');
  @My_KOC_AddItem:=GetProcAddress(i,'KOC_AddItem');
  @My_KOC_RemoveItem:=GetProcAddress(i,'KOC_RemoveItem');
  @My_KOC_WriteItem:=GetProcAddress(i,'KOC_WriteItem');
  @My_KOC_ReadItem:=GetProcAddress(i,'KOC_ReadItem');
  @My_KOC_Active:=GetProcAddress(i,'KOC_Active');
  @My_KOC_SetDataChangeProc:=GetProcAddress(i,'KOC_SetDataChangeProc');
  @My_KOC_SetShutdownProc:=GetProcAddress(i,'KOC_SetShutdownProc');
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -