libnodave readbyte > MAXPDU

jangbu

Level-1
Beiträge
12
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo,

kann mir jemand sagen, wie ich mit nodave.readbyte mehr als 200 Bytes einlesen kann. Ich muss einen größeren Block Realwerte einlesen und ab 200 Byte liest readbyte nur noch Mist.

Danke
jangbu
 
Wenn du mit einer Anfrage mehr Daten aus der SPS holen willst, musst du ReadmanyBytes verwenden. Readmanybytes liest die daten dann mit mehreren Aufrufen(je nach max PDU-Größe) von der SPS.
 
Schau doch mal in die Komponente von Axel, die liegt ja offen bei. Der hat das in etwa so gelöst:

PHP:
procedure DoReadBytes(Buffer: Pointer = Nil; SPS: Integer = 1; Size: Integer = 1024);
procedure DoWriteBytes(Buffer: Pointer = Nil; SPS: Integer = 1);

//Read the PLC-data into the buffer.
//~param Area Requested PLC-area.
//~param DB Number of requested datablock. Only used, if reading from Datablocks in the PLC.
//~param Start Start-address of the requested data within the address-range of the PLC.
//~param Size Length of the requested PLC-data in bytes.
//~param Buffer Pointer to the buffer. The internal buffer of the instance is used, if Nil (default).
procedure TNoDave.DoReadBytes(Area: TNoDaveArea; DB, Start, Size: Integer; Buffer: Pointer);
var
  Index, Length, MaxLen: Integer;
  StartTime: Cardinal;
begin
  Index:=0;
  StartTime:=GetTickCount;
  MaxLen:=MaxPDUData;
  While (Index < Size) and (MaxLen > 0) do
  begin
    Length:=(Size - Index);
    If Length > MaxLen then Length:=MaxLen;
    try
      LockNoDave.Enter;
      FLastError:=daveReadBytes(DaveConn, AreaCode(Area), DB, Index+Start, Size, Pointer(Integer(Buffer) + Index));
    except
      On E: Exception do DoOnError('Error in function TNoDave.DoReadBytes: ' + E.Message);
    end;
    LockNoDave.Leave;
    Inc(Index, Length);
  end;
  try
    FCycleTime:=GetTickCount - StartTime;
  except
  end;
end;

//Write the Buffer-data into the PLC.
//~param Area Requested PLC-area.
//~param DB Number of requested datablock. Only used, if reading from Datablocks in the PLC.
//~param Start Start-address of the requested data within the address-range of the PLC.
//~param Size Length of the requested PLC-data in bytes.
//~param Buffer Pointer to the buffer. The internal buffer of the instance is used, if Nil (default).
procedure TNoDave.DoWriteBytes(Area: TNoDaveArea; DB, Start, Size: Integer; Buffer: Pointer);
var
  Index, Length, MaxLen: Integer;
begin
  Index:=0;
  MaxLen:=MaxPDUData-4;
  While (Index < Size) and (MaxLen > 0) do
  begin
    Length:=(Size - Index);
    If Length > MaxLen then Length:=MaxLen;
    try
      LockNoDave.Enter;
      FLastError:=daveWriteBytes(DaveConn, AreaCode(Area), DB, Index+Start, Size, Pointer(Integer(Buffer) + Index));
    except
      On E: Exception do DoOnError('Error in function TNoDave.DoWriteBytes: ' + E.Message);
    end;
    LockNoDave.Leave;
    Inc(Index, Length);
  end;
end;
 
Zurück
Oben