(* Release 3.10 *) (*-------------------------------------------------------------------------* * * * COMMDEMO.MOD - COMMS Toolkit demonstration program * * * * COPYRIGHT (C) 1988..1992 Clarion Software Corporation. * * All Rights Reserved * * * *--------------------------------------------------------------------------*) MODULE CommDemo; IMPORT ComSetup,CommUtil,Filenames,IO,Keyboard,Lib,RS232,ScriptProcessor, Str,Term,Timer,Window; CONST TermWin = Window.WinDef(0,0,79,23,Window.LightGray,Window.Black,TRUE,FALSE,FALSE,FALSE,Window.SingleFrame,Window.White,Window.White); StatWin = Window.WinDef(0,24,79,24,Window.White,Window.Blue,TRUE,FALSE,FALSE,FALSE,Window.SingleFrame,Window.White,Window.White); GenWin = Window.WinDef(2,2,31,6,Window.White,Window.Blue,TRUE,FALSE,FALSE,TRUE,Window.SingleFrame,Window.White,Window.Blue); (*...............................................*) PROCEDURE Init; VAR stat : CommUtil.StatusFields; BEGIN ComSetup.InitSetup; WITH ComSetup.Setup.Serial DO RS232.SelectPort(Port); RS232.InitPort(Baud,DataBits,StopBits,Parity); END; RS232.Install; CASE ComSetup.Setup.Emulation OF Term.EmVT100 : Term.EmulateVT100; | Term.EmVT52 : Term.EmulateVT52; | Term.EmANSI : Term.EmulateANSI; | END; CommUtil.InitUtil; CommUtil.WrChar := Term.WrChar; ScriptProcessor.InitScriptProcessor; Timer.StartClock; Timer.StopClock; FOR stat:=CommUtil.logo TO CommUtil.time DO CommUtil.StatusLine(stat) END; END Init; (*...............................................*) PROCEDURE DialDirectory; VAR c : CHAR; Lnth : CARDINAL; Result : INTEGER; FileSpec : CommUtil.String80; BEGIN IF ScriptProcessor.ScriptState=ScriptProcessor.Off THEN Filenames.MakeFilename('',ComSetup.Setup.General.ScriptDir,'*','.CMD',FileSpec); Lnth := Str.Length(FileSpec); Result := CommUtil.SelectFile(1,1,'Dial',FileSpec,CommUtil.ScriptFile); IF Result>=0 THEN FileSpec[Lnth-5]:=0C; Str.Concat(CommUtil.ScriptFile,FileSpec,CommUtil.ScriptFile); IF ScriptProcessor.LoadScript(CommUtil.ScriptFile) THEN END; END; END; END DialDirectory; (*................................................*) PROCEDURE ToggleLogging(xpos,ypos:CARDINAL); VAR Ch : CHAR; BEGIN IF CommUtil.LogMode<>CommUtil.CloseLogging THEN CommUtil.SetLogMode(CommUtil.CloseLogging); ELSE CommUtil.CaptureFile[0] := 0C; CommUtil.ReadString(xpos,ypos,'Text Logging',' File Name? ',CommUtil.CaptureFile); IF (CommUtil.CaptureFile[0]=0C) AND (CommUtil.FuncKeyTyped<>CommUtil.Escape) THEN CommUtil.CaptureFile := 'TERM.LOG'; END; IF CommUtil.CaptureFile[0]<>0C THEN CommUtil.SetLogMode(CommUtil.OpenLogging); END; END; END ToggleLogging; (*................................................*) PROCEDURE LeaveProgram():BOOLEAN; VAR Ch : CHAR; Win : Window.WinType; Def : Window.WinDef; BEGIN Def := GenWin; WITH Def DO Foreground := CommUtil.Colors.GenFore; Background := CommUtil.Colors.GenBack; FrameFore := CommUtil.Colors.GenFrFore; FrameBack := CommUtil.Colors.GenFrBack; END ; Win := Window.Open(Def); Window.GotoXY(3,2); IO.WrStr('Leave Program (Y/N): N'); IO.WrChar(CHR(8)); REPEAT Ch:=CAP(IO.RdKey()); IF (Ch=CHR(27)) OR (Ch=CHR(13)) THEN Ch:='N'; END; UNTIL (Ch='Y') OR (Ch='N'); Window.Close(Win); RETURN Ch='Y'; END LeaveProgram; (*................................................*) PROCEDURE Intro; VAR Ch : CHAR; Def : Window.WinDef; Win : Window.WinType; BEGIN Def := GenWin; WITH Def DO X1:=24; Y1:=3; X2:=X1+31; Y2:=Y1+17; CursorOn:=FALSE; Foreground := CommUtil.Colors.GenFore; Background := CommUtil.Colors.GenBack; FrameFore := CommUtil.Colors.GenFrFore; FrameBack := CommUtil.Colors.GenFrBack; END; Win := Window.Open(Def); IO.WrStr(' ----------------------------'); IO.WrLn; IO.WrStr(' TopSpeed Modula-2 '); IO.WrLn; IO.WrStr(' Comms Toolkit V3.10 Demo'); IO.WrLn; IO.WrStr(' ----------------------------'); IO.WrLn; IO.WrStr(' Keys: '); IO.WrLn; IO.WrLn; IO.WrStr(' F1 : This info '); IO.WrLn; IO.WrStr(' ALT-0..9 : Send Macro '); IO.WrLn; IO.WrStr(' PgUp : Upload a File '); IO.WrLn; IO.WrStr(' PgDn : Download a File'); IO.WrLn; IO.WrStr(' ALT-B : Send Break '); IO.WrLn; IO.WrStr(' ALT-D : Dial Menu '); IO.WrLn; IO.WrStr(' ALT-H : Hangup '); IO.WrLn; IO.WrStr(' ALT-L : Toggle Logging '); IO.WrLn; IO.WrStr(' ALT-S : Setup '); IO.WrLn; IO.WrStr(' ALT-X : Exit Demo '); WHILE NOT Term.KeyPressed() DO END; Window.Close(Win); END Intro; (*................................................*) PROCEDURE Terminal; VAR Carrier,EndSession: BOOLEAN; (*. . . . . . . . . . . . . . . . . . . . . . . .*) PROCEDURE CheckCarrier; BEGIN IF Carrier<>RS232.CarrierDetect() THEN (* carrier has changed state *) Carrier := RS232.CarrierDetect(); CommUtil.StatusLine(CommUtil.carrier); IF Carrier THEN Timer.StartClock ELSE Timer.StopClock END; END; IF Carrier THEN Timer.UpdateTimer; CommUtil.StatusLine(CommUtil.time); END; END CheckCarrier; (*. . . . . . . . . . . . . . . . . . . . . . . .*) PROCEDURE SpecialKey; VAR c : CHAR; BEGIN c := Term.RdKey(); CASE ORD(c) OF 31 : (* Alt-S *) ComSetup.ChangeSetup; CommUtil.StatusLine(CommUtil.emul); | 32 : (* Alt-D *) DialDirectory; | 35 : (* Alt-H - Hangup Line *) RS232.UnInstall; (* forces DTR & RTS to drop *) Lib.Delay(500); RS232.Install; | 38 : (* Alt-L - Toggle Logging *) ToggleLogging(10,10); | 45 : (* Alt-X - Exit Program *) EndSession := LeaveProgram(); | 48 : (* ALT-B - Send Break for half a second *) RS232.SetBreak(5); | 59 : (* F1 - Show Intro again *) Intro; | 73 : (* PgUp *) CommUtil.DoUpload; | 81 : (* PgDn *) CommUtil.DoDownload; | 120..129 : (* ALT-0 to ALT-9 *) CommUtil.TransmitMacro((ORD(c)+1) MOD 10); | END; END SpecialKey; (*. . . . . . . . . . . . . . . . . . . . . . . .*) PROCEDURE CheckKeyboard; VAR c : CHAR; BEGIN IF Term.KeyPressed() THEN c := Term.RdKey(); IF c=0C THEN SpecialKey ELSIF (c=CHR(27)) AND (ScriptProcessor.ScriptState<>ScriptProcessor.Off) THEN ScriptProcessor.TerminateScript; ELSE RS232.SerialWrite(c,1); END; END; END CheckKeyboard; (*. . . . . . . . . . . . . . . . . . . . . . . .*) PROCEDURE CheckRemote; VAR c : CHAR; Cnt : CARDINAL; BEGIN Cnt := 0; WHILE (Cnt<10) AND RS232.SerialRead(c,0) DO CommUtil.Screen(c); INC(Cnt); END; END CheckRemote; (*. . . . . . . . . . . . . . . . . . . . . . . .*) BEGIN (* Terminal *) EndSession := FALSE; Carrier := FALSE; REPEAT CheckCarrier; CheckRemote; CheckKeyboard; ScriptProcessor.SingleStep; UNTIL EndSession; END Terminal; (*...............................................*) VAR Def : Window.WinDef; BEGIN (* CommDemo *) Def := StatWin; WITH Def DO Foreground := CommUtil.Colors.StatFore; Background := CommUtil.Colors.StatBack; END; CommUtil.StatW := Window.Open(Def); Def := TermWin; WITH Def DO Foreground := CommUtil.Colors.TermFore; Background := CommUtil.Colors.TermBack; END; CommUtil.TermW := Window.Open(Def); Init; Intro; Terminal; RS232.UnInstall; CommUtil.SetLogMode(CommUtil.CloseLogging); Window.Close(CommUtil.TermW); Window.Close(CommUtil.StatW); Window.CursorOn; END CommDemo.