home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
communic
/
ship
/
ship.pas
Wrap
Pascal/Delphi Source File
|
1987-11-08
|
8KB
|
258 lines
{-------------------------------- ship -----------------------------}
{
Purpose: To allow simple communications between the Slicer and
another system capable of sending and receiving characters
on an RS-232 port.
Method: In Receive mode, SHIP accepts characters from port A
of the Expansion Board and puts them into a file. This
continues until a key is struck (on the Slicer). The
file is then closed. No error checking can be done with
this primitive method, so you should check the file for
errors after you have received it.
In Send mode, SHIP simply opens the requested file and
sends it out port A of the Expansion board, one character
at a time until the entire file has been sent.
Terminal mode is mainly for debugging and making sure that
both ends are cooperating. Terminal mode just gets
characters from the keyboard and sends them to the other
end while receiving characters and displaying them on the
screen.
History: Laine Stump March 30,1985 vrs 1.0
}
{-------------------------------------------------------------------}
PROGRAM ship (input, output, workfile);
CONST
XON = ^Q; { codes for stopping/starting character stream }
XOFF = ^S;
modereg = $200; { SC2681 mode }
statusreg = $202; { " status }
baudreg = $202; { " baudrate }
commandreg = $204; { " command }
datareg = $206; { " data }
ACRreg = $208; { " baudrate set }
IMRreg = $20A; { " interrupt mode }
TxRdy = 4; { status mask for Transmit Ready }
RxRdy = 1; { status mask for Receive Ready }
IMRBYTE = $00; { turn off all interrupts }
COMBYTE = $15; { point to MR1, enable Tx & Rx }
MODEBYTE1 = $93; { use RTS/CTS, no parity, 8 bits }
MODEBYTE2 = $1F; { 2 stop bits }
SET2 = $80; { select baudrate set 2 }
BAUD300 = $44; BAUD600 = $55;
BAUD1200 = $66; BAUD2400 = $88;
BAUD4800 = $99; BAUD9600 = $BB;
BAUD19200 = $CC;
VAR
workfile : text;
{ ct & ct2 are global so they will be static variables }
{ this is because static variables are sometimes faster }
ct, ct2 : integer;
buffer : array[1..2048] of char;
baudrate : integer;
bits7 : boolean;
selection : char;
{-----------------------------------------}
{ initialize port for reading and writing }
{-----------------------------------------}
PROCEDURE initport ( baudrate : integer );
begin
port[IMRreg] := IMRBYTE; { turn off ints }
port[commandreg] := COMBYTE; { point to modebyte1 }
port[modereg] := MODEBYTE1; { set modes }
port[modereg] := MODEBYTE2;
port[ACRreg] := SET2; { use baudrate set 2 }
CASE (baudrate) OF { set requested baudrate }
300 : port[baudreg] := BAUD300;
600 : port[baudreg] := BAUD600;
1200 : port[baudreg] := BAUD1200;
2400 : port[baudreg] := BAUD2400;
4800 : port[baudreg] := BAUD4800;
9600 : port[baudreg] := BAUD9600;
19200 : port[baudreg] := BAUD19200
end { case baudrate }
end;
{-----------------------------------------------}
{ return TRUE if char ready, FALSE if not }
{-----------------------------------------------}
FUNCTION ReadPortStat : boolean;
begin
ReadPortStat := ((port[statusreg] and RxRdy) <> 0)
end; { ReadPortStat }
{-----------------------------------------------}
{ read a byte from port and return it to caller }
{-----------------------------------------------}
FUNCTION ReadPort : char;
begin
REPEAT UNTIL (ReadPortStat); { wait for char }
IF bits7 THEN
ReadPort := chr(port[datareg] and $7F)
ELSE
ReadPort := chr(port[datareg])
end; { ReadPort }
{-----------------------------------------------}
{ write a byte to port }
{-----------------------------------------------}
PROCEDURE WritePort ( thisbyte : char );
begin
REPEAT UNTIL (port[statusreg] and TxRdy) <> 0;
IF bits7 THEN
port[datareg] := ord(thisbyte) and $7F
ELSE
port[datareg] := ord(thisbyte)
end; { WritePort }
{ - - - beyond here is hardware independent - - - }
{-----------------------------------------------}
{ prompt for a baudrate and init the port }
{-----------------------------------------------}
PROCEDURE SetBaud (var baudrate : integer);
var yn : char;
begin
writeln;
write ('Baudrate: ');
readln (baudrate);
InitPort(baudrate);
write ('Strip high bit? ');
read (kbd,yn); writeln (yn);
bits7 := (upcase(yn) = 'Y')
end; { SetBaud }
{---------------------------------------}
{ send chars typed at console to port }
{ while echoing received chars }
{---------------------------------------}
PROCEDURE Terminal;
VAR done : boolean;
ch : char;
begin
writeln('Terminal Mode, baudrate is ',baudrate);
writeln('Type control+_ to end');
writeln;
done := FALSE;
REPEAT
IF (KeyPressed) THEN { char typed ? }
begin
read(kbd, ch);
IF (ch = ^_) THEN
done := TRUE
ELSE
WritePort(ch); { send it }
end; { if keypressed }
IF (ReadPortStat) THEN { char received ? }
write(ReadPort) { display it }
UNTIL (done);
end; { terminal }
{----------------------------------}
{ receive a file from the port }
{----------------------------------}
PROCEDURE Receive;
var filename : string[80];
begin
write('Name for Received file: ');
readln(filename);
assign(workfile, filename);
rewrite (workfile);
write ('Start sending from other end, ');
writeln ('press a key on this keyboard when done');
ct := 0;
WHILE (not Keypressed) DO
IF (ReadPortStat) THEN
begin
ct := ct + 1;
buffer[ct] := ReadPort; { save in buffer }
IF (buffer[ct] = ^M) THEN
begin
WritePort(XOFF); { turn off other end }
FOR ct2 := 1 to ct DO { dump buffer to file }
write (workfile, buffer[ct2]);
ct := 0;
WritePort(XON); { turn back on }
end; { if received char = ^M }
end; { if character ready }
IF (ct > 0) THEN { write out partial line }
FOR ct2 := 1 to ct DO
write(workfile, buffer[ct2]);
close (workfile)
end; { Receive }
{--------------------------------}
{ send a file out the port }
{--------------------------------}
PROCEDURE Send;
var ch : char;
filename : string[80];
begin
write('Name of File to Send: ');
readln(filename);
assign(workfile, filename);
reset (workfile);
write ('Set up other end to receive, ');
writeln ('press a key on this keyboard when ready');
REPEAT UNTIL (Keypressed);
WHILE (not EOF(workfile)) DO
begin
IF (ReadPortStat) THEN { check for XOFF }
IF (ReadPort = XOFF) THEN
REPEAT UNTIL (ReadPort = XON);
read(workfile, ch); { get a char }
WritePort (ch); { send it }
IF (ch = ^M) THEN { IF eoln wait for XON }
REPEAT UNTIL (ReadPort = XON)
end; { while not eof }
close (workfile)
end; { Receive }
{---- main ----}
begin
SetBaud (baudrate);
REPEAT
writeln;
write ('<B>audrate, <T>erminal, <S>end, <R>eceive, <Q>uit: ');
read(kbd,selection); writeln(selection);
CASE (upcase(selection)) OF
'B' : SetBaud (baudrate);
'T' : Terminal;
'R' : Receive;
'S' : Send;
'Q','E','X' : ;
ELSE
writeln ('Bad Option, Try Again');
end { case selection }
UNTIL (upcase(selection) in ['Q','X','E']);
writeln ('Bye now, have a good afternoon.')
end.