Thema: Delphi Exeption bei ReadCom

Einzelnen Beitrag anzeigen

Gehstock

Registriert seit: 28. Jan 2006
Ort: Görlitz / Sachsen
489 Beiträge
 
Delphi 2007 Professional
 
#1

Exeption bei ReadCom

  Alt 14. Mai 2009, 20:45
Zitat:
---------------------------
Apoxiutils1
---------------------------
Access violation at address 00405750 in module 'APOXIutils1.exe'. Write of address 0006004F.
---------------------------
OK
---------------------------

Delphi-Quellcode:
var
i : Integer;
c : Array of Byte;
begin
  SetLength(c,10);
   WriteCom(@Start,sizeOf(Start));
     if not ReadCom(@c,9) then//****hier nicht
      WriteCom(@Start3,sizeOf(Start3))
     else
      WriteCom(@Start2,sizeOf(Start2));
        if not ReadCom(@c,9) then//****aber hier
         AddLinesLOG(3,'Nicht erfolgt');
end;
die Com Funktionen

Delphi-Quellcode:
function ReadCom(Buf:Pointer; BufLen :Dword) : boolean;
var
 dErr: Dword;
begin
 result := False;
 if (hCom<>INVALID_HANDLE_VALUE)and(Buf<>Nil)and(BufLen<>0) then begin
  rxlen:=0;
  if FlgOvrlp then begin
   COMrd.hEvent:=CreateEvent(Nil,TRUE,FALSE,Nil);
   if not ReadFile(hCom,Buf^,BufLen,rxLen,@COMrd) then begin
    if not GetOverlappedResult(hCom,COMrd,rxLen,True) then begin
    end;
   end;
// ResetEvent(COMrd.hEvent);
   CloseHandle(COMrd.hEvent);
  end
  else begin
   if not ReadFile(hCom,Buf^,BufLen,rxLen,Nil) then begin
// ClearCommError(hCom,dErr,Nil);
// exit;
   end;
  end;
  if rxLen = BufLen then
  begin
  result := True;
// frmMain.AddTerminalLog(Buf,BufLen,'TX');
  end else ClearCommError(hCom,dErr,Nil);
 end;
end;

function WriteCom(Buf:Pointer; BufLen:Dword) : boolean;
Var
 dErr: Dword;
begin
 result:=FALSE;
 if (hCom<>INVALID_HANDLE_VALUE)and(Buf<>Nil)and(BufLen<>0) then begin
  txLen:=0;
  if FlgOvrlp then begin
   COMwr.hEvent:=CreateEvent(Nil,TRUE,FALSE,Nil);
   if not WriteFile(hCom,Buf^,BufLen,txLen,@COMwr) then begin
    if not GetOverlappedResult(hCom,COMwr,txLen,True) then begin
    end;
// ClearCommError(hCom,dErr,Nil);
   end;
// ResetEvent(COMwr.hEvent);
   CloseHandle(COMwr.hEvent);
  end
  else begin
   if not WriteFile(hCom,Buf^,BufLen,txLen,Nil) then begin
// ClearCommError(hCom,dErr,Nil);
// exit;
   end;
  end;
  if txLen = BufLen then result:=TRUE
  else ClearCommError(hCom,dErr,Nil);
 end;
end;
das ComLog

Zitat:
[14/05/2009 20:57:24] - Written data

41 54 0d AT.
41 54 23 00 58 00 67 42 fa e8 ce 72 29 33 0d AT#.X.gBúèÎr)3.

[14/05/2009 20:57:25] - Read data

57 00 06 00 4d 74 db b5 99 W...MtÛµ™
Es sieht also danach aus das das Auslesen klappt
Marcel
  Mit Zitat antworten Zitat