| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- (* 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.
|