Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi AccessViolation beim öffnen einer Com Verbindung (https://www.delphipraxis.net/83420-accessviolation-beim-oeffnen-einer-com-verbindung.html)

EDatabaseError 2. Jan 2007 15:01


AccessViolation beim öffnen einer Com Verbindung
 
Wenn ich mit diesem Code:

Delphi-Quellcode:
procedure TfComm.Button1Click(Sender: TObject);
begin
 GroupBox1.Enabled := false;
 Combobox1.Enabled := false;

 
 rs2321 := trs232.create(self);

 with rs2321 do begin
  ComPortSpeed := br19200;
  ComPortDatabits := db8bits;
  ComPortHwHandshaking := hhNone;
  ComPortParity := ptNone;
  ComPortStopBits := sb1bits;
  ComPortSwHandshaking := shnone;
  TimeOut := -1;
  TimeOutException := false;
 end;

 case combobox1.ItemIndex of
  0: rs2321.ComPort := pnCom1;
  1: rs2321.ComPort := pnCom2;
  2: rs2321.ComPort := pnCom3;
  3: rs2321.ComPort := pnCom4;
 end;

 RS2321.Connect;

 if RS2321.Connected then
  begin
   (Sender as tbutton).Caption := 'Verbindung erfolgreich!';

   GroupBox2.Enabled := false;
   Button1.Enabled := false;
   GroupBox3.Enabled := true;
   Button2.Enabled := true;
  end
 else
  messagedlg('Fehler bei dem Herstellen der Verbindung!'+#13+#10+'Bitte das Kabel nochmals überprüfen.', mtError, [mbOK], 0);
end;
...versuche eine RS232 Verbindung herstellen knallts in der Zeile : RS2321.Connect;

Die Connect Funktion sieht folgendermaßen aus:

Delphi-Quellcode:
function TCommPortDriver.Connect: boolean;
var comName: array[0..4] of char;
    tms: TCOMMTIMEOUTS;
begin
  FDatainbuffer('A');
  // Do nothing if already connected
  Result := Connected;
  if Result then exit;
  // Open the COM port
  StrPCopy( comName, 'COM' );
  comName[3] := chr( ord('1') + ord(FComPort) );
  comName[4] := #0;
  FComPortHandle := CreateFile(
                                comName,
                                GENERIC_READ or GENERIC_WRITE,
                                0, // Not shared
                                nil, // No security attributes
                                OPEN_EXISTING,
                                FILE_ATTRIBUTE_NORMAL,
                                0 // No template
                              ) ;
  Result := Connected;
  if not Result then exit;
  // Apply settings
  ApplyCOMSettings;
  // Setup timeouts: we disable timeouts because we are polling the com port!
  tms.ReadIntervalTimeout := 1; // Specifies the maximum time, in milliseconds,
                                // allowed to elapse between the arrival of two
                                // characters on the communications line
  tms.ReadTotalTimeoutMultiplier := 0; // Specifies the multiplier, in
                                       // milliseconds, used to calculate
                                       // the total time-out period
                                       // for read operations.
  tms.ReadTotalTimeoutConstant := 1; // Specifies the constant, in milliseconds,
                                     // used to calculate the total time-out
                                     // period for read operations.
  tms.WriteTotalTimeoutMultiplier := 0; // Specifies the multiplier, in
                                        // milliseconds, used to calculate
                                        // the total time-out period
                                        // for write operations.
  tms.WriteTotalTimeoutConstant := 0; // Specifies the constant, in
                                      // milliseconds, used to calculate
                                      // the total time-out period
                                      // for write operations.
  SetCommTimeOuts( FComPortHandle, tms );

  Sleep(1000); // to avoid timing problems, wait until the Comm-Port is opened
end;
(Für die die es wissen wollen die Exception tritt genau bei pop esi auf)

In einer anderen Anwendung funktioniert alles...ohne Exception.


Hoffe ihr könnt mir helfen.



Mfg
Tobi

SirThornberry 2. Jan 2007 15:14

Re: AccessViolation beim öffnen einer Com Verbindung
 
An welcher Adresse tritt die Zugriffsverletzung auf? Kannst du die vollständige Fehlermeldung posten? Und an welcher Stelle in der Connect-Methoden knallts?

EDatabaseError 2. Jan 2007 15:17

Re: AccessViolation beim öffnen einer Com Verbindung
 
Liste der Anhänge anzeigen (Anzahl: 1)
Klaro ;-)


//edit
Delphi-Quellcode:
FDatainbuffer('A');
hier knallts...

EDatabaseError 2. Jan 2007 15:22

Re: AccessViolation beim öffnen einer Com Verbindung
 
Die Zeile weg und es geht...Danke für die Idee auch mal Wartepunkte in der Komponente zu setzen...

Tobi

Klaus01 2. Jan 2007 15:22

Re: AccessViolation beim öffnen einer Com Verbindung
 
Ist der FDataInBuffer irgendwo instantiiert worden?

[edit] .. aber wenn Du ihn eh nicht brauchst..

Grüße
Klaus

SirThornberry 2. Jan 2007 15:23

Re: AccessViolation beim öffnen einer Com Verbindung
 
und an welcher Stelle in FDataInBuffer? Oder knallts schon beim Aufruf der Funktion (wäre eher unwahrscheinlich)

EDatabaseError 2. Jan 2007 15:25

Re: AccessViolation beim öffnen einer Com Verbindung
 
Zitat:

Zitat von SirThornberry
und an welcher Stelle in FDataInBuffer? Oder knallts schon beim Aufruf der Funktion (wäre eher unwahrscheinlich)

FDatainbuffer ist eine Protectedeigenschaft. Ein wunder das Delphi das überhaupt compiliert hat...

SirThornberry 2. Jan 2007 15:27

Re: AccessViolation beim öffnen einer Com Verbindung
 
warum "ein Wunder"? Innerhalb der Klasse ist es doch normal/richtig das man auf Protected-Eigenschaften zugreifen kann. Ist es wirklich ein Property oder eine Methode? Wenn es ein property ist liegt dann wohl daran das es nicht zugewiesen wurde.

EDatabaseError 2. Jan 2007 15:32

Re: AccessViolation beim öffnen einer Com Verbindung
 
Delphi-Quellcode:
   
TDataInBuffer = procedure(buffer:char) of object;
...
  protected
    FDataInBuffer             : TDataInBuffer;
...
  public
...
    property OnDataInBuffer: TDataInBuffer   read FDataInBuffer
                                              write FDataInBuffer;
Weitere Verknüpfungen/Vorkommnisse gibts nicht - :stupid: ok es war kein Wunder - es wurde eine Prozedur aufgerufen die ins leere lief


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:42 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz