home *** CD-ROM | disk | FTP | other *** search
- (*********************************************)
- (* *)
- (* MODEM.PAS Jan 92 *)
- (* *)
- (* MODEM sets and clears DTR and RTS and *)
- (* reads DSR, CTS, RI, and DCD *)
- (* *)
- (* This program is donated to the Public *)
- (* Domain by MarshallSoft Computing, Inc. *)
- (* It is provided as an example of the use *)
- (* of the Personal Communications Library. *)
- (* *)
- (*********************************************)
-
-
- program Modem;
- uses crt, PCL4P;
-
- Var
- Buffer : array[0..7] of Byte;
- Port : Integer;
-
- Procedure MyHalt( Code : Integer);
- var
- RetCode : Integer;
- begin
- if Code < 0 then RetCode := SioError(Code);
- RetCode := SioDone(Port);
- writeln('*** HALTING ***');
- Halt;
- end;
-
-
-
- Procedure Display;
- Var
- i : Integer;
- Begin
- GotoXY(1,1);
- WriteLn(' MODEM CONTROL'); Writeln;
- Write('Data Terminal Ready (DTR): ');
- if SioDTR(Port,READ) > 0 then WriteLn('ON ') else WriteLn('OFF');
- Write('Request to Send (RTS): ');
- if SioRTS(Port,READ) > 0 then WriteLn('ON ') else WriteLn('OFF');
- WriteLn; WriteLn(' MODEM STATUS'); WriteLn;
- Write('Data Set Ready (DSR): ');
- if SioDSR(Port) > 0 then WriteLn('ON ') else WriteLn('OFF');
- Write('Clear To Send (CTS): ');
- if SioCTS(Port) > 0 then WriteLn('ON ') else WriteLn('OFF');
- Write('Data Carrier Detect (DCD): ');
- if SioDCD(Port) > 0 then WriteLn('ON ') else WriteLn('OFF');
- Write('Ring Indicator (RI): ');
- if SioRI(Port) > 0 then WriteLn('ON ') else WriteLn('OFF')
- end;
-
-
- (* main program *)
-
- Var
- Row : Integer;
- Col : Integer;
- xRow : Integer;
- RetCode : Integer;
- I : Integer;
- C : Char;
- Begin
- (* fetch port from command line *)
- if ParamCount <> 1 then
- begin
- writeln('USAGE: "MODEM <port>" ');
- halt;
- end;
- Val( ParamStr(1), Port, RetCode);
- if RetCode <> 0 then
- begin
- writeln('Port must be 1 to 4');
- Halt;
- end;
- (* COM1 = 0, .., COM4 = 3 *)
- Port := Port - 1;
- (* must call SioRxBuf before SioReset *)
- RetCode := SioRxBuf(Port,Ofs(Buffer),Seg(Buffer),Size8);
- if RetCode < 0 then MyHalt(RetCode);
- (* reset port *)
- RetCode := SioReset(Port,NORESET);
- if RetCode < 0 then MyHalt(RetCode);
- TextMode(BW80);
- ClrScr;
- xRow := WhereY;
- Display;
- WriteLn;
- WriteLn('1) Set DTR 3) Clear DTR 5) Redisplay');
- WriteLn('2) Set RTS 4) Clear RTS 0) QUIT');
- WriteLn;
- Row := WhereY;
- while TRUE do
- begin
- (* clear keyboard *)
- while KeyPressed do C := ReadKey;
- (* get users' response *)
- GotoXY(1,Row);
- WriteLn('Select 0 to 5: ');
- GotoXY(15,Row);
- C := ReadKey; Write(C);
- if (C<'0') or (C>'5') then
- begin
- GotoXY(1,Row+1);
- Write('Must select 0 to 5. Type ENTER to continue');
- C := ReadKey;
- GotoXY(1,Row+1);
- for I := 0 to 41 do Write(' ');
- end
- else
- begin
- C := UpCase(C);
- case C of
- '0': (* QUIT *)
- begin
- RetCode := SioDone(Port);
- Halt
- end;
- '1': (* Set DTR *)
- RetCode := SioDTR(Port,SETON);
- '2': (* Set RTS *)
- RetCode := SioRTS(Port,SETON);
- '3': (* Clear DTR *)
- RetCode := SioDTR(Port,CLEAR);
- '4': (* Clear RTS *)
- RetCode := SioRTS(Port,CLEAR);
- '5': (* redisplay *)
- else
- begin
- Write('Bad response');
- end;
- end; (* case *)
- GotoXY(xRow,1);
- Display;
- end (* else *)
- end (* while *)
- end.