Ignore:
Timestamp:
Aug 16, 2012, 12:59:53 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Classes using TCommPin class now inherits from TCommNode which inherits from TComponent. All TCommNodes are now registred as components in PinConnection group on component palette.
  • Modified: TCommPin now have reference to parent TCommNode.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/UCommSerialPort.pas

    r407 r413  
    1313  { TCommSerialPort }
    1414
    15   TCommSerialPort = class(TSerialPort)
     15  TCommSerialPort = class(TCommNode)
    1616  private
    1717    procedure Receive(Sender: TCommPin; Stream: TListByte);
    1818    procedure SetStatus(Sender: TCommPin; AValue: Integer);
    1919    procedure ReceiveData(Stream: TListByte);
     20  protected
     21    procedure SetActive(AValue: Boolean); override;
    2022  public
     23    SerialPort: TSerialPort;
    2124    Lock: TCriticalSection;
    2225    Pin: TCommPin;
    2326    destructor Destroy; override;
    24     constructor Create;
     27    constructor Create(AOwner: TComponent); override;
    2528  end;
    2629
     
    3336procedure TCommSerialPort.ReceiveData(Stream: TListByte);
    3437begin
    35   if Active then Pin.Send(Stream);
     38  if SerialPort.Active then Pin.Send(Stream);
     39end;
     40
     41procedure TCommSerialPort.SetActive(AValue: Boolean);
     42begin
     43  inherited SetActive(AValue);
     44  SerialPort.Active := AValue;
    3645end;
    3746
     
    4049  try
    4150    Lock.Acquire;
    42     if (AValue and 1) = 1 then Parity := paMark else Parity := paSpace;
     51    if (AValue and 1) = 1 then SerialPort.Parity := paMark
     52      else SerialPort.Parity := paSpace;
    4353  finally
    4454    Lock.Release;
     
    4656end;
    4757
    48 constructor TCommSerialPort.Create;
     58constructor TCommSerialPort.Create(AOwner: TComponent);
    4959begin
    5060  inherited;
     61  SerialPort := TSerialPort.Create;
     62  SerialPort.OnReceiveData := ReceiveData;
    5163  Lock := TCriticalSection.Create;
    5264  Pin := TCommPin.Create;
    5365  Pin.OnReceive := Receive;
    5466  Pin.OnSetSatus := SetStatus;
    55   OnReceiveData := ReceiveData;
     67  Pin.Node := Self;
    5668end;
    5769
    5870destructor TCommSerialPort.Destroy;
    5971begin
    60   OnReceiveData := nil;
     72  SerialPort.OnReceiveData := nil;
    6173  Pin.Free;
    6274  Lock.Free;
     75  SerialPort.Free;
    6376  inherited;
    6477end;
     
    7184    S := TMemoryStream.Create;
    7285    Stream.WriteToStream(S);
    73     if Active then begin
     86    if SerialPort.Active then begin
    7487      S.Position := 0;
    7588      repeat
    7689        try
    7790          Lock.Acquire;
    78           if CanWrite(0) then
    79             SendStreamRaw(S);
     91          if SerialPort.CanWrite(0) then
     92            SerialPort.SendStreamRaw(S);
    8093        finally
    8194          Lock.Release;
Note: See TracChangeset for help on using the changeset viewer.