1 | unit SerialPort;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Device;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
40 | implementation
|
---|
41 |
|
---|
42 | { TSerialPort2 }
|
---|
43 |
|
---|
44 | procedure TSerialPort2.Write1(Address: Word; Data: Byte);
|
---|
45 | begin
|
---|
46 | if Assigned(FOnWrite) then FOnWrite(Data);
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TSerialPort2.Write2(Address: Word; Data: Word);
|
---|
50 | begin
|
---|
51 | if Assigned(FOnWrite) then FOnWrite(Data);
|
---|
52 | end;
|
---|
53 |
|
---|
54 | function TSerialPort2.Read1(Address: Word): Byte;
|
---|
55 | begin
|
---|
56 | if Assigned(FOnRead) then Result := FOnRead;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | function TSerialPort2.Read2(Address: Word): Word;
|
---|
60 | begin
|
---|
61 | if Assigned(FOnRead) then Result := FOnRead;
|
---|
62 | end;
|
---|
63 |
|
---|
64 | { TSerialPort1 }
|
---|
65 |
|
---|
66 | procedure TSerialPort1.Write1(Address: Byte; Data: Byte);
|
---|
67 | begin
|
---|
68 | if Assigned(FOnWrite) then FOnWrite(Data);
|
---|
69 | end;
|
---|
70 |
|
---|
71 | function TSerialPort1.Read1(Address: Byte): Byte;
|
---|
72 | begin
|
---|
73 | if Assigned(FOnRead) then Result := FOnRead;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | end.
|
---|
77 |
|
---|