source: branches/configured machine/SerialPort.pas

Last change on this file was 239, checked in by chronos, 16 months ago
File size: 1.7 KB
Line 
1unit SerialPort;
2
3interface
4
5uses
6 Classes, SysUtils, Device;
7
8type
9 TReadEvent = function: Byte of object;
10 TWriteEvent = procedure (B: Byte) of object;
11
12 { TSerialPort1 }
13
14 TSerialPort1 = class(TDevice1)
15 private
16 FOnRead: TReadEvent;
17 FOnWrite: TWriteEvent;
18 public
19 procedure Write1(Address: Byte; Data: Byte); override;
20 function Read1(Address: Byte): Byte; override;
21 property OnWrite: TWriteEvent read FOnWrite write FOnWrite;
22 property OnRead: TReadEvent read FOnRead write FOnRead;
23 end;
24
25 { TSerialPort2 }
26
27 TSerialPort2 = class(TDevice2)
28 private
29 FOnRead: TReadEvent;
30 FOnWrite: TWriteEvent;
31 public
32 procedure Write1(Address: Word; Data: Byte); override;
33 procedure Write2(Address: Word; Data: Word); override;
34 function Read1(Address: Word): Byte; override;
35 function Read2(Address: Word): Word; override;
36 property OnWrite: TWriteEvent read FOnWrite write FOnWrite;
37 property OnRead: TReadEvent read FOnRead write FOnRead;
38 end;
39
40implementation
41
42{ TSerialPort2 }
43
44procedure TSerialPort2.Write1(Address: Word; Data: Byte);
45begin
46 if Assigned(FOnWrite) then FOnWrite(Data);
47end;
48
49procedure TSerialPort2.Write2(Address: Word; Data: Word);
50begin
51 if Assigned(FOnWrite) then FOnWrite(Data);
52end;
53
54function TSerialPort2.Read1(Address: Word): Byte;
55begin
56 if Assigned(FOnRead) then Result := FOnRead;
57end;
58
59function TSerialPort2.Read2(Address: Word): Word;
60begin
61 if Assigned(FOnRead) then Result := FOnRead;
62end;
63
64{ TSerialPort1 }
65
66procedure TSerialPort1.Write1(Address: Byte; Data: Byte);
67begin
68 if Assigned(FOnWrite) then FOnWrite(Data);
69end;
70
71function TSerialPort1.Read1(Address: Byte): Byte;
72begin
73 if Assigned(FOnRead) then Result := FOnRead;
74end;
75
76end.
77
Note: See TracBrowser for help on using the repository browser.