Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit example_dll;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls, Grids, tedia_daq01h, Registry, Math, ComCtrls,
- AppEvnts;
- type
- ADWord=array of DWord;
- TExample = class(TForm)
- Panel2: TPanel;
- GroupBox6: TGroupBox;
- NumberOfChannels: TLabeledEdit;
- PageControl1: TPageControl;
- TabSheet1: TTabSheet;
- TabSheet2: TTabSheet;
- Panel1: TPanel;
- StringGrid1: TStringGrid;
- StringGrid2: TStringGrid;
- OpenAndSetParam: TButton;
- GetValues: TButton;
- Panel3: TPanel;
- SetValues: TButton;
- procedure GetValuesClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure OpenAndSetParamClick(Sender: TObject);
- procedure SetValuesClick(Sender: TObject);
- private
- public
- aktivni_sloupec:integer;
- is_running:boolean;
- call_buffer:PByte;
- call_size_of_buffer:integer;
- Fintput_or_output:DWord; //0-vstupni porty, 1-vystupni porty
- procedure resolve_error(n_error:DWord); //Procedura, ktera vytvori message box s chybovou zprávou
- end;
- var
- Example: TExample;
- Ihandle:PHandle;
- count_of_channels:integer;
- buffer:PDWord;
- frequency:double;
- period:double;
- implementation
- {$R *.dfm}
- procedure TExample.GetValuesClick(Sender: TObject);
- type
- AByte=array of byte;
- var
- result_:integer;
- i,j:integer;
- myRect:TGridRect;
- begin
- if(is_running) and (Fintput_or_output=0) then
- begin
- //Zjisteni hodnoty digitalnich vstupu
- result_:=Td_Get_DI(IHandle,0,buffer,count_of_channels);
- if result_<>0 then
- begin
- //Nepodařilo se odměřit požadovaný počet kanálů.
- resolve_error(result_);
- Exit;
- end;
- StringGrid1.RowCount:=max(count_of_channels+1,2);
- for j:=1 to count_of_channels do
- begin
- StringGrid1.Cells[aktivni_sloupec,j]:=IntToStr(ADWord(buffer)[j-1]);
- end;
- myRect.Left := aktivni_sloupec;
- myRect.Top := 1;
- myRect.Right := aktivni_sloupec;
- myRect.Bottom := count_of_channels+1;
- StringGrid1.Selection := myRect;
- aktivni_sloupec:= (aktivni_sloupec+1) mod 5;
- end
- else
- ShowMessage('Karta není nakonfigurována, nebo není nastavena ve správném režimu.');
- end;
- procedure TExample.FormCreate(Sender: TObject);
- var
- count_registry_card_loc:DWord;
- card_exists:boolean;
- result_:DWord;
- i:integer;
- begin
- //Vyplnim ListBox jmeny pripravenych karet
- count_of_channels:=3;
- aktivni_sloupec:=0;
- //Otevru kartu
- result_:=Td_Init_Driver(@Ihandle,PChar('EXAM_DIGITAL'));
- if result_<>0 then
- begin
- Application.MessageBox('Nenalezené žádná aktivní zařízení s názvem EXAM_DIGITAL, použijte administrační program [admin.exe].','Chyba!',MB_ICONERROR);
- resolve_error(result_);
- Application.Terminate;
- end;
- is_running:=false;
- for i:=0 to count_of_channels-1 do
- begin
- StringGrid2.Cells[i,1]:='1';
- end;
- end;
- procedure TExample.FormClose(Sender: TObject; var Action: TCloseAction);
- var
- result_:integer;
- begin
- //Uzavreme zarizeni
- result_:=Td_Close_Driver(Ihandle);
- if result_<>0 then
- begin
- //Nepodařilo se uzavřít kartu.
- resolve_error(result_);
- Exit;
- end;
- end;
- procedure TExample.OpenAndSetParamClick(Sender: TObject);
- type
- AByte=array of byte;
- var
- result_:DWord;
- i,j:integer;
- myRect:TGridRect;
- sample:byte;
- n_param:double;
- t_param:DWord;
- tmp_char:array[0..200] of char;
- tmp_char1:array[0..200] of char;
- begin
- try
- result_:=StrToInt(NumberOfChannels.Text);
- Except
- Application.MessageBox('Počet kanálů musí být celé kladné číslo.','Chyba!',MB_ICONERROR);
- Exit;
- end;
- if result_<=0 then
- begin
- Application.MessageBox('Počet kanálů musí být celé kladné číslo.','Chyba!',MB_ICONERROR);
- Exit;
- end;
- count_of_channels:=result_;
- StringGrid2.ColCount:=count_of_channels;
- for i:=0 to count_of_channels-1 do
- begin
- StringGrid2.Cells[i,1]:='1';
- end;
- if(PageControl1.Activepage=PageControl1.Pages[0]) then
- Fintput_or_output:=0
- else
- Fintput_or_output:=1;
- result_:=Td_Get_Info_DeviceName(PChar('EXAM_DIGITAL'),1,@n_param,@tmp_char[0],@t_param);
- result_:=Td_Get_Info_DeviceType(@tmp_char[0],1304,@n_param,@tmp_char1[0],@t_param);
- if (n_param=1) then //Parametr INFO_Digital_Not_Fixed=> musim nastavit dig. porty
- begin
- for i:=0 to count_of_channels-1 do
- begin
- case i of
- 0: result_:=Td_Set_Parameters(Ihandle,15,Fintput_or_output,nil,0,0);
- 1: result_:=Td_Set_Parameters(Ihandle,16,Fintput_or_output,nil,0,0);
- 2: result_:=Td_Set_Parameters(Ihandle,17,Fintput_or_output,nil,0,0);
- 3: result_:=Td_Set_Parameters(Ihandle,18,Fintput_or_output,nil,0,0);
- end;
- if result_<>0 then
- begin
- //Nepodařilo se nastavit porty jako výstupní.
- resolve_error(result_);
- Exit;
- end;
- end;
- end;
- is_running:=true;
- GetMem(buffer,count_of_channels*sizeof(DWord));
- end;
- procedure TExample.SetValuesClick(Sender: TObject);
- var
- i:integer;
- result_:DWord;
- sample:DWord;
- begin
- if(is_running) and (Fintput_or_output=1) then
- begin
- for i:=0 to count_of_channels-1 do
- begin
- try
- result_:=StrToInt(StringGrid2.Cells[i,1]);
- Except
- Application.MessageBox('V tabulce musíte nastavit taková čísla jaké mohou digitální výstupy nastavit [0..255].','Chyba!',MB_ICONERROR);
- Exit;
- end;
- if(result_<0) OR (result_>255) then
- begin
- Application.MessageBox('V tabulce musíte nastavit taková čísla jaké mohou digitální výstupy nastavit [0..255].','Chyba!',MB_ICONERROR);
- Exit;
- end;
- sample:=result_; //Mam platne cislo
- Td_Set_DO(Ihandle,i,@sample,1); //Tak ho dodeslu
- end;
- end
- else
- ShowMessage('Karta není nakonfigurována, nebo není nastavena ve správném režimu.');
- end;
- //Procedura, ktera vytvori message box s chybovou zprávou
- procedure TExample.resolve_error(n_error:DWord);
- var
- function_:array[0..1000] of char;
- error_:array[0..1000] of char;
- begin
- Td_Get_ErrorMessage(n_error,PChar(@function_),PChar(@error_));
- Application.MessageBox(PChar(@error_),PChar(@function_),MB_ICONERROR);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement