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