Changeset 4 for trunk/Platform/Base


Ignore:
Timestamp:
Nov 23, 2014, 12:56:33 AM (10 years ago)
Author:
chronos
Message:
  • Added: Now applications can write text to serial device which is displayed on form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Platform/Base/UPlatformBase.pas

    r3 r4  
    66
    77uses
    8   Classes, SysUtils, UFileSystem, UKernel;
     8  Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory;
    99
    1010type
    1111  { TCustomThread }
    1212
    13   TCustomThread = class(TThread)
     13  TCustomThread = class(TThreadEx)
    1414    Task: TTask;
    1515    procedure Execute; override;
     
    3232
    3333  TBaseScheduler = class(TScheduler)
    34     function AddTask(Name: string; EntryPoint: TEvent): TTask; override;
     34    function AddTask(Name: string; EntryPoint: TBasicEvent): TTask; override;
    3535    constructor Create; override;
     36    destructor Destroy; override;
    3637    procedure Start; override;
     38    procedure Stop; override;
     39  end;
     40
     41  TReceiveEvent = procedure(Data: TMemory) of object;
     42
     43  { TBaseSerialDevice }
     44
     45  TBaseSerialDevice = class(TDevice)
     46  private
     47    Lock: TCriticalSection;
     48    FOnReceiveData: TReceiveEvent;
     49  public
     50    constructor Create; override;
     51    destructor Destroy; override;
     52    procedure Service(Index: Integer; DataIn, DataOut: TMemory); override;
     53    property OnReceiveData: TReceiveEvent read FOnReceiveData write FOnReceiveData;
    3754  end;
    3855
    3956implementation
     57
     58{ TBaseSerialDevice }
     59
     60constructor TBaseSerialDevice.Create;
     61begin
     62  inherited Create;
     63  ClassName := 'Serial';
     64  Lock := TCriticalSection.Create;
     65end;
     66
     67destructor TBaseSerialDevice.Destroy;
     68begin
     69  Lock.Free;
     70  inherited Destroy;
     71end;
     72
     73procedure TBaseSerialDevice.Service(Index: Integer; DataIn, DataOut: TMemory);
     74begin
     75  inherited Service(Index, DataIn, DataOut);
     76  if Index = 0 then begin
     77    Lock.Acquire;
     78    if Assigned(FOnReceiveData) then
     79      FOnReceiveData(DataIn);
     80    Lock.Release;
     81  end else raise Exception.Create('Unsupported service ' + IntToStr(Index) + ' for driver ''' + Name + '''');
     82end;
    4083
    4184{ TBaseTask }
     
    63106{ TBaseScheduler }
    64107
    65 function TBaseScheduler.AddTask(Name: string; EntryPoint: TEvent): TTask;
     108function TBaseScheduler.AddTask(Name: string; EntryPoint: TBasicEvent): TTask;
    66109var
    67110  Task: TBaseTask;
     
    77120end;
    78121
     122destructor TBaseScheduler.Destroy;
     123begin
     124  inherited Destroy;
     125end;
     126
    79127procedure TBaseScheduler.Start;
    80128var
     
    86134end;
    87135
     136procedure TBaseScheduler.Stop;
     137begin
     138  inherited Start;
     139end;
     140
    88141end.
    89142
Note: See TracChangeset for help on using the changeset viewer.