![]() |
AccessViolation beim öffnen einer Com Verbindung
Wenn ich mit diesem Code:
Delphi-Quellcode:
...versuche eine RS232 Verbindung herstellen knallts in der Zeile : RS2321.Connect;
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; Die Connect Funktion sieht folgendermaßen aus:
Delphi-Quellcode:
(Für die die es wissen wollen die Exception tritt genau bei pop esi auf)
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; In einer anderen Anwendung funktioniert alles...ohne Exception. Hoffe ihr könnt mir helfen. Mfg Tobi |
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?
|
Re: AccessViolation beim öffnen einer Com Verbindung
Liste der Anhänge anzeigen (Anzahl: 1)
Klaro ;-)
//edit
Delphi-Quellcode:
hier knallts...
FDatainbuffer('A');
|
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 |
Re: AccessViolation beim öffnen einer Com Verbindung
Ist der FDataInBuffer irgendwo instantiiert worden?
[edit] .. aber wenn Du ihn eh nicht brauchst.. Grüße Klaus |
Re: AccessViolation beim öffnen einer Com Verbindung
und an welcher Stelle in FDataInBuffer? Oder knallts schon beim Aufruf der Funktion (wäre eher unwahrscheinlich)
|
Re: AccessViolation beim öffnen einer Com Verbindung
Zitat:
|
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.
|
Re: AccessViolation beim öffnen einer Com Verbindung
Delphi-Quellcode:
Weitere Verknüpfungen/Vorkommnisse gibts nicht - :stupid: ok es war kein Wunder - es wurde eine Prozedur aufgerufen die ins leere liefTDataInBuffer = procedure(buffer:char) of object; ... protected FDataInBuffer : TDataInBuffer; ... public ... property OnDataInBuffer: TDataInBuffer read FDataInBuffer write FDataInBuffer; |
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