unit ulmaglob;
interface
uses
  Classes, Forms,{v0.31} SysUtils,{/v0.31}
  WinUtl,
  LogType, Logu, {v0.19} PortLog,{/v0.19}
  ConfType, Confu,
  ULDrvTyp, ULDriver, DrvLogu,
  ul_lcabs, ModuType, Modulu{v0.14}, Channelsu, ExtDevIntu{/v0.14}
  {v0.23}, UlanGlob{/v0.23}{v0.24},AAAu{/v0.24}{v0.25},ExeLogu{/v0.25};

const
{ini.lst}
  UVDetAddr:longint = 3;
    { ulan device address of UV detector }
  UVDetSII:PScanInputInfo = nil;
    { handle for receiving data from UV detector }
{/ini.lst}
  IsInTimer:boolean = false;
    { recursion preventer for ulMDoTimer event }


function ulMInit(InitRcv:boolean):boolean;
  { ulMaster initialization, called from ulMaster main window create,
    opens ini file, opens log files }

function ulMDoTimer:boolean;
  { timer triggered method }

function ulMDone:boolean;
  { ulMaster deinitialization, called from ulMaster main window destroy,
    closes log files, ini file }

implementation

{const
  GlobalVars: PVarRecordArray = nil;}

function ulMInit(InitRcv:boolean):boolean;
begin
{  GetMem(GlobalVars, sizeof(TVarRecordArray) * MaxVarsCount);
  ConfigSetGlobals(GlobalVars, MaxVarsCount); ulanglob}
  LogRegister;
  ConfigInit(Application.ExeName);
  {v0.23}
  UlanConfigReadWrite(rwRead);
  {/v0.23}
  {v0.24}{/v0.24 SysLogInit;}
  DrvLogInit;
  {v0.14}
  ExtDevs := TExtDevs.Create;
  Modules := TModules.Create;
  Channels := TChannels.Create;
  {/v0.14}
  if InitRcv then
    RcvInit(UVDetSII, {v0.31}IntToStr(UVDetAddr){/v0.31 UVDetAddr});
  {v0.19}
  PortLogInit;
  {/v0.19}
  ulMInit := true;
end;


function ulMDoTimer:boolean;
begin
  ulMDoTimer := false;
  if IsInTimer then begin
    {v0.25}
    ExeLog.Log('ulmaglob.ulMDoTimer tried to call recursively');
    {/v0.25}
    exit;
  end;
  try
    IsInTimer := true;
    if Modules <> nil then begin
      Modules.DoTimer;
    end;
    RcvRun(UVDetSII);
    ulMDoTimer := true;
  finally
    IsInTimer := false;
  end;
end;

function ulMDone:boolean;
begin
  {v0.24}
  AAAFree;
  {/v0.24}
  {v0.23}
  UlanConfigReadWrite(rwWrite);
  {/v0.23}
  ConfigDone;
  RcvDone(UVDetSII);
  {v0.14}
  ClassFree(Channels);
  {/v0.14}
  ClassFree(Modules);
  {v0.14}
  ClassFree(ExtDevs);
  {/v0.14}
  {v0.19}
  PortLogDone;
  {/v0.19}
  DrvLogDone;
  {v0.24}{/v0.24 SysLogDone;}
  ulMDone := true;
end;

end.
