Changeset 407 for PinConnection


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.
Location:
PinConnection
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/PinConnection.lpk

    r340 r407  
    2222    <License Value="GNU/GPL"/>
    2323    <Version Minor="3"/>
    24     <Files Count="11">
     24    <Files Count="13">
    2525      <Item1>
    2626        <Filename Value="UCommFrame.pas"/>
     
    6565      <Item11>
    6666        <Filename Value="UCommTCPServer.pas"/>
    67         <UnitName Value="UCommSocket"/>
     67        <UnitName Value="UCommTCPServer"/>
    6868      </Item11>
     69      <Item12>
     70        <Filename Value="UCommTelnet.pas"/>
     71        <UnitName Value="UCommTelnet"/>
     72      </Item12>
     73      <Item13>
     74        <Filename Value="UCommTelnetComPortOption.pas"/>
     75        <UnitName Value="UCommTelnetComPortOption"/>
     76      </Item13>
    6977    </Files>
    7078    <i18n>
  • PinConnection/PinConnection.pas

    r340 r407  
    33 }
    44
    5 unit PinConnection; 
     5unit PinConnection;
    66
    77interface
     
    1010  UCommFrame, UCommHub, UCommPin, UCommSerialPort, UCommThread, UPacketBurst,
    1111  USerialPort, UCommConcentrator, UCommDelay, UCommTCPClient, UCommTCPServer,
    12   LazarusPackageIntf;
     12  UCommTelnet, UCommTelnetComPortOption, LazarusPackageIntf;
    1313
    1414implementation
    1515
    16 procedure Register; 
     16procedure Register;
    1717begin
    18 end; 
     18end;
    1919
    2020initialization
    21   RegisterPackage('PinConnection', @Register); 
     21  RegisterPackage('PinConnection', @Register);
    2222end.
  • PinConnection/UCommConcentrator.pas

    r289 r407  
    99
    1010uses
    11   Classes, SysUtils, Contnrs, UCommPin;
     11  Classes, SysUtils, Contnrs, UCommPin, SpecializedList;
    1212
    1313type
     
    3131    FPins: TPinList;
    3232    FMain: TCommPin;
    33     procedure MainReceive(Sender: TCommPin; Stream: TStream);
     33    procedure MainReceive(Sender: TCommPin; Stream: TListByte);
    3434    procedure MainSetStatus(Sender: TCommPin; Status: Integer);
    35     procedure Receive(Sender: TCommPin; Stream: TStream);
     35    procedure Receive(Sender: TCommPin; Stream: TListByte);
    3636    procedure SetStatus(Sender: TCommPin; Status: Integer);
    3737  public
     
    7575{ TCommConcentrator }
    7676
    77 procedure TCommConcentrator.MainReceive(Sender: TCommPin; Stream: TStream);
     77procedure TCommConcentrator.MainReceive(Sender: TCommPin; Stream: TListByte);
    7878var
    7979  I: Integer;
     
    9999end;
    100100
    101 procedure TCommConcentrator.Receive(Sender: TCommPin; Stream: TStream);
     101procedure TCommConcentrator.Receive(Sender: TCommPin; Stream: TListByte);
    102102begin
    103103  if FActive then FMain.Send(Stream);
  • PinConnection/UCommDelay.pas

    r302 r407  
    66
    77uses
    8   Classes, SysUtils, UCommPin, UThreading, SyncObjs, SpecializedList, UStreamHelper;
     8  Classes, SysUtils, UCommPin, UThreading, SyncObjs, SpecializedList, UStreamHelper,
     9  UBinarySerializer;
    910
    1011type
     
    1516  TDelayedPacket = class
    1617    ReceiveTime: TDateTime;
    17     Data: TStreamHelper;
     18    Data: TListByte;
    1819    constructor Create;
    1920    destructor Destroy; override;
     
    4041    Thread1: TCommDelayThread;
    4142    Thread2: TCommDelayThread;
    42     procedure ReceiveData1(Sender: TCommPin; AStream: TStream);
    43     procedure ReceiveData2(Sender: TCommPin; AStream: TStream);
     43    procedure ReceiveData1(Sender: TCommPin; AStream: TListByte);
     44    procedure ReceiveData2(Sender: TCommPin; AStream: TListByte);
    4445    procedure SetActive(AValue: Boolean);
    4546  public
     
    6263  I: Integer;
    6364  CurrentTime: TDateTime;
    64   SendData: TStreamHelper;
     65  SendData: TListByte;
    6566  DoSleep: Boolean;
    6667begin
    6768  try
    68     SendData := TStreamHelper.Create;
     69    SendData := TListByte.Create;
    6970    repeat
    7071      DoSleep := True;
     
    7677            if TDelayedPacket(PacketQueue[I]).ReceiveTime < (CurrentTime - Parent.Delay) then begin
    7778              DoSleep := False;
    78               SendData.Clear;
    79               SendData.WriteStream(TDelayedPacket(PacketQueue[I]).Data, TDelayedPacket(PacketQueue[I]).Data.Size);
     79              SendData.Assign(TDelayedPacket(PacketQueue[I]).Data);
    8080              PacketQueue.Delete(I);
    8181              try
    8282                Lock.Release;
    83                 Pin.Send(SendData.Stream);
     83                Pin.Send(SendData);
    8484              finally
    8585                Lock.Acquire;
     
    100100constructor TDelayedPacket.Create;
    101101begin
    102   Data := TStreamHelper.Create;
     102  Data := TListByte.Create;
    103103end;
    104104
     
    111111{ TCommDelay }
    112112
    113 procedure TCommDelay.ReceiveData1(Sender: TCommPin; AStream: TStream);
     113procedure TCommDelay.ReceiveData1(Sender: TCommPin; AStream: TListByte);
    114114begin
    115115  try
     
    119119    with TDelayedPacket(PacketQueue2.AddNew(TDelayedPacket.Create)) do begin
    120120      ReceiveTime := Now;
    121       Data.WriteStream(AStream, AStream.Size);
     121      Data.Assign(AStream);
    122122    end;
    123123  finally
     
    126126end;
    127127
    128 procedure TCommDelay.ReceiveData2(Sender: TCommPin; AStream: TStream);
     128procedure TCommDelay.ReceiveData2(Sender: TCommPin; AStream: TListByte);
    129129begin
    130130  try
     
    134134    with TDelayedPacket(PacketQueue1.AddNew(TDelayedPacket.Create)) do begin
    135135      ReceiveTime := Now;
    136       Data.WriteStream(AStream, AStream.Size);
     136      Data.Assign(AStream);
    137137    end;
    138138  finally
  • PinConnection/UCommFrame.pas

    r299 r407  
    66
    77uses
    8   Classes, UStreamHelper, Dialogs, SysUtils,
     8  Classes, UStreamHelper, Dialogs, SysUtils, SpecializedList, UBinarySerializer,
    99  UCommPin;
    1010
     
    1717  private
    1818    LastCharIsSpecialChar: Boolean;
    19     ReceiveBuffer: TStreamHelper;
     19    ReceiveBuffer: TBinarySerializer;
    2020    FrameState: TFrameState;
    2121    FFrameErrorCount: Integer;
    2222    FCRCErrorCount: Integer;
    23     function GetStreamCRC8(Stream: TStream): Byte;
     23    function GetStreamCRC8(Stream: TListByte): Byte;
     24    procedure RawDataReceive(Sender: TCommPin; Stream: TListByte);
     25    procedure RawSetStatus(Sender: TCommPin; Status: Integer);
     26    procedure FrameDataReceive(Sender: TCommPin; Stream: TListByte);
     27    procedure FrameSetStatus(Sender: TCommPin; Status: Integer);
    2428  public
    2529    RawDataPin: TCommPin;
     
    3034    ControlCodeFrameEnd: Byte;
    3135    ControlCodeSpecialChar: Byte;
    32     procedure RawDataReceive(Sender: TCommPin; Stream: TStream);
    33     procedure RawSetStatus(Sender: TCommPin; Status: Integer);
    34     procedure FrameDataReceive(Sender: TCommPin; Stream: TStream);
    35     procedure FrameSetStatus(Sender: TCommPin; Status: Integer);
    36     function ComputeRawSize(DataStream: TStream): Integer;
     36    function ComputeRawSize(DataStream: TListByte): Integer;
    3737    constructor Create;
    3838    destructor Destroy; override;
     
    4848constructor TCommFrame.Create;
    4949begin
    50   ReceiveBuffer := TStreamHelper.Create;
     50  ReceiveBuffer := TBinarySerializer.Create;
     51  ReceiveBuffer.List := TListByte.Create;
     52  ReceiveBuffer.OwnsList := True;
    5153  RawDataPin := TCommPin.Create;
    5254  RawDataPin.OnReceive := RawDataReceive;
     
    6870end;
    6971
    70 procedure TCommFrame.FrameDataReceive(Sender: TCommPin; Stream: TStream);
    71 var
    72   RawData: TStreamHelper;
     72procedure TCommFrame.FrameDataReceive(Sender: TCommPin; Stream: TListByte);
     73var
     74  RawData: TBinarySerializer;
    7375  I: Integer;
    7476  Character: Byte;
     
    7678begin
    7779  // Write CRC code to end of frame
    78   Stream.Position := 0;
    7980  CRC := GetStreamCRC8(Stream);
    8081
    8182  // Byte stuffing
    82   Stream.Position := 0;
    8383  try
    84     RawData := TStreamHelper.Create;
     84    RawData := TBinarySerializer.Create;
     85    RawData.List := TListByte.Create;
     86    RawData.OwnsList := True;
    8587    RawData.WriteByte(SpecialChar);
    8688    RawData.WriteByte(ControlCodeFrameStart);
    87     for I := 0 to Stream.Size - 1 do begin
    88       Character := Stream.ReadByte;
     89    for I := 0 to Stream.Count - 1 do begin
     90      Character := Stream[I];
    8991      if Character = SpecialChar then begin
    9092        RawData.WriteByte(SpecialChar);
     
    102104    RawData.WriteByte(ControlCodeFrameEnd);
    103105    if Random >= PacketLoss then
    104       RawDataPin.Send(RawData);
     106      RawDataPin.Send(RawData.List);
    105107
    106108  finally
     
    114116end;
    115117
    116 function TCommFrame.ComputeRawSize(DataStream: TStream): Integer;
     118function TCommFrame.ComputeRawSize(DataStream: TListByte): Integer;
     119var
     120  I: Integer;
    117121begin
    118122  Result := 5; // FrameStart + CRC + FrameEnd
    119   DataStream.Position := 0;
    120   while DataStream.Position < DataStream.Size do
    121     if DataStream.ReadByte = SpecialChar then Inc(Result, 2)
     123  for I := 0 to DataStream.Count - 1 do
     124    if DataStream[I] = SpecialChar then Inc(Result, 2)
    122125      else Inc(Result, 1);
    123126end;
    124127
    125 procedure TCommFrame.RawDataReceive(Sender: TCommPin; Stream: TStream);
     128procedure TCommFrame.RawDataReceive(Sender: TCommPin; Stream: TListByte);
    126129var
    127130  Character: Byte;
     
    130133  I: Integer;
    131134begin
    132   for I := 0 to Stream.Size - 1 do begin
    133     Character := Stream.ReadByte;
     135  for I := 0 to Stream.Count - 1 do begin
     136    Character := Stream[I];
    134137    if LastCharIsSpecialChar then begin
    135138      if Character = ControlCodeSpecialChar then begin
     
    139142          if FrameState = fsInside then
    140143            Inc(FFrameErrorCount);
    141           ReceiveBuffer.Size := 0;
     144          ReceiveBuffer.List.Count := 0;
     145          ReceiveBuffer.Position := 0;
    142146          FrameState := fsInside;
    143147        end else
     
    145149          if FrameState = fsInside then begin
    146150            // Check CRC
    147             if ReceiveBuffer.Size > 0 then begin
    148               ReceiveBuffer.Position := ReceiveBuffer.Size - 1;
     151            if ReceiveBuffer.List.Count > 0 then begin
     152              ReceiveBuffer.Position := ReceiveBuffer.List.Count - 1;
    149153              CRC := ReceiveBuffer.ReadByte;
    150               ReceiveBuffer.Size := ReceiveBuffer.Size - 1;
    151               ExpectedCRC := GetStreamCRC8(ReceiveBuffer);
     154              ReceiveBuffer.List.Count := ReceiveBuffer.List.Count - 1;
     155              ExpectedCRC := GetStreamCRC8(ReceiveBuffer.List);
    152156
    153157              if ExpectedCRC <> CRC then Inc(FCRCErrorCount)
    154158                else begin
    155159                  //if Random >= PacketLoss then
    156                     FrameDataPin.Send(ReceiveBuffer);
     160                    FrameDataPin.Send(ReceiveBuffer.List);
    157161                end;
    158162            end else Inc(FCRCErrorCount);
     
    173177end;
    174178
    175 function TCommFrame.GetStreamCRC8(Stream: TStream): Byte;
     179function TCommFrame.GetStreamCRC8(Stream: TListByte): Byte;
    176180var
    177181  I: Integer;
     
    182186begin
    183187  Pom := 0;
    184   Stream.Position := 0;
    185188  Result := 0;
    186   for I := 0 to Stream.Size - 1 do begin
    187     Stream.Read(Pom, 1);
     189  for I := 0 to Stream.Count - 1 do begin
     190    Pom := Stream[I];
    188191    for B := 0 to 7 do begin
    189       if ((Result xor Pom) and 1) = 1 then Result := ((Result xor Polynom) shr 1) or $80
     192      if ((Result xor Pom) and 1) = 1 then
     193        Result := ((Result xor Polynom) shr 1) or $80
    190194        else Result := Result shr 1;
    191195      Pom := (Pom shr 1) or ((Pom shl 7) and $80); // Rotace vpravo
  • PinConnection/UCommHub.pas

    r289 r407  
    66
    77uses
    8   Classes, SysUtils, Contnrs, UCommPin;
     8  Classes, SysUtils, Contnrs, UCommPin, SpecializedList;
    99
    1010type
     
    2727    FActive: Boolean;
    2828    FPins: TPinList;
    29     procedure Receive(Sender: TCommPin; Stream: TStream);
     29    procedure Receive(Sender: TCommPin; Stream: TListByte);
    3030    procedure SetStatus(Sender: TCommPin; Status: Integer);
    3131  public
     
    6868{ TCommHub }
    6969
    70 procedure TCommHub.Receive(Sender: TCommPin; Stream: TStream);
     70procedure TCommHub.Receive(Sender: TCommPin; Stream: TListByte);
    7171var
    7272  I: Integer;
  • PinConnection/UCommPin.pas

    r288 r407  
    66
    77uses
    8   Classes;
     8  Classes, SpecializedList;
    99
    1010type
     
    1212
    1313  TDataDiretion = (ddReceive, ddSend);
    14   TOnLogDataEvent = procedure (Stream: TStream; Direction: TDataDiretion) of object;
    15   TOnStreamEvent = procedure (Sender: TCommPin; Stream: TStream) of object;
     14  TOnLogDataEvent = procedure (Stream: TListByte; Direction: TDataDiretion) of object;
     15  TOnStreamEvent = procedure (Sender: TCommPin; Stream: TListByte) of object;
    1616  TOnSetStatus = procedure (Sender: TCommPin; Status: Integer) of object;
    1717
     
    3131    procedure SetStatus(AValue: Integer);
    3232  protected
    33     procedure Receive(Stream: TStream);
     33    procedure Receive(Stream: TListByte);
    3434    procedure ReceiveStatus(AValue: Integer);
    3535  public
     
    3939    procedure Connect(Pin: TCommPin);
    4040    procedure Disconnect;
    41     procedure Send(Stream: TStream);
     41    procedure Send(Stream: TListByte);
    4242    procedure ResetCounters;
    4343    property Connected: Boolean read GetConnected;
     
    100100end;
    101101
    102 procedure TCommPin.Receive(Stream: TStream);
     102procedure TCommPin.Receive(Stream: TListByte);
    103103begin
    104   Inc(FDataRxCount, Stream.Size);
     104  Inc(FDataRxCount, Stream.Count);
    105105  Inc(FFrameRxCount);
    106106  if Assigned(FOnLogData) then FOnLogData(Stream, ddReceive);
    107   Stream.Position := 0;
    108107  if Assigned(FOnReceive) then FOnReceive(Self, Stream);
    109108end;
     
    122121end;
    123122
    124 procedure TCommPin.Send(Stream: TStream);
     123procedure TCommPin.Send(Stream: TListByte);
    125124begin
    126   Inc(FDataTxCount, Stream.Size);
     125  Inc(FDataTxCount, Stream.Count);
    127126  Inc(FFrameTxCount);
    128127  if Assigned(FOnLogData) then FOnLogData(Stream, ddSend);
  • 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;
  • PinConnection/UCommTCPClient.pas

    r339 r407  
    77uses
    88  Classes, SysUtils, blcksock, synsock, UCommPin, UCommon, UThreading,
    9   DateUtils;
     9  DateUtils, SpecializedList;
    1010
    1111type
     
    1919  public
    2020    Parent: TCommTCPClient;
    21     Stream: TMemoryStream;
     21    Stream: TListByte;
    2222    procedure Execute; override;
    2323    constructor Create(CreateSuspended: Boolean;
     
    3333    FOnReceiveData: TReceiveDataEvent;
    3434    FReceiveThread: TCommSocketReceiveThread;
    35     procedure ReceiveData(Sender: TCommPin; Stream: TStream);
     35    procedure ReceiveData(Sender: TCommPin; Stream: TListByte);
    3636    procedure SetActive(const AValue: Boolean);
    3737  public
     
    5353{ TCommTCPClient }
    5454
    55 procedure TCommTCPClient.ReceiveData(Sender: TCommPin; Stream:TStream);
     55procedure TCommTCPClient.ReceiveData(Sender: TCommPin; Stream: TListByte);
     56var
     57  Mem: TMemoryStream;
    5658begin
    5759  if FActive then begin
    58     Socket.SendStreamRaw(Stream);
     60    try
     61      Mem := TMemoryStream.Create;
     62      Stream.WriteToStream(Mem);
     63      Socket.SendStreamRaw(Mem);
     64    finally
     65      Mem.Free;
     66    end;
    5967  end;
    6068end;
     
    120128          RecvBuffer(Buffer, Length(Buffer));
    121129
    122           Stream.Size := Length(Buffer);
    123           Stream.Position := 0;
    124           Stream.Write(Buffer[0], Length(Buffer));
     130          Stream.Count := Length(Buffer);
     131          Stream.ReplaceBuffer(0, Pointer(Buffer)^, Length(Buffer));
    125132          Pin.Send(Stream);
    126133        end else InBufferUsed := 0;
     
    134141begin
    135142  inherited;
    136   Stream := TMemoryStream.Create;
     143  Stream := TListByte.Create;
    137144end;
    138145
  • PinConnection/UCommTCPServer.pas

    r339 r407  
    77uses
    88  Classes, SysUtils, blcksock, synsock, UCommPin, UCommon, UThreading,
    9   DateUtils, SpecializedList;
     9  DateUtils, SpecializedList, tlntsend;
    1010
    1111type
     
    1919  public
    2020    Parent: TCommTCPServer;
    21     Stream: TMemoryStream;
     21    Stream: TListByte;
    2222    procedure Execute; override;
    2323    constructor Create(CreateSuspended: Boolean;
     
    3232  TCommTCPServerSession = class
    3333  private
    34     procedure ReceiveData(Sender: TCommPin; Stream: TStream);
     34    procedure ReceiveData(Sender: TCommPin; Stream: TListByte);
    3535  public
    3636    Server: TCommTCPServer;
     
    6767{ TCommTCPServerSession }
    6868
    69 procedure TCommTCPServerSession.ReceiveData(Sender: TCommPin; Stream: TStream);
    70 begin
    71   Socket.SendStreamRaw(Stream);
     69procedure TCommTCPServerSession.ReceiveData(Sender: TCommPin; Stream: TListByte);
     70var
     71  Mem: TMemoryStream;
     72begin
     73  try
     74    Mem := TMemoryStream.Create;
     75    Stream.WriteToStream(Mem);
     76    Socket.SendStreamRaw(Mem);
     77  finally
     78    Mem.Free;
     79  end;
    7280end;
    7381
     
    130138          //if Socket.Socket = INVALID_SOCKET then Break;
    131139
    132           Stream.Size := Length(Buffer);
    133           Stream.Position := 0;
    134           Stream.Write(Buffer[0], Length(Buffer));
     140          Stream.Count := Length(Buffer);
     141          Stream.ReplaceBuffer(0, PByte(Buffer)^, Length(Buffer));
    135142          Pin.Send(Stream);
    136143          DoSleep := False;
     
    146153begin
    147154  inherited;
    148   Stream := TMemoryStream.Create;
     155  Stream := TListByte.Create;
    149156end;
    150157
  • PinConnection/UCommThread.pas

    r384 r407  
    77uses
    88  Classes, SysUtils, blcksock, UCommPin, SyncObjs, UStreamHelper, UCommon,
    9   DateUtils, UThreading;
     9  DateUtils, UThreading, SpecializedList, UBinarySerializer;
    1010
    1111type
     
    1919  public
    2020    Parent: TCommThread;
    21     Stream: TStreamHelper;
     21    Stream: TBinarySerializer;
    2222    procedure Execute; override;
    2323    constructor Create(CreateSuspended: Boolean;
     
    3333    FOnReceiveData: TReceiveDataEvent;
    3434    FReceiveThread: TCommThreadReceiveThread;
    35     FInputBuffer: TMemoryStream;
     35    FInputBuffer: TBinarySerializer;
    3636    FInputBufferLock: TCriticalSection;
    3737    FDataAvailable: TEvent;
    3838    FStatusEvent: TEvent;
    3939    FStatusValue: Integer;
    40     procedure PinReceiveData(Sender: TCommPin; Stream: TStream);
     40    procedure PinReceiveData(Sender: TCommPin; Stream: TListByte);
    4141    procedure PinSetStatus(Sender: TCommPin; Status: Integer);
    42     procedure ExtReceiveData(Sender: TCommPin; Stream: TStream);
     42    procedure ExtReceiveData(Sender: TCommPin; Stream: TListByte);
    4343    procedure ExtSetStatus(Sender: TCommPin; AStatus: Integer);
    4444    procedure SetActive(const AValue: Boolean);
     
    5555{ TCommThread }
    5656
    57 procedure TCommThread.PinReceiveData(Sender: TCommPin; Stream:TStream);
     57procedure TCommThread.PinReceiveData(Sender: TCommPin; Stream: TListByte);
    5858begin
    5959  if FActive then Ext.Send(Stream);
     
    6565end;
    6666
    67 procedure TCommThread.ExtReceiveData(Sender: TCommPin; Stream: TStream);
    68 var
    69   StreamHelper: TStreamHelper;
     67procedure TCommThread.ExtReceiveData(Sender: TCommPin; Stream: TListByte);
    7068begin
    7169  try
    72     StreamHelper := TStreamHelper.Create(FInputBuffer);
    7370    FInputBufferLock.Acquire;
    74     StreamHelper.WriteStream(Stream, Stream.Size);
     71    FInputBuffer.WriteList(Stream, 0, Stream.Count);
    7572    FDataAvailable.SetEvent;
    7673  finally
    7774    FInputBufferLock.Release;
    78     StreamHelper.Free;
    7975  end;
    8076end;
     
    110106begin
    111107  inherited Create;
    112   FInputBuffer := TMemoryStream.Create;
     108  FInputBuffer := TBinarySerializer.Create;
     109  FInputBuffer.List := TListByte.Create;
     110  FInputBuffer.OwnsList := True;
    113111  FInputBufferLock := TCriticalSection.Create;
    114112  Ext := TCommPin.Create;
     
    150148      try
    151149        FInputBufferLock.Acquire;
    152         Stream.Size := 0;
    153         Stream.WriteStream(FInputBuffer, FInputBuffer.Size);
     150        Stream.List.Assign(FInputBuffer.List);
    154151        FDataAvailable.ResetEvent;
    155152        FInputBuffer.Clear;
     
    157154        FInputBufferLock.Release;
    158155      end; // else Yield;
    159       Pin.Send(Stream);
     156      Pin.Send(Stream.List);
    160157    end;
    161158
     
    182179begin
    183180  inherited;
    184   Stream := TStreamHelper.Create;
     181  Stream := TBinarySerializer.Create;
     182  Stream.List := TListByte.Create;
     183  Stream.OwnsList := True;
    185184end;
    186185
  • PinConnection/UPacketBurst.pas

    r231 r407  
    66
    77uses
    8   Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils,
    9   DateUtils;
     8  Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils, SpecializedList,
     9  DateUtils, UBinarySerializer;
    1010
    1111type
     
    2525    SendThread: TPacketBurstSendThread;
    2626    SendStreamLock: TCriticalSection;
    27     SendStream: TStreamHelper;
    28     ReceiveStream: TStreamHelper;
    29     procedure PacketSingleReceive(Sender: TCommPin; Stream: TStream);
    30     procedure PacketBurstReceive(Sender: TCommPin; Stream: TStream);
     27    SendStream: TBinarySerializer;
     28    ReceiveStream: TBinarySerializer;
     29    procedure PacketSingleReceive(Sender: TCommPin; Stream: TListByte);
     30    procedure PacketBurstReceive(Sender: TCommPin; Stream: TListByte);
    3131    procedure SetActive(const AValue: Boolean);
    3232  public
     
    6363end;
    6464
    65 procedure TPacketBurst.PacketBurstReceive(Sender: TCommPin; Stream: TStream);
     65procedure TPacketBurst.PacketBurstReceive(Sender: TCommPin; Stream: TListByte);
    6666var
    67   PacketStream: TStreamHelper;
     67  PacketStream: TListByte;
    6868  Size: Word;
    6969begin
    7070  try
    71     PacketStream := TStreamHelper.Create;
    72     ReceiveStream.Seek(0, soFromEnd);
    73     ReceiveStream.WriteStream(Stream, Stream.Size);
     71    PacketStream := TListByte.Create;
     72    ReceiveStream.Position := ReceiveStream.List.Count;
     73    ReceiveStream.WriteList(Stream, 0, Stream.Count);
    7474    ReceiveStream.Position := 0;
    7575    Size := ReceiveStream.ReadWord;
    76     while Size < ReceiveStream.Size do begin
    77       PacketStream.Stream.Size := 0;
    78       PacketStream.ReadStream(TStream(ReceiveStream), Size);
     76    while Size < ReceiveStream.List.Count do begin
     77      PacketStream.Count := Size;
     78      ReceiveStream.ReadList(PacketStream, 0, Size);
    7979      PacketSinglePin.Send(PacketStream);
    8080      Size := ReceiveStream.ReadWord;
     
    100100end;
    101101
    102 procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: TStream);
     102procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: TListByte);
    103103var
    104104  SignalEvent: Boolean;
     
    106106  try
    107107    SendStreamLock.Acquire;
    108     SendStream.WriteWord(Stream.Size);
    109     Stream.Position := 0;
    110     SendStream.WriteStream(Stream, Stream.Size);
    111     SignalEvent := SendStream.Size > SendBurstSize;
     108    SendStream.WriteWord(Stream.Count);
     109    SendStream.WriteList(Stream, 0, Stream.Count);
     110    SignalEvent := SendStream.List.Count > SendBurstSize;
    112111  finally
    113112    SendStreamLock.Release;
     
    120119procedure TPacketBurstSendThread.Execute;
    121120var
    122   Stream: TStreamHelper;
     121  Stream: TListByte;
    123122begin
    124123  try
    125     Stream := TStreamHelper.Create;
     124    Stream := TListByte.Create;
    126125    with PacketBurst do
    127126    repeat
     
    130129        SendStreamLock.Acquire;
    131130        SendStream.Position := 0;
    132         if SendStream.Size < SendBurstSize then begin
    133           PacketBurstPin.Send(SendStream);
    134           SendStream.Stream.Size := 0;
     131        if SendStream.List.Count < SendBurstSize then begin
     132          PacketBurstPin.Send(SendStream.List);
     133          SendStream.List.Count := 0;
    135134        end else
    136         while (SendStream.Size - SendStream.Position) > SendBurstSize do begin
    137           Stream.Stream.Size := 0;
     135        while (SendStream.List.Count - SendStream.Position) > SendBurstSize do begin
     136          Stream.Count := 0;
    138137          SendStream.ReadStream(TStream(Stream), SendBurstSize);
    139138          PacketBurstPin.Send(Stream);
  • 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.