-
Notifications
You must be signed in to change notification settings - Fork 1
/
RS232.exp
131 lines (119 loc) · 2.35 KB
/
RS232.exp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
MODULE RS232;
IMPORT SYSTEM;
CONST
data = -56;
stat = -52;
PROCEDURE Send*(x : INTEGER);
BEGIN
REPEAT
UNTIL SYSTEM.BIT(stat, 1);
SYSTEM.PUT(data, x)
END Send;
PROCEDURE Rec*(VAR x : INTEGER);
BEGIN
REPEAT
UNTIL SYSTEM.BIT(stat, 0);
SYSTEM.GET(data, x)
END Rec;
PROCEDURE SendInt*(x : INTEGER);
VAR
i: INTEGER;
BEGIN
Send(1);
i := 4;
REPEAT
i := i-1;
Send(x);
x := ROR(x, 8)
UNTIL i = 0
END SendInt;
PROCEDURE SendHex*(x : INTEGER);
VAR
i: INTEGER;
BEGIN
Send(2);
i := 4;
REPEAT
i := i-1;
Send(x);
x := ROR(x, 8)
UNTIL i = 0
END SendHex;
PROCEDURE SendReal*(x : REAL);
VAR
i: INTEGER;
u: INTEGER;
BEGIN
Send(3);
u := ORD(x);
i := 4;
REPEAT
i := i-1;
Send(u);
u := ROR(u, 8)
UNTIL i = 0
END SendReal;
PROCEDURE SendStr*(x : ARRAY OF CHAR);
VAR
i: INTEGER;
k: INTEGER;
BEGIN
Send(4);
i := 0;
REPEAT
k := ORD(x[i]);
Send(k);
INC(i)
UNTIL k = 0
END SendStr;
PROCEDURE RecInt*(VAR x : INTEGER);
VAR
i: INTEGER;
x0: INTEGER;
y: INTEGER;
BEGIN
i := 4;
x0 := 0;
REPEAT
i := i-1;
Rec(y);
x0 := ROR(x0+y, 8)
UNTIL i = 0;
x := x0
END RecInt;
PROCEDURE RecReal*(VAR x : REAL);
VAR
i: INTEGER;
x0: INTEGER;
y: INTEGER;
BEGIN
i := 4;
x0 := 0;
REPEAT
i := i-1;
Rec(y);
x0 := ROR(x0+y, 8)
UNTIL i = 0;
x := SYSTEM.VAL(REAL, x0)
END RecReal;
PROCEDURE RecStr*(VAR x : ARRAY OF CHAR);
VAR
i: INTEGER;
k: INTEGER;
BEGIN
i := 0;
REPEAT
Rec(k);
x[i] := CHR(k);
INC(i)
UNTIL k = 0
END RecStr;
PROCEDURE Line*;
BEGIN
Send(6)
END Line;
PROCEDURE End*;
BEGIN
Send(7)
END End;
END RS232.