Ignore:
Timestamp:
Oct 24, 2011, 9:01:08 AM (13 years ago)
Author:
george
Message:
  • Added: TCommPin now support state number forwarding. State value is designed mainly for simulating parity bit and possibly other state bits.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/UCommThread.pas

    r272 r288  
    3636    FInputBufferLock: TCriticalSection;
    3737    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);
    3942    procedure ExtReceiveData(Sender: TCommPin; Stream: TStream);
     43    procedure ExtSetStatus(Sender: TCommPin; AStatus: Integer);
    4044    procedure SetActive(const AValue: Boolean);
    4145  public
     
    5155{ TCommThread }
    5256
    53 procedure TCommThread.ReceiveData(Sender: TCommPin; Stream:TStream);
     57procedure TCommThread.PinReceiveData(Sender: TCommPin; Stream:TStream);
    5458begin
    5559  if FActive then Ext.Send(Stream);
     60end;
     61
     62procedure TCommThread.PinSetStatus(Sender: TCommPin; Status: Integer);
     63begin
     64  if FActive then Ext.Status := Status;
    5665end;
    5766
     
    6877    FInputBufferLock.Release;
    6978    StreamHelper.Free;
     79  end;
     80end;
     81
     82procedure TCommThread.ExtSetStatus(Sender: TCommPin; AStatus: Integer);
     83begin
     84  try
     85    FInputBufferLock.Acquire;
     86    FStatusValue := AStatus;
     87    FStatusEvent.SetEvent;
     88  finally
     89    FInputBufferLock.Release;
    7090  end;
    7191end;
     
    96116  Ext := TCommPin.Create;
    97117  Ext.OnReceive := ExtReceiveData;
     118  Ext.OnSetSatus := ExtSetStatus;
    98119  Pin := TCommPin.Create;
    99   Pin.OnReceive := ReceiveData;
     120  Pin.OnReceive := PinReceiveData;
     121  Pin.OnSetSatus := PinSetStatus;
    100122  FDataAvailable := TSimpleEvent.Create;
     123  FStatusEvent := TSimpleEvent.Create;
    101124end;
    102125
     
    108131  Ext.Free;
    109132  Pin.Free;
     133  FStatusEvent.Free;
    110134  FDataAvailable.Free;
    111135  inherited Destroy;
     
    119143    with Parent do
    120144    repeat
     145      // Check if new data arrived
    121146      if FDataAvailable.WaitFor(1) = wrSignaled then
    122147      try
     
    130155        FInputBufferLock.Release;
    131156      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;
    132167    until Terminated;
    133168  finally
Note: See TracChangeset for help on using the changeset viewer.