Autor Beitrag
Moonbiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Mo 10.10.05 17:06 
Hi!

Ich arbeite mir der vielleicht bekannten Komponente 'comm_async' um Daten, die mein Microcontroler an den ComPort sendet, an Delphi zu übergeben. Die Daten die jener MC sendet sind $ldx$rdx$lix$rix (x ist ein integer zwischen 0 und 255) und werden aller 200ms gesendet.

Wenn ein Zeichen ankommt (OnCharRecieve), wird es der Variable buf übergeben, welche ein char ist.

Die Daten werden, schreibt man sie bspweise in ein Memofeld, einwandfrei übertragen!

Nur wenn ich die Daten weiterverarbeiten will, gibt es jede menge fehler:

Hier der Code den ich zum trennen und schreiben in eine dynamische array benutze:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
[...]
type  TTable = array of array[1..4] of integer;

var
  Form1: TForm1;
  acs: string;
  i,j : integer;
  robotable : TTable;
  ctrl:boolean;

[...]

procedure TForm1.Comm1CharReceived(Sender: TObject; cbInQue: Cardinal);
var
  buf:char;
  tempacs1:string;
  tempacs2:integer;
begin
COMM1.Read(@buf,1);
if buf='$' then ctrl:=true;
if (buf<>'$') and ctrl then acs:=acs+buf;

if (buf='$') and (acs<>'') and ctrl then
  begin
  tempacs1:=acs[1]+acs[2];

  case length(acs) of
  3:tempacs2:=StrToInt(acs[3]);
  4:tempacs2:=StrToInt(acs[3]+acs[4]);
  5:tempacs2:=StrToInt(acs[3]+acs[4]+acs[5]);
  end;

  //label3.caption:=Inttostr(tempacs2);

  if (tempacs1 <> 'ld') and (tempacs1 <> 'rd')
    and (tempacs1 <> 'li') and (tempacs1 <> 'ri') then
      begin
      // Raise an exception
      end
    else
      begin
        SetLength(robotable,j);
        if tempacs1 = 'ld' then robotable[1,j]:=tempacs2;
        if tempacs1 = 'rd' then robotable[2,j]:=tempacs2;
        if tempacs1 = 'li' then robotable[3,j]:=tempacs2;
        if tempacs1 = 'ri' then robotable[4,j]:=tempacs2;

        memo.SelText:=
        IntToStr(robotable[1,j])+' - '+
        IntToStr(robotable[2,j])+' - '+
        IntToStr(robotable[3,j])+' - '+
        IntToStr(robotable[4,j])+' -- ';

        inc(i);
        if i=4 then
          begin
          inc(j);
          i:=0;
          end;
      end;
  acs:='';
  ctrl:=false;
  end;
end;


Wenn ich es nach einem neustart ausführe, schreibt er manchmal die richtigen, oft aber auch die falschen zahlen in die tabelle (oder zeigt sie zumindest beim ausgeben), und stürzt dann ab. Führe ich es danach nochmal aus, zeigt er nur noch wilde zeichen, und man kann sich außerdem irgendwie vor allen mgl fehlern nicht mehr retten...

bitte helft mir,
thx

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Mo 10.10.05 18:18 
Schon mal versucht mit dem Debugger einzeln durchzusteppen?

Die Variable j.. wird die am Anfang auf 0 gesetzt?

_________________
Stellen Sie sich bitte Zirkusmusik vor.
Moonbiker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Mo 10.10.05 18:22 
nein, ist das wichtig?:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;
j:=1;
acs:='';
ctrl:=false;
//
combobox1.ItemIndex:=0;
ComboBox1Change(nil)
//
end;


Ein Fehler ist übrigens, wenn er eine weile empfangen hat, dass dann versucht wird ein bspweise 'rd6' versucht wird als integer zu verwenden, und dann nat. da es kein gültiger integerwert ist ein fehler kommt...

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Di 11.10.05 11:58 
1) Ja, es ist wichtig, wenn man mit Indiezes arbeitet.
Delphi setzt integer nicht autom. auf 0.

2) Debugge dein Programm mal und gehe dabei Schrittweise vor, prüfe alle deine Variablen.

//Edit: Prüf mal f. den robottable, ob die Werte an der richtigen Position stehen.

_________________
Stellen Sie sich bitte Zirkusmusik vor.
Moonbiker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Di 11.10.05 12:10 
vielen dank, werde ich gleich versuchen!
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Di 11.10.05 12:19 
Ich bin schon n bissl aus Delphi raus, weil ich derzeit mehr mit C rumfuhrwerke..

Bzgl. robottable

kann es sein, dass robottable in der ersten Dimension x beträgt und in der zweiten dimension 4.
Du greifst aber zu, indem du in der ersten Dimension von 1 bis 4 gehst und j dementsprechend, über den
Index 4 hinausgeht?

Evtl. verwechsel ich da auch was.

_________________
Stellen Sie sich bitte Zirkusmusik vor.
ähM_Key
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 88

Windows XP Professional
D7 Enterprise
BeitragVerfasst: Do 13.10.05 09:03 
Hi!

Ich hab das Proggi mit Moonbiker geschrieben.

Wir haben die angesprochenen Sachen probiert, aber das Problem besteht immernoch.

..an sich müsste es doch funktionieren, also theoretisch; ist bestimmt wieder so ein komischer Fehler :(
Vielleicht irgendwas mit dem Timing vom Com-Port, Speicherüberlauf...k.A.

Grüße; ähM_Key

_________________
Alles geht ni! Aber ein bissl' was muss!