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/USerialPort.pas

    r404 r407  
    77uses
    88  Classes, SysUtils, SynaSer, StdCtrls, Dialogs, UCommon, UThreading,
    9   DateUtils, FileUtil;
     9  DateUtils, FileUtil, SpecializedList;
    1010
    1111type
     
    1919
    2020  TSerialPort = class;
    21   TReceiveDataEvent = procedure(Stream: TMemoryStream) of object;
     21  TReceiveDataEvent = procedure(Stream: TListByte) of object;
    2222
    2323  { TSerialPortReceiveThread }
     
    4545    FStopBits: TStopBits;
    4646    FReceiveThread: TSerialPortReceiveThread;
    47     FReceiveBuffer: TMemoryStream;
     47    FReceiveBuffer: TListByte;
    4848    function GetBaudRateNumeric: Integer;
    4949    function GetName: string;
     
    7070    property RTS: Boolean read FRTS write SetRTS;
    7171    property DTR: Boolean read FDTR write SetDTR;
    72     property ReceiveBuffer: TMemoryStream read FReceiveBuffer;
     72    property ReceiveBuffer: TListByte read FReceiveBuffer;
    7373
    7474    property BaudRateNumeric: Integer read GetBaudRateNumeric write SetBaudRateNumeric;
     
    214214begin
    215215  inherited Create;
    216   FReceiveBuffer := TMemoryStream.Create;
     216  FReceiveBuffer := TListByte.Create;
    217217  FBaudRate := br9600;
    218218  FName := 'COM1';
     
    335335  InBufferUsed: Integer;
    336336  Buffer: array of Byte;
     337  Read: Integer;
    337338begin
    338339  InBufferUsed := 0;
     
    344345        if InBufferUsed > 0 then begin
    345346          SetLength(Buffer, InBufferUsed);
    346           RecvBuffer(Buffer, Length(Buffer));
    347 
    348           Parent.FReceiveBuffer.Size := Length(Buffer);
    349           Parent.FReceiveBuffer.Position := 0;
    350           Parent.FReceiveBuffer.Write(Buffer[0], Length(Buffer));
     347          Read := RecvBuffer(Buffer, Length(Buffer));
     348          SetLength(Buffer, Read);
     349
     350          Parent.FReceiveBuffer.Count := Length(Buffer);
     351          Parent.FReceiveBuffer.ReplaceBuffer(0, PByte(Buffer)^, Length(Buffer));
    351352          if Assigned(Parent.FOnReceiveData) then
    352353            Parent.FOnReceiveData(Parent.FReceiveBuffer);
Note: See TracChangeset for help on using the changeset viewer.