-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialstream.pas
46 lines (36 loc) · 1.03 KB
/
serialstream.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
unit SerialStream;
{$mode ObjFPC}{$H+}
interface
uses
Classes, Serial, SysUtils;
type
TSerialStream = class(THandleStream)
public
constructor Create(const ADevice: string; const ABaud: integer;
const AByteSize: integer = 8; const AParity: TParityType = NoneParity;
const AStopBits: integer = 1);
destructor Destroy; override;
public
function Read(var ABuffer; ACount: longint): longint; override;
end;
implementation
constructor TSerialStream.Create(const ADevice: string;
const ABaud, AByteSize: integer; const AParity: TParityType; const AStopBits: integer);
begin
inherited Create(SerOpen(ADevice));
if Handle = 0 then
begin
raise Exception.Create('Unable to open serial device');
end;
SerSetParams(Handle, ABaud, AByteSize, AParity, AStopBits, []);
end;
destructor TSerialStream.Destroy;
begin
SerClose(Handle);
inherited;
end;
function TSerialStream.Read(var ABuffer; ACount: longint): longint;
begin
Result := SerReadTimeout(Handle, byte(ABuffer), ACount, High(longint));
end;
end.