Ignore:
Timestamp:
Feb 8, 2011, 11:02:02 AM (13 years ago)
Author:
george
Message:
Location:
PinConnection
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • PinConnection

    • Property svn:ignore
      •  

        old new  
        11lib
         2backup
  • PinConnection/UPacketBurst.pas

    r129 r163  
    66
    77uses
    8   Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils;
     8  Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils,
     9  UMicroThreading, DateUtils;
    910
    1011type
    1112  TPacketBurst = class;
    1213
    13   TPacketBurstSendThread = class(TThread)
     14  TPacketBurstSendThread = class(TMicroThread)
    1415    PacketBurst: TPacketBurst;
    1516    procedure Execute; override;
    1617  end;
    1718
     19  { TPacketBurst }
     20
    1821  TPacketBurst = class
    1922  private
    20     SendThreadEvent: TEvent;
     23    FActive: Boolean;
     24    SendThreadEvent: TMicroThreadEvent;
    2125    SendThread: TPacketBurstSendThread;
    2226    SendStreamLock: TCriticalSection;
     
    2529    procedure PacketSingleReceive(Sender: TCommPin; Stream: TStream);
    2630    procedure PacketBurstReceive(Sender: TCommPin; Stream: TStream);
     31    procedure SetActive(const AValue: Boolean);
    2732  public
    28     SendPeriod: Integer; // ms
     33    SendPeriod: TDateTime;
    2934    SendBurstSize: Integer;
    3035    PacketSinglePin: TCommPin;
     
    3237    destructor Destroy; override;
    3338    constructor Create;
     39    property Active: Boolean read FActive write SetActive;
    3440  end;
    3541
     
    4450  PacketBurstPin := TCommPin.Create;
    4551  PacketBurstPin.OnReceive := PacketBurstReceive;
    46   SendThread := TPacketBurstSendThread.Create(True);
    47   SendThread.PacketBurst := Self;
    48   SendThread.Start;
     52  SendThread := TMicroThreadEvent.Create;
     53  SendPeriod := OneMillisecond;
    4954end;
    5055
    5156destructor TPacketBurst.Destroy;
    5257begin
    53   SendThread.Free;
     58  Active := False;
     59  SendThreadEvent.Free;
    5460  PacketSinglePin.Free;
    5561  PacketBurstPin.Free;
     
    7985end;
    8086
     87procedure TPacketBurst.SetActive(const AValue: Boolean);
     88begin
     89  if FActive = AValue then Exit;
     90  FActive := AValue;
     91  if AValue then begin
     92    SendThread := TPacketBurstSendThread.Create(True);
     93    SendThread.FreeOnTerminate := False;
     94    SendThread.PacketBurst := Self;
     95    SendThread.Name := 'PacketBurst';
     96    SendThread.Start;
     97  end else begin
     98    FreeAndNil(SendThread);
     99  end;
     100end;
     101
    81102procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: TStream);
    82103var
     
    101122  Stream: TStreamHelper;
    102123begin
    103   inherited;
    104   try
    105124  try
    106125    Stream := TStreamHelper.Create;
     
    127146    Stream.Free;
    128147  end;
    129   except
    130     on E: Exception do
    131       if Assigned(ExceptionHandler) then ExceptionHandler(Self, E);
    132   end;
    133148end;
    134149
Note: See TracChangeset for help on using the changeset viewer.