-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSERIAL.PAS
108 lines (89 loc) · 2.28 KB
/
USERIAL.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
USerial Unit
Provides read-only stream access to a part of another stream
2022 LRT
}
unit
USerial;
interface
uses
consts, utils, uexc, uclasses, types, locale, uobject, ustream, math,
int14;
type
PSerial = ^TSerial;
TSerial = object (TStream)
public
constructor initWithPort(port: ESerialPort);
destructor done; virtual;
function read(buffer: pointer; count: word): word; virtual;
procedure write(buffer: pointer; count: word); virtual;
procedure seek(pos: longint); virtual;
function getPosition: longint; virtual;
function isEOF: boolean; virtual;
function getSize: longint; virtual;
function isReadOnly: boolean; virtual;
function getClassName: string; virtual;
function getClassId: word; virtual;
private
_handle: text;
end;
implementation
{ TSerial public }
constructor TSerial.initWithPort(port: ESerialPort);
begin
inherited init;
assign(_handle, 'COM' + chr(1+ord(port)+ord('0')));
rewrite(_handle);
end;
destructor TSerial.done;
begin
close(_handle);
inherited done;
end;
function TSerial.read(buffer: pointer; count: word): word;
begin
iassert(false, @self, 0, S_ERR_UNSUPPORTED_ACTION);
end;
procedure TSerial.write(buffer: pointer; count: word);
var
p: pchar;
i: word;
begin
p := buffer;
for i:=1 to count do
begin
system.write(_handle, p^);
inc(p);
end;
end;
procedure TSerial.seek(pos: longint);
begin
iassert(false, @self, 0, S_ERR_UNSUPPORTED_ACTION);
end;
function TSerial.getPosition: longint;
begin
iassert(false, @self, 0, S_ERR_UNSUPPORTED_ACTION);
end;
function TSerial.isEOF: boolean;
begin
iassert(false, @self, 0, S_ERR_UNSUPPORTED_ACTION);
end;
function TSerial.getSize: longint;
begin
iassert(false, @self, 0, S_ERR_UNSUPPORTED_ACTION);
end;
function TSerial.isReadOnly: boolean;
begin
isReadOnly := false;
end;
function TSerial.getClassName: string;
begin
getClassName := 'TSerial';
end;
function TSerial.getClassId: word;
begin
getClassId := C_CLASS_ID_Serial;
end;
{ TSerial private }
{ Other }
end.