unit Controller_Panel; //============================================================================= // Контроллер пульта управления (АК3) //============================================================================= interface uses Controllers; const cDataSignature='ControllPanel'; cBasePort=$ED00; cValidPorts=[$30..$33]; cValidReadPorts=cValidPorts; cValidWritePorts=cValidPorts; type tVEU=word; tValve=(vNone, vProba1, vProba2, vEtalon1, vEtalon2, vEtalon3, vEtalon4, vPumping); tValves=byte; tBlock=(bBPGI, b10kV, bVEU, bValveControl); tBlocks=set of tBlock; tData=record Valves :tValves; VEU :tVEU; Blocks :tBlocks; end; tCtrlPanel=class(tController) private Data :tData; procedure SetValves(b:byte); function GetValves:byte; procedure SetVEUHi(b:byte); procedure SetVEULo(b:byte); function GetVEUHi:byte; function GetVEULo:byte; procedure SetBlock(b:byte); function GetBlock:byte; public constructor Create; destructor Destroy; override; procedure Init; override; procedure OutB(b:byte; Port:word); override; function InB(Port:word):byte; override; function ValidPort(Port:word; BasePort:word):boolean; override; function ValidReadPort(Port:word):boolean; override; function ValidWritePort(Port:word):boolean; override; function DataSize:cardinal; override; function SetData(aData:Pointer):boolean; override; function GetData(aData:Pointer):boolean; override; function SubPath:string; override; function GetStateBlock:tBlocks; end; implementation uses Windows, Messages, Hardware; //***************************************************************************** // //***************************************************************************** //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- constructor TCtrlPanel.Create; begin inherited; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- destructor tCtrlPanel.Destroy; begin inherited; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tCtrlPanel.Init; begin Data.Valves:=0; Data.VEU:=0; Data.Blocks:=[]; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tCtrlPanel.OutB(b:byte; Port:word); begin case Port of $30:begin SetValves(b); end; $33:begin SetVEULo(b); end; $32:begin SetVEUHi(b); end; $31:begin SetBlock(b); end; end; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.InB(Port:word):byte; begin Result:=$FF; case Port of $30:begin Result:=GetValves; end; $33:begin Result:=GetVEULo; end; $32:begin Result:=GetVEUHi; end; $31:begin Result:=GetBlock; end; end; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.ValidPort(Port:word; BasePort:word):boolean; begin Result:=(Port in cValidPorts) and (BasePort=cBasePort); end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.ValidReadPort(Port:word):boolean; begin Result:=Port in cValidReadPorts; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.ValidWritePort(Port:word):boolean; begin Result:=Port in cValidWritePorts; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tCtrlPanel.SetValves(b:byte); var f:text; begin if b>7 then begin MessageBox(0,'SetValves','Panel',MB_OK); RunError(201); end; Data.Valves:=b; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.GetValves:byte; var f:text; begin Result:=Data.Valves; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tCtrlPanel.SetVEUHi(b:byte); begin Data.VEU:=(Data.VEU and $FF) or (b shl 8); MI1201AGM.SetVoltage(3,Data.VEU); end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tCtrlPanel.SetVEULo(b:byte); begin Data.VEU:=(Data.VEU and $FF00) or b; MI1201AGM.SetVoltage(3,Data.VEU); end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.GetVEUHi:byte; begin Result:=(Data.VEU and $FF00) shr 8; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.GetVEULo:byte; begin Result:=(Data.VEU and $FF); end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tCtrlPanel.SetBlock(b:byte); begin Data.Blocks:=tBlocks((not b) and $F); MI1201AGM.UpdateWarringSignal; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.GetBlock:byte; begin Result:=byte(Data.Blocks) and $F; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.GetStateBlock:tBlocks; begin Result:=Data.Blocks; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.DataSize:cardinal; begin Result:=SizeOf(Data); end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.SetData(aData:Pointer):boolean; begin Result:=false; try Move(aData^, Data, DataSize); Result:=True; except end; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.GetData(aData:Pointer):boolean; begin Result:=false; try Move(Data, aData^, DataSize); Result:=True; except end; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- function tCtrlPanel.SubPath:string; begin Result:=cDataSignature; end; //----------------------------------------------------------------------------- end.