unit Analog_Output;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    cbxSelBoard: TComboBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    cbxChannel: TComboBox;
    cbxAORange: TComboBox;
    eValue: TEdit;
    btnOutput: TButton;
    btnExit: TButton;
    procedure cbxSelecBoardChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnExitClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnOutputClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses UniDAQ;
{$R *.DFM}
var
   wTotalBoards,wRtn,wBoardNo,wChannel,wCfgCode:Word;
   sCardInfo:Array [0..31] of IXUD_CARD_INFO;
   sDevInfo:Array [0..31] of IXUD_DEVICE_INFO;
   sSelCardInfo:IXUD_CARD_INFO;
   sSelDevInfo:IXUD_DEVICE_INFO;
   szModelName: Array [0..19] of char;
   fAOValue:Single ;

procedure TForm1.cbxSelecBoardChange(Sender: TObject);
var
   wChannelIndex:Word;
begin

       sSelDevInfo := sDevInfo[cbxSelBoard.ItemIndex];
       sSelCardInfo :=sCardInfo[cbxSelBoard.ItemIndex];
       cbxChannel.Items.Clear();

       //Get AO Channel Numbers
       if (sSelCardInfo.wAOChannels)>0 then
       begin
            for wChannelIndex:=0 to sSelCardInfo.wAOChannels -1 do
                cbxChannel.Items.Add('Channel'+' '+IntToStr(wChannelIndex));

            cbxChannel.ItemIndex := 0;
       end
       else
       begin
           cbxChannel.Items.Add('None Output Port');
           cbxChannel.Enabled := FALSE;
       end;

end;
procedure TForm1.FormCreate(Sender: TObject);
var
   wBoardIndex:WORD;
begin
     //Initital  resource and Get Boroad numbers from driver
     wRtn := Ixud_DriverInit(wTotalBoards);

     If wRtn <> NoError Then
     begin
        Application.MessageBox('*** DriverInit ! ***', 'Error' , IDOK);
        Exit;
     End;

     If wTotalBoards <1 Then
     begin
        Application.MessageBox('*** Do not Find Board! ***', 'Error' , IDOK);
        Exit;
     End;

     for wBoardIndex :=0  to  wTotalBoards - 1  do
     begin
         //Get Card Information
         wRtn := Ixud_GetCardInfo(wBoardIndex,sDevInfo[wBoardIndex],sCardInfo[wBoardIndex],szModelName);
         cbxSelBoard.Items.Add(IntToStr(wBoardIndex)+':'+szModelName);
     end;

     //Select the Board Number 0
     cbxSelBoard.ItemIndex :=0;
     cbxSelecBoardChange(Sender);

     //Select the Analog Output Range to +/-10 V
     cbxAORange.ItemIndex := 3;

end;

procedure TForm1.btnExitClick(Sender: TObject);
begin
     //wRtn:=Ixud_DriverClose();
     Close;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
     //Release the resource from driver
     wRtn := Ixud_DriverClose;
end;

procedure TForm1.btnOutputClick(Sender: TObject);
begin
     wBoardNo := cbxSelBoard.ItemIndex;
     wChannel := cbxChannel.ItemIndex;
     wCfgCode := cbxAORange.ItemIndex;
     fAOValue := StrToFloat(eValue.Text);

     wRtn := Ixud_ConfigAO(wBoardNo,wChannel,wCfgCode);

     wRtn := Ixud_WriteAOVoltage(wBoardNo,wChannel,fAOValue);
end;

end.

