home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
turbopas
/
comdemo.ark
/
COMDEMO.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1986-08-24
|
6KB
|
265 lines
(* Rev 1 - re-shuffled control-\ commands to make room for BREAK B.E. *)
type
string20 = string[20];
string80= string[80];
const
revision = 1;
maxbuffer = 32767;
cr = ^m^j;
online_msg = '*** Connected to remote port ***'^m^j;
offline_msg = '*** At micro ***'^m^j;
escape_char = ^\;
var
abort, logging, file_open, connect_end : boolean;
initport : string[10];
line_buffer : string[100];
buffer : array[0..maxbuffer] of char;
bufptr, cr_delay : integer;
file_var : text;
filename : string[20];
previous_char : char;
{$I commlib.inc}
procedure menu;
begin
writeln;
write(offline_msg);
writeln('Current port is ',c_port_str[c_current_port]);
writeln('Current baud rate is ', c_baud_str[c_current_baud]);
writeln('Current parity is ', c_parity_str[c_current_parity]);
writeln;
Writeln('^\-B - Transmit BREAK.');
writeln('^\-D - Set delay after carriage return');
writeln('^\-E - Exit program.');
writeln('^\-G - Get (receive) a file.');
writeln('^\-H - Menu.');
writeln('^\-P - Set port.');
writeln('^\-Q - Exit program.');
writeln('^\-R - Set baud Rate.');
writeln('^\-S - Send a file.');
writeln('^\-W - Write buffer and close file.');
write(online_msg);
end;
procedure close_file;
var
count : integer;
begin
if file_open and (bufptr > 0) then
begin
for count := 0 to bufptr - 1 do
write(file_var,buffer[count]);
close(file_var);
file_open := false;
end;
logging := false;
bufptr := 0;
end;
procedure writescr(message : string80);
var
count : integer;
begin
for count := 1 to length(message) do
c_put_scr_char(message[count]);
end;
procedure set_port;
var count, port : integer;
begin
writescr(cr);
writescr(offline_msg);
writeln;
writeln('Current port is ',c_port_str[c_current_port]);
writeln('Possible ports are:');
count := 1;
while c_port_str[count] <> '' do
begin
writeln(count, ' - ',c_port_str[count]);
count := count + 1;
end;
write('Type the number of the desired port: ');
readln(port);
if c_set_port(port) then
writeln('Port set to: ',c_port_str[c_current_port])
else
writeln('Invalid port select, port remains ', c_port_str[c_current_port]);
writescr(cr);
writescr(online_msg);
end;
procedure set_baud;
var count, baud : integer;
begin
writescr(offline_msg);
writeln;
writeln('Current baud rate is ',c_baud_str[c_current_baud]);
writeln('Possible baud rates are:');
count := 1;
while c_baud_str[count] <> '' do
begin
writeln(count, ' - ',c_baud_str[count]);
count := count + 1;
end;
write('Type the number of the desired baud rate: ');
readln(baud);
if c_set_baud(baud) then
writeln('Baud rate set to: ',c_baud_str[c_current_baud])
else
begin
write('Invalid baud rate select, baud rate remains ');
writeln(c_baud_str[c_current_baud]);
end;
writescr(online_msg);
end;
procedure send;
var
count : integer;
line : string[100];
begin
writescr(offline_msg);
writescr('Filename to send: ');
readln(filename);
assign(file_var, filename);
{$i-} reset(file_var); {$i+}
if ioresult = 0 then
begin
file_open := true;
bufptr := 1;
while (not eof(file_var)) and (not c_get_kbd_char) do
begin
read(file_var,line);
for count := 1 to length(line) do
begin
c_put_comm_char(line[count]);
while c_get_comm_char do
c_put_scr_char(c_comm_char);
end;
c_put_comm_char(^m);
for count := 0 to (10 * cr_delay) do
while c_get_comm_char do
c_put_scr_char(c_comm_char);
readln(file_var);
end;
end
else
writescr('File not found'^m^j);
if file_open then
begin
close(file_var);
file_open := false;
end;
writescr(online_msg);
end;
procedure receive;
var
count : integer;
filename : string[20];
open_ok,connect_end : boolean;
begin
writescr(offline_msg);
write('Filename: ');
readln(filename);
assign(file_var,filename);
{$I-}
rewrite(file_var);
{$I+}
if ioresult <> 0 then
writeln('File could not be opened!')
else
begin
file_open := true;
bufptr := 0;
logging := true;
end;
writescr(online_msg);
end;
procedure set_delay;
begin
writescr(offline_msg);
write('Current delay value is: ',cr_delay,'. Enter new value: ');
readln(cr_delay);
writescr(online_msg);
end;
procedure connect;
begin
menu;
connect_end := false;
previous_char := ' ';
repeat
if c_get_kbd_char then
begin
if (previous_char = escape_char) or (c_kbd_char = escape_char) then
begin
case chr(ord(c_kbd_char) and $9f) of
^b : if NOT c_send_break then writeln('** BREAK not implemented **');
^d : set_delay;
^g : receive;
^h : menu;
^p : set_port;
^s : send;
^r : set_baud;
^q,^e : begin
close_file;
abort := c_reset;
halt;
end;
^w : close_file;
escape_char : ;
end;
previous_char := c_kbd_char;
end
else
begin
c_put_comm_char(c_kbd_char);
previous_char := c_kbd_char;
end;
end;
if c_get_comm_char then
begin
c_comm_char := chr(ord(c_comm_char) and $7f);
c_put_scr_char(c_comm_char);
if logging then
begin
buffer[bufptr] := c_comm_char;
bufptr := bufptr + 1;
end;
end;
until connect_end;
end;
begin
lowvideo;
cr_delay := 0;
bufptr := 0;
logging := false;
file_open := false;
writeln('Communications Demo Program Rev. ', revision);
writeln('Comm Library version ',c_lib_version);
if not c_init(1,1,1) then
begin
writeln('Initialization failed!');
abort := true;
end
else
abort := false;
if not abort then
repeat
connect;
until connect_end;
abort := c_reset;
end.