Changeset 163 for PinConnection/UPacketBurst.pas
- Timestamp:
- Feb 8, 2011, 11:02:02 AM (13 years ago)
- Location:
- PinConnection
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection
- Property svn:ignore
-
old new 1 1 lib 2 backup
-
- Property svn:ignore
-
PinConnection/UPacketBurst.pas
r129 r163 6 6 7 7 uses 8 Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils; 8 Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils, 9 UMicroThreading, DateUtils; 9 10 10 11 type 11 12 TPacketBurst = class; 12 13 13 TPacketBurstSendThread = class(T Thread)14 TPacketBurstSendThread = class(TMicroThread) 14 15 PacketBurst: TPacketBurst; 15 16 procedure Execute; override; 16 17 end; 17 18 19 { TPacketBurst } 20 18 21 TPacketBurst = class 19 22 private 20 SendThreadEvent: TEvent; 23 FActive: Boolean; 24 SendThreadEvent: TMicroThreadEvent; 21 25 SendThread: TPacketBurstSendThread; 22 26 SendStreamLock: TCriticalSection; … … 25 29 procedure PacketSingleReceive(Sender: TCommPin; Stream: TStream); 26 30 procedure PacketBurstReceive(Sender: TCommPin; Stream: TStream); 31 procedure SetActive(const AValue: Boolean); 27 32 public 28 SendPeriod: Integer; // ms33 SendPeriod: TDateTime; 29 34 SendBurstSize: Integer; 30 35 PacketSinglePin: TCommPin; … … 32 37 destructor Destroy; override; 33 38 constructor Create; 39 property Active: Boolean read FActive write SetActive; 34 40 end; 35 41 … … 44 50 PacketBurstPin := TCommPin.Create; 45 51 PacketBurstPin.OnReceive := PacketBurstReceive; 46 SendThread := TPacketBurstSendThread.Create(True); 47 SendThread.PacketBurst := Self; 48 SendThread.Start; 52 SendThread := TMicroThreadEvent.Create; 53 SendPeriod := OneMillisecond; 49 54 end; 50 55 51 56 destructor TPacketBurst.Destroy; 52 57 begin 53 SendThread.Free; 58 Active := False; 59 SendThreadEvent.Free; 54 60 PacketSinglePin.Free; 55 61 PacketBurstPin.Free; … … 79 85 end; 80 86 87 procedure TPacketBurst.SetActive(const AValue: Boolean); 88 begin 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; 100 end; 101 81 102 procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: TStream); 82 103 var … … 101 122 Stream: TStreamHelper; 102 123 begin 103 inherited;104 try105 124 try 106 125 Stream := TStreamHelper.Create; … … 127 146 Stream.Free; 128 147 end; 129 except130 on E: Exception do131 if Assigned(ExceptionHandler) then ExceptionHandler(Self, E);132 end;133 148 end; 134 149
Note:
See TracChangeset
for help on using the changeset viewer.