unit Defset;
// ----------------------------------------
// Set default analogue and digital outputs
// ----------------------------------------
// 29.05.07 Updated

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, global, shared, ValidatedEdit ;

type
  TDefSetFrm = class(TForm)
    DACGroup: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    DIGGroup: TGroupBox;
    GroupBox2: TGroupBox;
    rbOn1: TRadioButton;
    rbOff1: TRadioButton;
    GroupBox5: TGroupBox;
    rbOn3: TRadioButton;
    rboff3: TRadioButton;
    GroupBox6: TGroupBox;
    rbon4: TRadioButton;
    rboff4: TRadioButton;
    GroupBox7: TGroupBox;
    rbon5: TRadioButton;
    rboff5: TRadioButton;
    GroupBox8: TGroupBox;
    rbon6: TRadioButton;
    rboff6: TRadioButton;
    GroupBox9: TGroupBox;
    rbon7: TRadioButton;
    rboff7: TRadioButton;
    GroupBox1: TGroupBox;
    rbOn2: TRadioButton;
    rbOff2: TRadioButton;
    Dig0: TGroupBox;
    rbOn0: TRadioButton;
    rbOff0: TRadioButton;
    Label3: TLabel;
    Label4: TLabel;
    bOK: TButton;
    bCancel: TButton;
    Label5: TLabel;
    Label6: TLabel;
    edVHold0: TValidatedEdit;
    edDivideFactor0: TValidatedEdit;
    edVHold1: TValidatedEdit;
    edDivideFactor1: TValidatedEdit;
    procedure bOKClick(Sender: TObject);
    procedure bCancelClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DefSetFrm: TDefSetFrm;

implementation

{$R *.DFM}

uses mdiform, maths ;

procedure TDefSetFrm.bOKClick(Sender: TObject);
var
   Value : Word ;
begin
     { Update default digital O/P settings }
     Value := 0 ;
     if rbOn0.checked then Value := Value or 1 ;
     if rbOn1.checked then Value := Value or 2 ;
     if rbOn2.checked then Value := Value or 4 ;
     if rbOn3.checked then Value := Value or 8 ;
     if rbOn4.checked then Value := Value or 16 ;
     if rbOn5.checked then Value := Value or 32 ;
     if rbOn6.checked then Value := Value or 64 ;
     if rbOn7.checked then Value := Value or 128 ;
     Settings.DigitalOutputs := Value ;

     Settings.VCommand[0].HoldingVoltage := edVHold0.Value ;
     Settings.VCommand[0].DivideFactor := edDivideFactor0.Value ;
     Settings.VCommand[1].HoldingVoltage := edVHold1.Value ;
     Settings.VCommand[1].DivideFactor := edDivideFactor1.Value ;

     Settings.UpdateOutputs := True ;
     close ;

     end;


procedure TDefSetFrm.bCancelClick(Sender: TObject);
begin
     close ;
     end;

procedure TDefSetFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
     Action := caFree ;
     end;

procedure TDefSetFrm.FormShow(Sender: TObject);
// --------------------------------------
// Initialisations when form is displayed
// --------------------------------------
var
   Bit : Word ;
begin

     { Get default digital O/P settings }
     Bit := Settings.DigitalOutputs and 1 ;
     if Bit <> 0 then rbOn0.checked := true
                 else rbOff0.checked := true ;
     Bit := Settings.DigitalOutputs and 2 ;
     if Bit <> 0 then rbOn1.checked := true
                 else rbOff1.checked := true  ;
     Bit := Settings.DigitalOutputs and 4 ;
     if Bit <> 0 then rbOn2.checked := true
                 else rbOff2.checked := true  ;
     Bit := Settings.DigitalOutputs and 8 ;
     if Bit <> 0 then rbOn3.checked := true
                 else rbOff3.checked := true  ;
     Bit := Settings.DigitalOutputs and 16 ;
     if Bit <> 0 then rbOn4.checked := true
                 else rbOff4.checked := true  ;
     Bit := Settings.DigitalOutputs and 32 ;
     if Bit <> 0 then rbOn5.checked := true
                 else rbOff5.checked := true  ;
     Bit := Settings.DigitalOutputs and 64 ;
     if Bit <> 0 then rbOn6.checked := true
                 else rbOff6.checked := true  ;
     Bit := Settings.DigitalOutputs and 128 ;
     if Bit <> 0 then rbOn7.checked := true
                 else rbOff7.checked := true  ;
     { Get voltage settings }
     edVHold0.Value := Settings.VCommand[0].HoldingVoltage ;
     edDivideFactor0.Value := Settings.VCommand[0].DivideFactor ;
     edVHold1.Value := Settings.VCommand[1].HoldingVoltage ;
     edDivideFactor1.Value := Settings.VCommand[1].DivideFactor ;

     end;


end.
