Changeset 288 for PinConnection/UCommThread.pas
- Timestamp:
- Oct 24, 2011, 9:01:08 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection/UCommThread.pas
r272 r288 36 36 FInputBufferLock: TCriticalSection; 37 37 FDataAvailable: TEvent; 38 procedure ReceiveData(Sender: TCommPin; Stream: TStream); 38 FStatusEvent: TEvent; 39 FStatusValue: Integer; 40 procedure PinReceiveData(Sender: TCommPin; Stream: TStream); 41 procedure PinSetStatus(Sender: TCommPin; Status: Integer); 39 42 procedure ExtReceiveData(Sender: TCommPin; Stream: TStream); 43 procedure ExtSetStatus(Sender: TCommPin; AStatus: Integer); 40 44 procedure SetActive(const AValue: Boolean); 41 45 public … … 51 55 { TCommThread } 52 56 53 procedure TCommThread. ReceiveData(Sender: TCommPin; Stream:TStream);57 procedure TCommThread.PinReceiveData(Sender: TCommPin; Stream:TStream); 54 58 begin 55 59 if FActive then Ext.Send(Stream); 60 end; 61 62 procedure TCommThread.PinSetStatus(Sender: TCommPin; Status: Integer); 63 begin 64 if FActive then Ext.Status := Status; 56 65 end; 57 66 … … 68 77 FInputBufferLock.Release; 69 78 StreamHelper.Free; 79 end; 80 end; 81 82 procedure TCommThread.ExtSetStatus(Sender: TCommPin; AStatus: Integer); 83 begin 84 try 85 FInputBufferLock.Acquire; 86 FStatusValue := AStatus; 87 FStatusEvent.SetEvent; 88 finally 89 FInputBufferLock.Release; 70 90 end; 71 91 end; … … 96 116 Ext := TCommPin.Create; 97 117 Ext.OnReceive := ExtReceiveData; 118 Ext.OnSetSatus := ExtSetStatus; 98 119 Pin := TCommPin.Create; 99 Pin.OnReceive := ReceiveData; 120 Pin.OnReceive := PinReceiveData; 121 Pin.OnSetSatus := PinSetStatus; 100 122 FDataAvailable := TSimpleEvent.Create; 123 FStatusEvent := TSimpleEvent.Create; 101 124 end; 102 125 … … 108 131 Ext.Free; 109 132 Pin.Free; 133 FStatusEvent.Free; 110 134 FDataAvailable.Free; 111 135 inherited Destroy; … … 119 143 with Parent do 120 144 repeat 145 // Check if new data arrived 121 146 if FDataAvailable.WaitFor(1) = wrSignaled then 122 147 try … … 130 155 FInputBufferLock.Release; 131 156 end; // else Yield; 157 158 // Check if state changed 159 if FStatusEvent.WaitFor(1) = wrSignaled then 160 try 161 FInputBufferLock.Acquire; 162 Pin.Status := FStatusValue; 163 finally 164 FStatusEvent.ResetEvent; 165 FInputBufferLock.Release; 166 end; 132 167 until Terminated; 133 168 finally
Note:
See TracChangeset
for help on using the changeset viewer.