source: branches/ByteArray/Devices/Serial.pas

Last change on this file was 47, checked in by chronos, 7 months ago
  • Added: Common package.
  • Modified: Improved BigInt class.
File size: 1.2 KB
Line 
1unit Serial;
2
3interface
4
5uses
6 Classes, SysUtils, Device, BigInt, Channel;
7
8type
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
28implementation
29
30{ TSerial }
31
32function TSerial.Read(Address: TBigInt; Size: TBigIntSize): TBigInt;
33begin
34 case Integer(Address) of
35 0: if Assigned(FOnRead) then Result := FOnRead;
36 end;
37end;
38
39procedure TSerial.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt);
40begin
41 case Integer(Address) of
42 0: if Assigned(FOnWrite) then FOnWrite(Value);
43 end;
44end;
45
46function TSerial.GetAddressCount: Integer;
47begin
48 Result := 1;
49end;
50
51procedure TSerial.SetChannel(Channel: TChannel);
52begin
53 Channel.Read := Read;
54 Channel.Write := Write;
55end;
56
57end.
58
Note: See TracBrowser for help on using the repository browser.