Changeset 272


Ignore:
Timestamp:
Aug 30, 2011, 3:50:15 PM (13 years ago)
Author:
george
Message:
  • Fixed: Do not send or receive data for comm classes if not in active state.
  • Fixed: TCommProtocol now raise ENotActive exception on try to send data while in inactive state.
  • Fixed: Reseting event after data received in TCommThread class.
Location:
PinConnection
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/Languages/UCommProtocol.cs.po

    r268 r272  
    1818msgstr "Chyba dekódování dat"
    1919
     20#: ucommprotocol.sprotocolnotactive
     21msgid "Device protocol not active"
     22msgstr ""
     23
    2024#: ucommprotocol.sresponseerror
    2125#| msgid "Command %s response error %s"
  • PinConnection/Languages/UCommProtocol.po

    r268 r272  
    88#: ucommprotocol.sprotocoldecodeerror
    99msgid "Data decode error"
     10msgstr ""
     11
     12#: ucommprotocol.sprotocolnotactive
     13msgid "Device protocol not active"
    1014msgstr ""
    1115
  • PinConnection/UCommHub.pas

    r119 r272  
    1414  TCommHub = class
    1515  private
     16    FActive: Boolean;
    1617    FPins: TObjectList;
    1718    function GetPin(Index: Integer): TCommPin;
     
    2930    function AddNew: TCommPin;
    3031    property Pins[Index: Integer]: TCommPin read GetPin;
     32    property Active: Boolean read FActive write FActive;
    3133  end;
    3234
     
    4446  I: Integer;
    4547begin
    46   // Broadcast received packet to all other pins
    47   for I := 0 to FPins.Count - 1 do
    48     if Sender <> FPins[I] then
    49       TCommPin(FPins[I]).Send(Stream);
     48  if FActive then begin
     49    // Broadcast received packet to all other pins
     50    for I := 0 to FPins.Count - 1 do
     51      if Sender <> FPins[I] then
     52        TCommPin(FPins[I]).Send(Stream);
     53  end;
    5054end;
    5155
  • PinConnection/UCommProtocol.pas

    r268 r272  
    1414  ECommTimeout = class(Exception);
    1515  ECommError = class(Exception);
     16  ENotActive = class(Exception);
    1617
    1718  TResponseError = (rcNone, rcCommandNotSupported, rcSequenceOutOfRange,
     
    118119  SDeviceProtocol = 'Device protocol';
    119120  SProtocolDecodeError = 'Data decode error';
     121  SProtocolNotActive = 'Device protocol not active';
    120122
    121123procedure TCommProtocol.DataReceive(Sender: TCommPin; Stream: TStream);
     
    133135    with Request do
    134136    try
     137      Stream.Position := 0;
    135138      ReadFromStream(Stream);
    136139      if TestIndex(0) then
     
    273276  NewRequest: TVarBlockIndexed;
    274277begin
     278  if FActive then begin
    275279  try
    276280    Session := TDeviceProtocolSession.Create;
     
    337341    NewRequest.Free;
    338342  end;
     343  end else raise ENotActive.Create(SProtocolNotActive);
    339344end;
    340345
  • PinConnection/UCommSerialPort.pas

    r258 r272  
    2929procedure TCommSerialPort.ReceiveData(Stream: TMemoryStream);
    3030begin
    31   Pin.Send(Stream);
     31  if Active then Pin.Send(Stream);
    3232end;
    3333
     
    5151procedure TCommSerialPort.Receive(Sender: TCommPin; Stream: TStream);
    5252begin
    53   Stream.Position := 0;
    54   repeat
    55     try
    56       Lock.Acquire;
    57       if CanWrite(0) then
    58         SendStreamRaw(Stream);
    59     finally
    60       Lock.Release;
    61     end;
    62     if Stream.Position <> Stream.Size then
    63       Sleep(1);
    64   until Stream.Position = Stream.Size;
     53  if Active then begin
     54    Stream.Position := 0;
     55    repeat
     56      try
     57        Lock.Acquire;
     58        if CanWrite(0) then
     59          SendStreamRaw(Stream);
     60      finally
     61        Lock.Release;
     62      end;
     63      if Stream.Position <> Stream.Size then
     64        Sleep(1);
     65    until Stream.Position = Stream.Size;
     66  end;
    6567end;
    6668
  • PinConnection/UCommSocket.pas

    r231 r272  
    4949procedure TCommSocket.ReceiveData(Sender: TCommPin; Stream:TStream);
    5050begin
    51   Socket.SendStreamRaw(Stream);
     51  if FActive then Socket.SendStreamRaw(Stream);
    5252end;
    5353
  • PinConnection/UCommThread.pas

    r231 r272  
    1919  public
    2020    Parent: TCommThread;
    21     Stream: TMemoryStream;
     21    Stream: TStreamHelper;
    2222    procedure Execute; override;
    2323    constructor Create(CreateSuspended: Boolean;
     
    5353procedure TCommThread.ReceiveData(Sender: TCommPin; Stream:TStream);
    5454begin
    55   Ext.Send(Stream);
     55  if FActive then Ext.Send(Stream);
    5656end;
    5757
     
    115115
    116116procedure TCommThreadReceiveThread.Execute;
    117 var
    118   StreamHelper: TStreamHelper;
    119117begin
    120118  try
    121     StreamHelper := TStreamHelper.Create(Stream);
    122119    with Parent do
    123120    repeat
    124       if FDataAvailable.WaitFor(1) = wrSignaled then begin
     121      if FDataAvailable.WaitFor(1) = wrSignaled then
    125122      try
    126123        FInputBufferLock.Acquire;
    127124        Stream.Size := 0;
    128         StreamHelper.WriteStream(FInputBuffer, FInputBuffer.Size);
     125        Stream.WriteStream(FInputBuffer, FInputBuffer.Size);
    129126        Pin.Send(Stream);
     127      finally
     128        FDataAvailable.ResetEvent;
    130129        FInputBuffer.Clear;
    131       finally
    132130        FInputBufferLock.Release;
    133       end;
    134131      end; // else Yield;
    135132    until Terminated;
    136133  finally
    137     StreamHelper.Free;
    138134  end;
    139135end;
     
    143139begin
    144140  inherited;
    145   Stream := TMemoryStream.Create;
     141  Stream := TStreamHelper.Create;
    146142end;
    147143
Note: See TracChangeset for help on using the changeset viewer.