Hi,
ich habe ein Problem mit dem ComConfigDialog, der sich bei mir einfach nicht öffnen will.
Meine serielle Schnittstelle steuere ich wie folgt an:
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:
| function TRS232.OpenComPort(): boolean; var TimeOuts : TCommTimeOuts; begin Result := false; if CConn then exit; StrPCopy(CNumm,'COM' + IntToStr(PortNum)); CHandle := CreateFile(CNumm, Generic_Read or Generic_Write, 0 , nil, OPEN_EXISTING, 0, 0); if CHandle <> Invalid_Handle_Value then begin CConn:= true; SetupComm(CHandle,1,1); SetCommState(CHandle, CConf.DCB); GetCommTimeouts(CHandle,Timeouts); TimeOuts.ReadIntervalTimeout := 100; Timeouts.ReadTotalTimeoutMultiplier:= 100; Timeouts.ReadTotalTimeoutConstant:= 0; TimeOuts.WriteTotalTimeoutMultiplier := 100; TimeOuts.WriteTotalTimeoutConstant := 0; SetCommTimeouts(CHandle,Timeouts); Result := true; end; end;
procedure TRS232.CloseComPort(); begin if CConn then begin PurgeComm (CHandle,PURGE_RXABORT or PURGE_RXCLEAR or PURGE_TXABORT or PURGE_TXCLEAR); CloseHandle(CHandle); end; CConn := false; end; |
Wenn ich vor dem ersten Öffnen mit "OpenComPort" den Befehl:
CommConfigDialog(CNumm,CHandle,CConf) ausführe, klappt das einwandfrei. Habe ich aber zur Laufzeit meines Programms die Schnittstelle offen gehabt und sie wieder mit "CloseComPort" geschlossen, gibt mir der "CommConfigDialog" als Fehlermeldung 1223 (ERROR_CANCELLED) zurück. Was mache ich falsch bzw. was habe ich in CloseComPort vergessen?