Einzelnen Beitrag anzeigen

hedie

Registriert seit: 12. Dez 2005
Ort: Schweiz
1.024 Beiträge
 
Delphi XE6 Starter
 
#8

AW: wo kommt das type hin?

  Alt 9. Jun 2010, 19:33
Gut...

Hier mein gesamter Code


Funktion: Ich empfange von einer Computer Hardware Dezimal Zahlen von 0 - 255
Diese wandle ich nach Binär und stelle die 1en und 0en auf einer Oberfläche dar
Das ganze ist dan ein LogicAnalyzer

In den Arrays Daten1-Daten8 steht wo eine 1 oder eine 0 ist bezogen auf die gesamte anzahl an gesammelten daten

Beispiel
Delphi-Quellcode:
Data[1] := 1 //Eine Eins
Data[2] := 4112 //Steht an stelle 4112 des gesamten
Delphi-Quellcode:
unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ExtCtrls, StdCtrls, jpeg, ImgList, ComCtrls;

type
  MyData = array[1..100000] of integer;
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    OpenLogic1: TMenuItem;
    About1: TMenuItem;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Image9: TImage;
    Shape1: TShape;
    ScrollBar1: TScrollBar;
    ImageList1: TImageList;
    Label9: TLabel;
    Label10: TLabel;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    Image17: TImage;
    Image18: TImage;
    ProgressBar1: TProgressBar;
    ScrollBar2: TScrollBar;
    Label11: TLabel;
    About2: TMenuItem;
    KeineAktualisierungverfgbar1: TMenuItem;
    Label1: TLabel;
    Label12: TLabel;
    update_check: TTimer;
    marker1: TPanel;
    dispmarker1: TLabel;
    Button1: TButton;
    marker2: TPanel;
    dispmarker2: TLabel;
    GroupBox1: TGroupBox;
    dispdmarker: TLabel;
    dispfreq: TLabel;
    ComboBox1: TComboBox;
    Button2: TButton;
    Label13: TLabel;
    ListBox1: TListBox;
    Button3: TButton;
    Label14: TLabel;
    Memo1: TMemo;
    Button5: TButton;
    ComboBox2: TComboBox;
    procedure draw_raw_data(drawspace:TImage;color:TColor; data_in:MyData);
    procedure prepaire_data;
    procedure refresh_all;
    procedure FormCreate(Sender: TObject);
    procedure About2Click(Sender: TObject);
    procedure KeineAktualisierungverfgbar1Click(Sender: TObject);
    procedure update_checkTimer(Sender: TObject);
    procedure refresh_marker(X:integer;marker:TPanel;display:TLabel);
    procedure refresh_times;
    procedure marker1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure marker2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormShow(Sender: TObject);
    procedure ComboBox1DropDown(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure ScrollBar2Change(Sender: TObject);
    procedure clear_disp(disp:TImage);
    procedure clear_all;
    procedure ScrollBar1Change(Sender: TObject);


  private
    { Private-Deklarationen }
  public

    version_t:string;
    version,timems,timebasems,timeleft,timeright,marker1ms,marker2ms:integer;
    data1,data2,data3,data4,data5,data6,data7,data8: MyData;

  end;

var
  Form1: TForm1;

implementation



uses about, update,D2XXUnit, CfgUnit;




var
 DevicePresent : Boolean;
 Selected_Device_Serial_Number : String;
 Selected_Device_Description : String;
 Store_Buffer : Array[0..512000] of byte; //512kb Speicher.
 Store_Buffer_Count:integer;
 gesamt_einheit:integer;
 ein_pixel,buffer_size,start,stop:integer;
 main_color:tcolor;


{$R *.dfm}

procedure TForm1.refresh_times;
begin
  timeleft := ((timems div ScrollBar1.Max) * ScrollBar1.Position) - timebasems;
  timeright := ((timems div ScrollBar1.Max) * ScrollBar1.Position);
  Label9.Caption := inttostr(timeleft)+'ms';
  Label10.Caption := inttostr(timeright)+'ms';
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  start := ScrollBar1.Position;
  Label9.Caption := inttostr(start);
  stop := ScrollBar1.Position + (gesamt_einheit div ScrollBar2.Position);
  Label10.Caption := inttostr(stop);
  clear_all;
  refresh_all;
  
end;

procedure TForm1.ScrollBar2Change(Sender: TObject);
begin

  ScrollBar1.Max := (gesamt_einheit);
  Label11.Caption := inttostr(gesamt_einheit div ScrollBar2.Position);
  ein_pixel := (gesamt_einheit div ScrollBar2.Position) div Image9.Width;
  clear_all;
  refresh_all;
end;

procedure TForm1.refresh_marker(X:integer;marker:TPanel;display:TLabel);
var mslen:integer;
begin
  if ((marker.Left + X) > (Image9.Left - 1)) and ((marker.Left + X) < ((Image9.Left + Image9.Width) +1)) then begin
    mslen := (timebasems * timems div (Image9.width));
    display.Caption := inttostr( ( ((marker.Left - Image9.Left) * mslen) div 10000) + timeleft + 1)+'ms';
    marker.Left := marker.Left + X;
    display.Left := display.Left + X;
    if marker.Name = 'marker1then marker1ms := ( ((marker.Left - Image9.Left) * mslen) div 10000) + timeleft + 1;
    if marker.Name = 'marker2then marker2ms := ( ((marker.Left - Image9.Left) * mslen) div 10000) + timeleft + 1;
    dispdmarker.Caption := 'Delta ms: '+inttostr(marker2ms-marker1ms)+'ms';
    dispfreq.Caption := 'Freq. Hz: '+ inttostr(1000 div ((marker2ms-marker1ms)))+'Hz';
  end;

end;

procedure draw_up(pointer:TImage;color:TColor;x:integer);
begin
 with pointer.Canvas do begin
    Pen.Color := color;
    Pen.Width := 1;
    MoveTo(x,25);
    LineTo(x,5);
    //color := clBlack;
 end;
 //showmessage(inttostr(x));
end;

procedure draw_down(pointer:TImage;color:TColor;x:integer);
begin
 with pointer.Canvas do begin
    Pen.Color := color;
    Pen.Mode := pmMerge;
    Pen.Width := 1;
    MoveTo(x,5);
    LineTo(x,25);
 end;

end;

procedure draw_line(pointer:TImage;color:TColor;x1,x2,y:integer);
begin
 with pointer.Canvas do begin
    Pen.Color := color;
    Pen.Width := 1;
    MoveTo(x1,y);
    LineTo(x2,y);
 end;
end;


procedure TForm1.About2Click(Sender: TObject);
begin
  Form2.ShowModal;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if dispmarker1.Visible = true then begin
    dispmarker1.Visible := false;
    dispmarker2.Visible := false;
    marker1.Visible := false;
    marker2.Visible := false;
  end
  else begin
    dispmarker1.Visible := true;
    dispmarker2.Visible := true;
    marker1.Visible := true;
    marker2.Visible := true;
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
If Open_USB_Device_By_Serial_Number(Selected_Device_Serial_Number) = FT_OK then begin
  FT_Current_Parity := 1;
  FT_Current_StopBits := 0;
  FT_Current_DataBits := 8;
  Set_USB_Device_DataCharacteristics;
  FT_Current_Baud := 3000000;
  Set_USB_Device_BaudRate;
  Label13.Caption := 'Status: Verbunden mit: ' + Selected_Device_Serial_Number;
end
else begin
  Label13.Caption := 'Status: Fehler beim verbinden mit: ' + Selected_Device_Serial_Number;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin


  ProgressBar1.Max := gesamt_einheit;
  ProgressBar1.Position := 0;
  repeat
  Read_USB_Device_Buffer(buffer_size);
  Move(FT_In_Buffer[0], Store_Buffer[Store_Buffer_Count], Length(FT_In_Buffer));
  Inc(Store_Buffer_Count, buffer_size);
  ProgressBar1.Position := ProgressBar1.Position + buffer_size;
  Label14.Caption := 'Saved: '+inttostr(ProgressBar1.Position);
  Application.ProcessMessages;
  until ProgressBar1.Position = gesamt_einheit;
end;

procedure TForm1.refresh_all;
begin
  draw_raw_data(Image9,main_color,data1);
  draw_raw_data(Image12,main_color,data2);
  draw_raw_data(Image13,main_color,data3);
  draw_raw_data(Image14,main_color,data4);
  draw_raw_data(Image15,main_color,data5);
  draw_raw_data(Image16,main_color,data6);
  draw_raw_data(Image17,main_color,data7);
  draw_raw_data(Image18,main_color,data8);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  clear_all;
  prepaire_data;
  refresh_all;
end;

{procedure doFoo2(const  a: Array of Byte);
var
i:integer;
value_old:integer;
data_counter:integer;
begin
  i := 0;
  data_counter := 1;
  value_old := 500;
  repeat
  if a[i] <> value_old then  begin
    Form1.Memo1.Lines.Add(inttostr(a[i])+','+inttostr(i)+',');
    if(a[i] = 1) then begin
      Form1.data[data_counter] := 1;
      Form1.data[data_counter + 1] := i;
      data_counter := data_counter + 2;
    end;
    if(a[i] = 0) then begin
      Form1.data[data_counter] := 0;
      Form1.data[data_counter + 1] := i;
      data_counter := data_counter + 2;
    end;
    value_old := a[i];
  end;
  i := i + 1;
  until gesamt_einheit <= i;
  Form1.data[data_counter] := 748575;
end;        }


procedure TForm1.ComboBox1Click(Sender: TObject);
begin
  Selected_Device_Serial_Number := ListBox1.Items.Strings[ComboBox1.ItemIndex];
  //Showmessage(Selected_Device_Serial_Number);
end;

procedure TForm1.ComboBox1DropDown(Sender: TObject);
var S:String; DeviceIndex : DWord; I : Integer; LV : TListItem;
begin
ComboBox1.Items.clear; //Auswahl löschen
ListBox1.Clear; //Geräte ID's löschen
GetFTDeviceCount;
S := IntToStr(FT_Device_Count);
DeviceIndex := 0;
If FT_Device_Count > 0 then
  Button2.Enabled := true;
  For I := 1 to FT_Device_Count do
  Begin
  GetFTDeviceDescription ( DeviceIndex );
  ComboBox1.Items.Add(FT_Device_String);
  GetFTDeviceSerialNo( DeviceIndex );
  ListBox1.Items.Add(FT_Device_String);
  DeviceIndex := DeviceIndex + 1;
  End;

end;

procedure TForm1.prepaire_data;
  var
alter_wert,counter,i,i2,temp_wert,cd1,cd2,cd3,cd4,cd5,cd6,cd7,cd8:integer;
vorheriges_x,aktuelle_flanke:integer;
linie_zeichnen:boolean;
temp_data,old_data:Array[0..8] of integer;
begin

  i := 0;
  i2:= 0;
  counter := 1;
  vorheriges_x := 0;
  aktuelle_flanke := 0;
  cd8 := 1;
  cd7 := 1;
  cd6 := 1;
  cd5 := 1;
  cd4 := 1;
  cd3 := 1;
  cd2 := 1;
  cd1 := 1;

  repeat

    //Form1.Memo1.Lines.Add(inttostr(Store_Buffer[i])+',Bin:');
    temp_data[0] := Store_Buffer[i] mod 2;
    temp_wert := Store_Buffer[i] div 2;
    temp_data[1] := temp_wert mod 2;
    temp_wert := temp_wert div 2;
    temp_data[2] := temp_wert mod 2;
    temp_wert := temp_wert div 2;
    temp_data[3] := temp_wert mod 2;
    temp_wert := temp_wert div 2;
    temp_data[4] := temp_wert mod 2;
    temp_wert := temp_wert div 2;
    temp_data[5] := temp_wert mod 2;
    temp_wert := temp_wert div 2;
    temp_data[6] := temp_wert mod 2;
    temp_wert := temp_wert div 2;
    temp_data[7] := temp_wert mod 2;



    if temp_data[0] <> old_data[0] then begin
      data1[cd1] := temp_data[0];
      data1[cd1+1] := i;
      cd1 := cd1 + 2;
    end;
    if temp_data[1] <> old_data[1] then begin
      data2[cd2] := temp_data[1];
      data2[cd2+1] := i;
      cd2 := cd2 + 2;
    end;
    if temp_data[2] <> old_data[2] then begin
      data3[cd3] := temp_data[2];
      data3[cd3+1] := i;
      cd3 := cd3 + 2;
    end;
    if temp_data[3] <> old_data[3] then begin
      data4[cd4] := temp_data[3];
      data4[cd4+1] := i;
      cd4 := cd4 + 2;
    end;
    if temp_data[4] <> old_data[4] then begin
      data5[cd5] := temp_data[4];
      data5[cd5+1] := i;
      cd5 := cd5 + 2;
    end;
    if temp_data[5] <> old_data[5] then begin
      data6[cd6] := temp_data[5];
      data6[cd6+1] := i;
      cd6 := cd6 + 2;
    end;
    if temp_data[6] <> old_data[6] then begin
      data7[cd7] := temp_data[6];
      data7[cd7+1] := i;
      cd7 := cd7 + 2;
    end;
    if temp_data[7] <> old_data[7] then begin
      data8[cd8] := temp_data[7];
      data8[cd8+1] := i;
      cd8 := cd8 + 2;
    end;
    Move(temp_data[0], old_data[0], Length(temp_data)); //Array kopieren
    i := i + 1;

  until gesamt_einheit <= i;

  data1[cd1] := 5;
  data2[cd2] := 5;
  data3[cd3] := 5;
  data4[cd4] := 5;
  data5[cd5] := 5;
  data6[cd6] := 5;
  data7[cd7] := 5;
  data8[cd8] := 5;

  {cd1 := 1;
    repeat

    Form1.Memo1.Lines.Add(inttostr(data1[cd1]));
    Form1.Memo1.Lines.Add(inttostr(data1[cd1+1]));
    cd1 := cd1 + 2;
    until data1[cd1] = 5;
                                     }

    cd1 := 1;
    repeat
    Form1.Memo1.Lines.Add(inttostr(data1[cd1]));
    Form1.Memo1.Lines.Add(inttostr(data1[cd1+1]));
    cd1 := cd1 + 2;
    until (data1[cd1] = 5) or (data1[cd1-2] = 5);

    cd2 := 1;
    repeat
    Form1.Memo1.Lines.Add(inttostr(data2[cd2]));
    Form1.Memo1.Lines.Add(inttostr(data2[cd2+1]));
    cd2 := cd2 + 2;
    until (data2[cd2] = 5) or (data2[cd2-2] = 5);

    cd3 := 1;
    repeat
    Form1.Memo1.Lines.Add(inttostr(data3[cd3]));
    Form1.Memo1.Lines.Add(inttostr(data3[cd3+1]));
    cd3 := cd3 + 2;
    until (data3[cd3] = 5) or (data3[cd3-2] = 5);

    cd4 := 1;
    repeat
    Form1.Memo1.Lines.Add(inttostr(data4[cd4]));
    Form1.Memo1.Lines.Add(inttostr(data4[cd4+1]));
    cd4 := cd4 + 2;
    until (data4[cd4] = 5) or (data4[cd4-2] = 5);

    cd5 := 1;
    repeat
    Form1.Memo1.Lines.Add(inttostr(data5[cd5]));
    Form1.Memo1.Lines.Add(inttostr(data5[cd5+1]));
    cd5 := cd5 + 2;
    until (data5[cd5] = 5) or (data5[cd5-2] = 5);

    Form1.Memo1.Lines.Add(' |-| ');

  {repeat
  if Store_Buffer[i] <> alter_wert then  begin
    Form1.Memo1.Lines.Add(inttostr(Store_Buffer[i])+','+inttostr(i)+',');

    if(Store_Buffer[i] = 1) then begin
      data[counter] := 1;
      data[counter + 1] := i;
      counter := counter + 2;
    end;

    if(Store_Buffer[i] = 0) then begin
      data[counter] := 0;
      data[counter + 1] := i;
      counter := counter + 2;
    end;
    alter_wert := Store_Buffer[i];
  end;
  i := i + 1;
  until gesamt_einheit <= i;
  data[counter] :=  748575;    }

end;

procedure TForm1.draw_raw_data(drawspace:TImage;color:TColor;data_in:MyData);
var
counter:integer;
begin

  counter := 1;
  repeat
    draw_up(drawspace,color,((data_in[counter+1] - start) div ein_pixel));
    if data_in[counter - 2] = 1 then draw_line(drawspace,color,(data_in[counter-1]-start) div ein_pixel,(data_in[counter+1] - start) div ein_pixel,5);
    if data_in[counter - 2] = 0 then draw_line(drawspace,color,(data_in[counter-1]-start) div ein_pixel,(data_in[counter+1] - start) div ein_pixel,25);
    counter := counter + 2;
  until (data_in[counter] = 5) or(data_in[counter-2] = 5) ;
  if data_in[counter - 2] = 1 then draw_line(drawspace,color,(data_in[counter-1]-start)div ein_pixel,gesamt_einheit div ein_pixel,5);
  if data_in[counter - 2] = 0 then draw_line(drawspace,color,(data_in[counter-1]-start)div ein_pixel,gesamt_einheit div ein_pixel,25);

end;

procedure TForm1.clear_disp(disp:TImage);
begin
  with disp.canvas do begin
  brush.Color:=$00575048;
  brush.Style:=bsSolid;
  rectangle(0,-1,disp.Width+2,disp.Height+2);
  end;
end;

procedure TForm1.clear_all;
begin
  clear_disp(Form1.Image9);
  clear_disp(Form1.Image12);
  clear_disp(Form1.Image13);
  clear_disp(Form1.Image14);
  clear_disp(Form1.Image15);
  clear_disp(Form1.Image16);
  clear_disp(Form1.Image17);
  clear_disp(Form1.Image18);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

version_t := '1.0.0.21';
form1.DoubleBuffered := true;


end;

procedure TForm1.FormShow(Sender: TObject);
begin
  FT_Enable_Error_Report := true; // Error reporting = on
  gesamt_einheit := 50000; //Anzahl Samples
  buffer_size := 1000; //Anzahl Samples pro übertragung
  start := 0;
  stop := gesamt_einheit;
  ein_pixel := gesamt_einheit div Image9.Width;
  main_color := clWhite;
  //DevicePresent
end;

procedure TForm1.KeineAktualisierungverfgbar1Click(Sender: TObject);
begin
  Form3.Showmodal;
end;

procedure TForm1.marker1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  refresh_marker(X,marker1,dispmarker1);
end;

procedure TForm1.marker2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  refresh_marker(X,marker2,dispmarker2);
end;

procedure TForm1.update_checkTimer(Sender: TObject);
begin
  update_check.Enabled := false;

  if paramstr(1) = 'updatethen begin
    deletefile(extractfilepath(paramstr(0))+'old.exe');
    showmessage('Herzlichen Glückwunsch... Update erfolgreich! Version: ' + version_t);
  end;

end;

end.
Claudio
Tu was du nicht lassen kannst
- http://endasmedia.ch
  Mit Zitat antworten Zitat