Line | |
---|
1 | unit Serial;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Device, BigInt, Channel;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TReadEvent = function: Byte of object;
|
---|
10 | TWriteEvent = procedure (Value: Byte) of object;
|
---|
11 |
|
---|
12 | { TSerial }
|
---|
13 |
|
---|
14 | TSerial = class(TDevice)
|
---|
15 | private
|
---|
16 | FOnRead: TReadEvent;
|
---|
17 | FOnWrite: TWriteEvent;
|
---|
18 | public
|
---|
19 | function Read(Address: TBigInt; Size: TBigIntSize): TBigInt;
|
---|
20 | procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt);
|
---|
21 | function GetAddressCount: Integer; override;
|
---|
22 | procedure SetChannel(Channel: TChannel); override;
|
---|
23 | property OnWrite: TWriteEvent read FOnWrite write FOnWrite;
|
---|
24 | property OnRead: TReadEvent read FOnRead write FOnRead;
|
---|
25 | end;
|
---|
26 |
|
---|
27 |
|
---|
28 | implementation
|
---|
29 |
|
---|
30 | { TSerial }
|
---|
31 |
|
---|
32 | function TSerial.Read(Address: TBigInt; Size: TBigIntSize): TBigInt;
|
---|
33 | begin
|
---|
34 | case Integer(Address) of
|
---|
35 | 0: if Assigned(FOnRead) then Result := FOnRead;
|
---|
36 | end;
|
---|
37 | end;
|
---|
38 |
|
---|
39 | procedure TSerial.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt);
|
---|
40 | begin
|
---|
41 | case Integer(Address) of
|
---|
42 | 0: if Assigned(FOnWrite) then FOnWrite(Value);
|
---|
43 | end;
|
---|
44 | end;
|
---|
45 |
|
---|
46 | function TSerial.GetAddressCount: Integer;
|
---|
47 | begin
|
---|
48 | Result := 1;
|
---|
49 | end;
|
---|
50 |
|
---|
51 | procedure TSerial.SetChannel(Channel: TChannel);
|
---|
52 | begin
|
---|
53 | Channel.Read := Read;
|
---|
54 | Channel.Write := Write;
|
---|
55 | end;
|
---|
56 |
|
---|
57 | end.
|
---|
58 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.