Ignore:
Timestamp:
Aug 14, 2012, 10:31:30 AM (12 years ago)
Author:
chronos
Message:
  • Modified: PinConnection package now use for data parameters TListByte instead of TStream class contained in TemplateGenerics package. TStream have Position property which has no meaning for forwarding plain byte memory block. There is TBinarySerializer class used for serializing data instead of TStreamHelper class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/UCommSerialPort.pas

    r288 r407  
    66
    77uses
    8   Classes, USerialPort, UCommPin, SysUtils, DateUtils,
     8  Classes, USerialPort, UCommPin, SysUtils, DateUtils, SpecializedList,
    99  SyncObjs;
    1010
     
    1515  TCommSerialPort = class(TSerialPort)
    1616  private
    17     procedure Receive(Sender: TCommPin; Stream: TStream);
     17    procedure Receive(Sender: TCommPin; Stream: TListByte);
    1818    procedure SetStatus(Sender: TCommPin; AValue: Integer);
    19     procedure ReceiveData(Stream: TMemoryStream);
     19    procedure ReceiveData(Stream: TListByte);
    2020  public
    2121    Lock: TCriticalSection;
     
    3131{ TCommSerialPort }
    3232
    33 procedure TCommSerialPort.ReceiveData(Stream: TMemoryStream);
     33procedure TCommSerialPort.ReceiveData(Stream: TListByte);
    3434begin
    3535  if Active then Pin.Send(Stream);
     
    6464end;
    6565
    66 procedure TCommSerialPort.Receive(Sender: TCommPin; Stream: TStream);
     66procedure TCommSerialPort.Receive(Sender: TCommPin; Stream: TListByte);
     67var
     68  S: TMemoryStream;
    6769begin
    68   if Active then begin
    69     Stream.Position := 0;
    70     repeat
    71       try
    72         Lock.Acquire;
    73         if CanWrite(0) then
    74           SendStreamRaw(Stream);
    75       finally
    76         Lock.Release;
    77       end;
    78       if Stream.Position <> Stream.Size then
    79         Sleep(1);
    80     until Stream.Position = Stream.Size;
     70  try
     71    S := TMemoryStream.Create;
     72    Stream.WriteToStream(S);
     73    if Active then begin
     74      S.Position := 0;
     75      repeat
     76        try
     77          Lock.Acquire;
     78          if CanWrite(0) then
     79            SendStreamRaw(S);
     80        finally
     81          Lock.Release;
     82        end;
     83        if S.Position <> S.Size then
     84          Sleep(1);
     85      until S.Position = S.Size;
     86    end;
     87  finally
     88    S.Free;
    8189  end;
    8290end;
Note: See TracChangeset for help on using the changeset viewer.