{ Общий предок контроллеров уровня 1. Доп. управление состоянием и кодами ошибок объектов } {--------------------------------------------------------------------------- The control units for mass-spectrometer MI1201-AGM (c) Copyright Aleksandrov O.E., 1998 Модуль управления масс-спектрометром МИ1201-АГМ (c) Собственность Александрова О.Е., 1998 Molecular Physics department 620002, Екатеринбург, К-2 USTU, Ekaterinsburg, K-2, 620002 УГТУ, RUSSIA Кафедра молекулярной физики phone 75-48-39 тел. 75-48-39 E-mail: aleks@dpt.ustu.ru ----------------------------------------------------------------------------} Unit c_Ctrl1; INTERFACE USES MiTypes, MiscFunc, c_Ctrl; type tData=record xStartTime:longint; xTimeOut:word; end; tTmpData=record StartTime:longint; TimeOut:word; TimeInterval:tTimeInterval; end; tCtrl=object(c_Ctrl.tCtrl) function Name:tName; virtual; constructor Init; { Сохранение/восстановление состояния контроллера } function DataSize:word; // procedure Save(var DataPtr:pointer); // procedure exRestore(var DataPtr:pointer); function Restore(var DataPtr:pointer):boolean; function Save(var DataPtr:pointer):boolean; { Время ожидания события на шине } procedure TimeOut(x:word); function CurTimeOut:word; procedure MarkTime; function TimeSinceMark:word; function StartTime:tTiks; function IntelliTimeOut(Time, MinTime:tTiks):tTiks; procedure xMarkTime(var t:tTiks); function xTimeSinceMark(t:tTiks):tTiks; function xIntelliTimeOut(Time:tTiks; DTime, MinDTime:tTiks):tTiks; { Установка/чтение времени выполнения операции (только для многопротокового выполнения)} function OperationTimeSet(ATime:tTiks):tTiks; function OperationTime:tTiks; function OperationTimeInc(ATime:tTiks):tTiks; function OperationTimeDec(ATime:tTiks):tTiks; procedure OperationTimeReset(ATime:tTiks); procedure SetErrorCode(ErrCode:tErrorCode); private prData:tData; prTmpData:tTmpData; end; IMPLEMENTATION USES {$IfNDef Seg16} MMSystem, Windows, {$EndIF} DataSave; constructor tCtrl.Init; begin Inherited Init; MarkTime; prTmpData.TimeInterval.Start(0); TimeOut(1000); end; function tCtrl.OperationTime:tTiks; begin OperationTime:=prTmpData.TimeInterval.TimeLeft+CurTimeOut; end; function tCtrl.OperationTimeSet(ATime:tTiks):tTiks; begin prTmpData.TimeInterval.Increment(ATime); OperationTimeSet:=prTmpData.TimeInterval.TimeLeft; end; function tCtrl.OperationTimeInc(ATime:tTiks):tTiks; begin prTmpData.TimeInterval.Increment(ATime); OperationTimeInc:=prTmpData.TimeInterval.TimeLeft; end; function tCtrl.OperationTimeDec(ATime:tTiks):tTiks; begin prTmpData.TimeInterval.Decrement(ATime); OperationTimeDec:=prTmpData.TimeInterval.TimeLeft; end; procedure tCtrl.OperationTimeReset(ATime:tTiks); begin prTmpData.TimeInterval.Start(ATime); end; procedure tCtrl.SetErrorCode(ErrCode:tErrorCode); begin Inherited SetErrorCode(ErrCode); OperationTimeReset(0); end; function tCtrl.Name; begin Name:='Ctrl1'; end; (*procedure tCtrl.exRestore; begin Inherited exRestore(DataPtr); RestoreData(DataPtr, prData, SizeOf(prData)); end;*) (*procedure tCtrl.Save; begin Inherited Save(DataPtr); StoreData(DataPtr, prData, SizeOf(prData)); end;*) function tCtrl.Restore(var DataPtr:pointer):boolean; begin if Inherited Restore(DataPtr) then Restore:=RestoreDataEx(DataPtr, prData, SizeOf(prData)) else Restore:=FALSE; end; function tCtrl.Save(var DataPtr:pointer):boolean; begin if Inherited Save(DataPtr) then Save:=StoreDataEx(DataPtr, prData, SizeOf(prData)) else Save:=FALSE; end; function tCtrl.DataSize:word; begin DataSize:=Inherited DataSize + DataSave.SizeOfData(SizeOf(prData)); end; function tCtrl.TimeSinceMark:word; begin TimeSinceMark:=xTimeSinceMark(prTmpData.StartTime); end; function tCtrl.IntelliTimeOut(Time, MinTime:tTiks):tTiks; begin IntelliTimeOut:=xIntelliTimeOut(prTmpData.StartTime, Time, MinTime); end; procedure tCtrl.MarkTime; begin // prTmpData.StartTime:=GetTickCount; prTmpData.StartTime:=timeGetTime; end; procedure tCtrl.xMarkTime(var t:tTiks); begin // t:=GetTickCount; t:=timeGetTime; end; function tCtrl.xTimeSinceMark(t:tTiks):tTiks; begin // t:=TimeSpentTicks(t); t:=TimeSpentTime(t); if ABS(t)>High(word) then xTimeSinceMark:=High(word) else xTimeSinceMark:=Abs(t); end; function tCtrl.xIntelliTimeOut(Time:tTiks; DTime, MinDTime:tTiks):tTiks; var x:tTiks; begin x:=xTimeSinceMark(Time); if DTime