Changeset 413


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.
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • ISPProgrammer/Dallas/UDallasProgrammer.pas

    r410 r413  
    88  Classes, SysUtils, USerialPort, UCommSerialPort, UCommPin, UCommMark,
    99  UJobProgressView, SyncObjs, DateUtils, Dialogs, URegistry,
    10   Forms, UISPProgrammer, Registry, UBinarySerializer, SpecializedList;
     10  Forms, UISPProgrammer, Registry, UBinarySerializer, SpecializedList,
     11  UCommTelnet;
    1112
    1213const
     
    135136
    136137procedure TDallasProgrammer.SetActive(AValue: Boolean);
     138var
     139  SerialPort: TCommSerialPort;
     140  Telnet: TCommTelnet;
    137141begin
    138142  if Active = AValue then Exit;
     
    144148    HexData := TStringList.Create;
    145149
    146     SerialPort.Active := False;
    147     SerialPortBackup.Assign(SerialPort);
    148     SerialPortBackupPin := SerialPort.Pin.RemotePin;
    149     SerialPort.Pin.Disconnect;
    150 
    151     //SerialPort.Name := SerialPort.Name;
    152     SerialPort.FlowControl := fcNone;
    153     SerialPort.BaudRate := BaudRate;
    154     SerialPort.DTR := True;
    155     SerialPort.Pin.Connect(CommMark.PinRaw);
    156     SerialPort.Flush;
    157     SerialPort.Purge;
    158     SerialPort.Active := True;
    159     if Assigned(FOnLogData) then
    160       Pin.OnLogData := FOnLogData;
     150    if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommSerialPort) then begin
     151      SerialPort := TCommSerialPort(ExtPin.RemotePin.Node);
     152      SerialPort.Active := False;
     153      SerialPortBackup.Assign(SerialPort);
     154      SerialPortBackupPin := SerialPort.Pin.RemotePin;
     155      SerialPort.Pin.Disconnect;
     156
     157      //SerialPort.Name := SerialPort.Name;
     158      SerialPort.SerialPort.FlowControl := fcNone;
     159      SerialPort.SerialPort.BaudRate := BaudRate;
     160      SerialPort.SerialPort.DTR := True;
     161      SerialPort.Pin.Connect(CommMark.PinRaw);
     162      SerialPort.SerialPort.Flush;
     163      SerialPort.SerialPort.Purge;
     164      SerialPort.Active := True;
     165      if Assigned(FOnLogData) then
     166        Pin.OnLogData := FOnLogData;
     167    end;
     168    if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommTelnet) then begin
     169      Telnet := TCommTelnet(ExtPin.RemotePin.Node);
     170    end;
    161171    ResponseClear;
    162172    CommMark.Active := True;
    163 
    164173    ReadIdentification;
    165174  end else begin
    166175    CommMark.Active := False;
    167     SerialPort.Active := False;
    168     SerialPort.Assign(SerialPortBackup);
    169     SerialPort.Pin.Connect(SerialPortBackupPin);
    170     SerialPort.Active := True;
     176    if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommSerialPort) then begin
     177      SerialPort := TCommSerialPort(ExtPin.Node);
     178      SerialPort.Active := False;
     179      SerialPort.Assign(SerialPortBackup);
     180      SerialPort.Pin.Connect(SerialPortBackupPin);
     181      SerialPort.Active := True;
     182    end;
     183    if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommTelnet) then begin
     184      Telnet := TCommTelnet(ExtPin.RemotePin.Node);
     185    end;
    171186    HexData.Free;
    172187    Request.Free;
     
    359374  Mark := TListByte.Create;
    360375  Mark.SetArray([13, 10]);
    361   CommMark := TCommMark.Create;
     376  CommMark := TCommMark.Create(nil);
    362377  CommMark.Mark.Assign(Mark);
    363378  CommMark.PinFrame.Connect(Pin);
    364379  BaudRate := 9600;
    365   SerialPortBackup := TCommSerialPort.Create;
     380  SerialPortBackup := TCommSerialPort.Create(nil);
    366381end;
    367382
  • ISPProgrammer/UISPProgrammer.pas

    r406 r413  
    66
    77uses
    8   Classes, SysUtils, Registry, UIntelHexFile, UCommSerialPort,
    9   UCPUType, UJobProgressView;
     8  Classes, SysUtils, Registry, UIntelHexFile,
     9  UCPUType, UJobProgressView, UCommPin;
    1010
    1111type
     
    3131    HexFile: TIntelHexFile;
    3232    FileName: string;
    33     SerialPort: TCommSerialPort;
    3433    Capabilities: TISPProgCapabilities;
     34    ExtPin: TCommPin;
    3535    procedure Log(Text: string);
    3636    procedure LoadFromRegistry(Root: HKEY; Key: string); virtual;
     
    130130constructor TISPProgrammer.Create;
    131131begin
     132  ExtPin := TCommPin.Create;
    132133  HexFile := TIntelHexFile.Create;
    133134  HexFile.BytePerLine := 20;
    134   SerialPort := nil;
    135135end;
    136136
     
    138138begin
    139139  Active := False;
     140  ExtPin.Free;
    140141  HexFile.Free;
    141142  inherited Destroy;
  • PinConnection/PinConnection.lpk

    r411 r413  
    2121    <Description Value="System for class bidirectional communication interconnection."/>
    2222    <License Value="GNU/GPL"/>
    23     <Version Minor="3"/>
    24     <Files Count="14">
     23    <Version Minor="4"/>
     24    <Files Count="15">
    2525      <Item1>
    2626        <Filename Value="USerialPort.pas"/>
     
    7979        <UnitName Value="UCommMark"/>
    8080      </Item14>
     81      <Item15>
     82        <Filename Value="UPinConnection.pas"/>
     83        <HasRegisterProc Value="True"/>
     84        <UnitName Value="UPinConnection"/>
     85      </Item15>
    8186    </Files>
    8287    <i18n>
  • PinConnection/PinConnection.pas

    r411 r413  
    1010  USerialPort, UPacketBurst, UCommFrame, UCommHub, UCommPin, UCommSerialPort,
    1111  UCommThread, UCommConcentrator, UCommDelay, UCommTCPClient, UCommTCPServer,
    12   UCommTelnet, UCommTelnetComPortOption, UCommMark, LazarusPackageIntf;
     12  UCommTelnet, UCommTelnetComPortOption, UCommMark, UPinConnection,
     13  LazarusPackageIntf;
    1314
    1415implementation
     
    1617procedure Register;
    1718begin
     19  RegisterUnit('UPinConnection', @UPinConnection.Register);
    1820end;
    1921
  • PinConnection/UCommConcentrator.pas

    r407 r413  
    2626  { TCommConcentrator }
    2727
    28   TCommConcentrator = class
     28  TCommConcentrator = class(TCommNode)
    2929  private
    3030    FActive: Boolean;
     
    3636    procedure SetStatus(Sender: TCommPin; Status: Integer);
    3737  public
    38     constructor Create;
     38    constructor Create(AOwner: TComponent); override;
    3939    destructor Destroy; override;
    4040    property Pins: TPinList read FPins write FPins;
     
    5757begin
    5858  Result := TCommPin(Items[Add(TCommPin.Create)]);
     59  Result.Node := Concentrator;
    5960end;
    6061
     
    109110end;
    110111
    111 constructor TCommConcentrator.Create;
     112constructor TCommConcentrator.Create(AOwner: TComponent);
    112113begin
     114  inherited;
    113115  FPins := TPinList.Create;
    114116  FPins.Concentrator := Self;
  • PinConnection/UCommDelay.pas

    r407 r413  
    3333  { TCommDelay }
    3434
    35   TCommDelay = class
     35  TCommDelay = class(TCommNode)
    3636  private
    3737    FActive: Boolean;
     
    4949    Pin1: TCommPin;
    5050    Pin2: TCommPin;
    51     constructor Create;
     51    constructor Create(AOwner: TComponent); override;
    5252    destructor Destroy; override;
    5353    property Delay: TDateTime read FDelay write FDelay;
     
    169169end;
    170170
    171 constructor TCommDelay.Create;
     171constructor TCommDelay.Create(AOwner: TComponent);
    172172begin
     173  inherited;
    173174  Lock1 := TCriticalSection.Create;
    174175  Lock2 := TCriticalSection.Create;
     
    177178  Pin1 := TCommPin.Create;
    178179  Pin1.OnReceive := ReceiveData1;
     180  Pin1.Node := Self;
    179181  Pin2 := TCommPin.Create;
    180182  Pin2.OnReceive := ReceiveData2;
     183  Pin2.Node := Self;
    181184end;
    182185
  • PinConnection/UCommFrame.pas

    r411 r413  
    1414  { TCommFrame }
    1515
    16   TCommFrame = class
     16  TCommFrame = class(TCommNode)
    1717  private
    1818    LastCharIsSpecialChar: Boolean;
     
    3535    ControlCodeSpecialChar: Byte;
    3636    function ComputeRawSize(DataStream: TListByte): Integer;
    37     constructor Create;
     37    constructor Create(AOwner: TComponent); override;
    3838    destructor Destroy; override;
    3939    property FrameErrorCount: Integer read FFrameErrorCount;
     
    4646{ TCommFrame }
    4747
    48 constructor TCommFrame.Create;
    49 begin
     48constructor TCommFrame.Create(AOwner: TComponent);
     49begin
     50  inherited;
    5051  ReceiveBuffer := TBinarySerializer.Create;
    5152  ReceiveBuffer.List := TListByte.Create;
     
    5354  RawDataPin := TCommPin.Create;
    5455  RawDataPin.OnReceive := RawDataReceive;
     56  RawDataPin.Node := Self;
    5557  FrameDataPin := TCommPin.Create;
    5658  FrameDataPin.OnReceive := FrameDataReceive;
     59  FrameDataPin.Node := Self;
    5760  PacketLoss := 0;
    5861  SpecialChar := $fe;
  • PinConnection/UCommHub.pas

    r407 r413  
    2323  { TCommHub }
    2424
    25   TCommHub = class
     25  TCommHub = class(TCommNode)
    2626  private
    2727    FActive: Boolean;
     
    3030    procedure SetStatus(Sender: TCommPin; Status: Integer);
    3131  public
    32     constructor Create;
     32    constructor Create(AOwner: TComponent); override;
    3333    destructor Destroy; override;
    3434    property Pins: TPinList read FPins write FPins;
     
    5050begin
    5151  Result := TCommPin(Items[Add(TCommPin.Create)]);
     52  Result.Node := Hub;
    5253end;
    5354
     
    9293end;
    9394
    94 constructor TCommHub.Create;
     95constructor TCommHub.Create(AOwner: TComponent);
    9596begin
     97  inherited;
    9698  FPins := TPinList.Create;
    9799  FPins.Hub := Self;
  • PinConnection/UCommMark.pas

    r410 r413  
    1212  { TCommMark }
    1313
    14   TCommMark = class
     14  TCommMark = class(TCommNode)
    1515  private
    1616    FActive: Boolean;
     
    2727    Mark: TListByte;
    2828    procedure Reset;
    29     constructor Create;
     29    constructor Create(AOwner: TComponent); override;
    3030    destructor Destroy; override;
    3131    property Active: Boolean read FActive write SetActive;
     
    8888end;
    8989
    90 constructor TCommMark.Create;
     90constructor TCommMark.Create(AOwner: TComponent);
    9191begin
     92  inherited;
    9293  PinRaw := TCommPin.Create;
    9394  PinRaw.OnReceive := RawDataReceive;
    9495  PinRaw.OnSetSatus := RawSetStatus;
     96  PinRaw.Node := Self;
    9597  PinFrame := TCommPin.Create;
    9698  PinFrame.OnReceive := FrameDataReceive;
    9799  PinFrame.OnSetSatus := FrameSetStatus;
     100  PinFrame.Node := Self;
    98101  Mark := TListByte.Create;
    99102  FMarkIndex := 0;
  • PinConnection/UCommPin.pas

    r407 r413  
    1010type
    1111  TCommPin = class;
     12  TCommNode = class;
    1213
    1314  TDataDiretion = (ddReceive, ddSend);
     
    3536  public
    3637    RemotePin: TCommPin;
     38    Node: TCommNode;
    3739    constructor Create;
    3840    destructor Destroy; override;
     
    5254  end;
    5355
     56  { TCommNode }
     57
     58  TCommNode = class(TComponent)
     59  private
     60    FActive: Boolean;
     61  protected
     62    procedure SetActive(AValue: Boolean); virtual;
     63  public
     64    property Active: Boolean read FActive write SetActive;
     65  end;
     66
    5467
    5568implementation
     69
     70{ TCommNode }
     71
     72procedure TCommNode.SetActive(AValue: Boolean);
     73begin
     74  if FActive = AValue then Exit;
     75  FActive := AValue;
     76end;
    5677
    5778{ TCommPin }
  • 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;
  • PinConnection/UCommTCPClient.pas

    r411 r413  
    2828  { TCommTCPClient }
    2929
    30   TCommTCPClient = class
     30  TCommTCPClient = class(TCommNode)
    3131  private
    3232    FActive: Boolean;
     
    4141    Port: Word;
    4242    property Active: Boolean read FActive write SetActive;
    43     constructor Create;
     43    constructor Create(AOwner: TComponent); override;
    4444    destructor Destroy; override;
    4545  end;
     
    9393end;
    9494
    95 constructor TCommTCPClient.Create;
     95constructor TCommTCPClient.Create(AOwner: TComponent);
    9696begin
    97   inherited Create;
     97  inherited;
    9898  Socket := TTCPBlockSocket.Create;
    9999  Pin := TCommPin.Create;
    100100  Pin.OnReceive := ReceiveData;
     101  Pin.Node := Self;
    101102end;
    102103
  • PinConnection/UCommTCPServer.pas

    r407 r413  
    4343  { TCommTCPServer }
    4444
    45   TCommTCPServer = class
     45  TCommTCPServer = class(TCommNode)
    4646  private
    4747    FActive: Boolean;
     
    5959    property OnConnect: TSocketConnectEvent read FOnConnect write FOnConnect;
    6060    property OnDisconnect: TSocketConnectEvent read FOnDisconnect write FOnDisconnect;
    61     constructor Create;
     61    constructor Create(AOwner: TComponent); override;
    6262    destructor Destroy; override;
    6363  end;
     
    8585  Pin := TCommPin.Create;
    8686  Pin.OnReceive := ReceiveData;
     87  Pin.Node := Server;
    8788end;
    8889
     
    187188end;
    188189
    189 constructor TCommTCPServer.Create;
    190 begin
    191   inherited Create;
     190constructor TCommTCPServer.Create(AOwner: TComponent);
     191begin
     192  inherited;
    192193  Sessions := TListObject.Create;
    193194  Socket := TTCPBlockSocket.Create;
  • PinConnection/UCommTelnet.pas

    r412 r413  
    6767  { TCommTelnet }
    6868
    69   TCommTelnet = class
     69  TCommTelnet = class(TCommNode)
    7070  private
    7171    FResponses: TListObject; // TListObject<TListByte>
     
    9292    procedure SendSubCommand(OptionCode: TTelnetCommand; Request, Response: TListByte);
    9393    procedure SendCommand(Code: TTelnetCode; Request, Response: TListByte);
    94     constructor Create;
     94    constructor Create(AOwner: TComponent); override;
    9595    destructor Destroy; override;
    9696    property Active: Boolean read FActive write SetActive;
     
    399399end;
    400400
    401 constructor TCommTelnet.Create;
    402 begin
     401constructor TCommTelnet.Create(AOwner: TComponent);
     402begin
     403  inherited;
    403404  FResponses := TListObject.Create;
    404405  FCommandData := TBinarySerializer.Create;
     
    407408  TelnetPin := TCommPin.Create;
    408409  TelnetPin.OnReceive := TelnetDataReceive;
     410  TelnetPin.Node := Self;
    409411  RawPin := TCommPin.Create;
    410412  RawPin.OnReceive := RawDataReceive;
     413  RawPin.Node := Self;
    411414  Options := TListObject.Create;
    412415  Options.OwnsObjects := False;
  • PinConnection/UCommThread.pas

    r407 r413  
    2828  { TCommThread }
    2929
    30   TCommThread = class
     30  TCommThread = class(TCommNode)
    3131  private
    3232    FActive: Boolean;
     
    4747    Pin: TCommPin;
    4848    property Active: Boolean read FActive write SetActive;
    49     constructor Create;
     49    constructor Create(AOwner: TComponent); override;
    5050    destructor Destroy; override;
    5151  end;
     
    103103end;
    104104
    105 constructor TCommThread.Create;
     105constructor TCommThread.Create(AOwner: TComponent);
    106106begin
    107   inherited Create;
     107  inherited;
    108108  FInputBuffer := TBinarySerializer.Create;
    109109  FInputBuffer.List := TListByte.Create;
     
    113113  Ext.OnReceive := ExtReceiveData;
    114114  Ext.OnSetSatus := ExtSetStatus;
     115  Ext.Node := Self;
    115116  Pin := TCommPin.Create;
    116117  Pin.OnReceive := PinReceiveData;
    117118  Pin.OnSetSatus := PinSetStatus;
     119  Pin.Node := Self;
    118120  FDataAvailable := TSimpleEvent.Create;
    119121  FStatusEvent := TSimpleEvent.Create;
  • PinConnection/UPacketBurst.pas

    r407 r413  
    1919  { TPacketBurst }
    2020
    21   TPacketBurst = class
     21  TPacketBurst = class(TCommNode)
    2222  private
    2323    FActive: Boolean;
     
    3636    PacketBurstPin: TCommPin;
    3737    destructor Destroy; override;
    38     constructor Create;
     38    constructor Create(AOwner: TComponent); override;
    3939    property Active: Boolean read FActive write SetActive;
    4040  end;
     
    4444{ TSerialPort }
    4545
    46 constructor TPacketBurst.Create;
     46constructor TPacketBurst.Create(AOwner: TComponent);
    4747begin
     48  inherited;
    4849  PacketSinglePin := TCommPin.Create;
    4950  PacketSinglePin.OnReceive := PacketSingleReceive;
     51  PacketSinglePin.Node := Self;
    5052  PacketBurstPin := TCommPin.Create;
    5153  PacketBurstPin.OnReceive := PacketBurstReceive;
     54  PacketBurstPin.Node := Self;
    5255  SendThreadEvent := TSimpleEvent.Create;
    5356  SendPeriod := 1;
Note: See TracChangeset for help on using the changeset viewer.