COMMDEMO.MOD 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. (* Release 3.10 *)
  2. (*-------------------------------------------------------------------------*
  3. * *
  4. * COMMDEMO.MOD - COMMS Toolkit demonstration program *
  5. * *
  6. * COPYRIGHT (C) 1988..1992 Clarion Software Corporation. *
  7. * All Rights Reserved *
  8. * *
  9. *--------------------------------------------------------------------------*)
  10. MODULE CommDemo;
  11. IMPORT ComSetup,CommUtil,Filenames,IO,Keyboard,Lib,RS232,ScriptProcessor,
  12. Str,Term,Timer,Window;
  13. CONST
  14. TermWin = Window.WinDef(0,0,79,23,Window.LightGray,Window.Black,TRUE,FALSE,FALSE,FALSE,Window.SingleFrame,Window.White,Window.White);
  15. StatWin = Window.WinDef(0,24,79,24,Window.White,Window.Blue,TRUE,FALSE,FALSE,FALSE,Window.SingleFrame,Window.White,Window.White);
  16. GenWin = Window.WinDef(2,2,31,6,Window.White,Window.Blue,TRUE,FALSE,FALSE,TRUE,Window.SingleFrame,Window.White,Window.Blue);
  17. (*...............................................*)
  18. PROCEDURE Init;
  19. VAR
  20. stat : CommUtil.StatusFields;
  21. BEGIN
  22. ComSetup.InitSetup;
  23. WITH ComSetup.Setup.Serial DO
  24. RS232.SelectPort(Port);
  25. RS232.InitPort(Baud,DataBits,StopBits,Parity);
  26. END;
  27. RS232.Install;
  28. CASE ComSetup.Setup.Emulation OF
  29. Term.EmVT100 : Term.EmulateVT100; |
  30. Term.EmVT52 : Term.EmulateVT52; |
  31. Term.EmANSI : Term.EmulateANSI; |
  32. END;
  33. CommUtil.InitUtil;
  34. CommUtil.WrChar := Term.WrChar;
  35. ScriptProcessor.InitScriptProcessor;
  36. Timer.StartClock;
  37. Timer.StopClock;
  38. FOR stat:=CommUtil.logo TO CommUtil.time DO
  39. CommUtil.StatusLine(stat)
  40. END;
  41. END Init;
  42. (*...............................................*)
  43. PROCEDURE DialDirectory;
  44. VAR
  45. c : CHAR;
  46. Lnth : CARDINAL;
  47. Result : INTEGER;
  48. FileSpec : CommUtil.String80;
  49. BEGIN
  50. IF ScriptProcessor.ScriptState=ScriptProcessor.Off THEN
  51. Filenames.MakeFilename('',ComSetup.Setup.General.ScriptDir,'*','.CMD',FileSpec);
  52. Lnth := Str.Length(FileSpec);
  53. Result := CommUtil.SelectFile(1,1,'Dial',FileSpec,CommUtil.ScriptFile);
  54. IF Result>=0 THEN
  55. FileSpec[Lnth-5]:=0C;
  56. Str.Concat(CommUtil.ScriptFile,FileSpec,CommUtil.ScriptFile);
  57. IF ScriptProcessor.LoadScript(CommUtil.ScriptFile) THEN
  58. END;
  59. END;
  60. END;
  61. END DialDirectory;
  62. (*................................................*)
  63. PROCEDURE ToggleLogging(xpos,ypos:CARDINAL);
  64. VAR
  65. Ch : CHAR;
  66. BEGIN
  67. IF CommUtil.LogMode<>CommUtil.CloseLogging THEN
  68. CommUtil.SetLogMode(CommUtil.CloseLogging);
  69. ELSE
  70. CommUtil.CaptureFile[0] := 0C;
  71. CommUtil.ReadString(xpos,ypos,'Text Logging',' File Name? ',CommUtil.CaptureFile);
  72. IF (CommUtil.CaptureFile[0]=0C) AND (CommUtil.FuncKeyTyped<>CommUtil.Escape) THEN
  73. CommUtil.CaptureFile := 'TERM.LOG';
  74. END;
  75. IF CommUtil.CaptureFile[0]<>0C THEN
  76. CommUtil.SetLogMode(CommUtil.OpenLogging);
  77. END;
  78. END;
  79. END ToggleLogging;
  80. (*................................................*)
  81. PROCEDURE LeaveProgram():BOOLEAN;
  82. VAR
  83. Ch : CHAR;
  84. Win : Window.WinType;
  85. Def : Window.WinDef;
  86. BEGIN
  87. Def := GenWin;
  88. WITH Def DO
  89. Foreground := CommUtil.Colors.GenFore;
  90. Background := CommUtil.Colors.GenBack;
  91. FrameFore := CommUtil.Colors.GenFrFore;
  92. FrameBack := CommUtil.Colors.GenFrBack;
  93. END ;
  94. Win := Window.Open(Def);
  95. Window.GotoXY(3,2);
  96. IO.WrStr('Leave Program (Y/N): N');
  97. IO.WrChar(CHR(8));
  98. REPEAT
  99. Ch:=CAP(IO.RdKey());
  100. IF (Ch=CHR(27)) OR (Ch=CHR(13)) THEN
  101. Ch:='N';
  102. END;
  103. UNTIL (Ch='Y') OR (Ch='N');
  104. Window.Close(Win);
  105. RETURN Ch='Y';
  106. END LeaveProgram;
  107. (*................................................*)
  108. PROCEDURE Intro;
  109. VAR
  110. Ch : CHAR;
  111. Def : Window.WinDef;
  112. Win : Window.WinType;
  113. BEGIN
  114. Def := GenWin;
  115. WITH Def DO
  116. X1:=24;
  117. Y1:=3;
  118. X2:=X1+31;
  119. Y2:=Y1+17;
  120. CursorOn:=FALSE;
  121. Foreground := CommUtil.Colors.GenFore;
  122. Background := CommUtil.Colors.GenBack;
  123. FrameFore := CommUtil.Colors.GenFrFore;
  124. FrameBack := CommUtil.Colors.GenFrBack;
  125. END;
  126. Win := Window.Open(Def);
  127. IO.WrStr(' ----------------------------');
  128. IO.WrLn;
  129. IO.WrStr(' TopSpeed Modula-2 ');
  130. IO.WrLn;
  131. IO.WrStr(' Comms Toolkit V3.10 Demo');
  132. IO.WrLn;
  133. IO.WrStr(' ----------------------------');
  134. IO.WrLn;
  135. IO.WrStr(' Keys: ');
  136. IO.WrLn;
  137. IO.WrLn;
  138. IO.WrStr(' F1 : This info ');
  139. IO.WrLn;
  140. IO.WrStr(' ALT-0..9 : Send Macro ');
  141. IO.WrLn;
  142. IO.WrStr(' PgUp : Upload a File ');
  143. IO.WrLn;
  144. IO.WrStr(' PgDn : Download a File');
  145. IO.WrLn;
  146. IO.WrStr(' ALT-B : Send Break ');
  147. IO.WrLn;
  148. IO.WrStr(' ALT-D : Dial Menu ');
  149. IO.WrLn;
  150. IO.WrStr(' ALT-H : Hangup ');
  151. IO.WrLn;
  152. IO.WrStr(' ALT-L : Toggle Logging ');
  153. IO.WrLn;
  154. IO.WrStr(' ALT-S : Setup ');
  155. IO.WrLn;
  156. IO.WrStr(' ALT-X : Exit Demo ');
  157. WHILE NOT Term.KeyPressed() DO
  158. END;
  159. Window.Close(Win);
  160. END Intro;
  161. (*................................................*)
  162. PROCEDURE Terminal;
  163. VAR
  164. Carrier,EndSession: BOOLEAN;
  165. (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  166. PROCEDURE CheckCarrier;
  167. BEGIN
  168. IF Carrier<>RS232.CarrierDetect() THEN
  169. (* carrier has changed state *)
  170. Carrier := RS232.CarrierDetect();
  171. CommUtil.StatusLine(CommUtil.carrier);
  172. IF Carrier THEN
  173. Timer.StartClock
  174. ELSE
  175. Timer.StopClock
  176. END;
  177. END;
  178. IF Carrier THEN
  179. Timer.UpdateTimer;
  180. CommUtil.StatusLine(CommUtil.time);
  181. END;
  182. END CheckCarrier;
  183. (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  184. PROCEDURE SpecialKey;
  185. VAR
  186. c : CHAR;
  187. BEGIN
  188. c := Term.RdKey();
  189. CASE ORD(c) OF
  190. 31 : (* Alt-S *)
  191. ComSetup.ChangeSetup;
  192. CommUtil.StatusLine(CommUtil.emul); |
  193. 32 : (* Alt-D *)
  194. DialDirectory; |
  195. 35 : (* Alt-H - Hangup Line *)
  196. RS232.UnInstall; (* forces DTR & RTS to drop *)
  197. Lib.Delay(500);
  198. RS232.Install; |
  199. 38 : (* Alt-L - Toggle Logging *)
  200. ToggleLogging(10,10); |
  201. 45 : (* Alt-X - Exit Program *)
  202. EndSession := LeaveProgram(); |
  203. 48 : (* ALT-B - Send Break for half a second *)
  204. RS232.SetBreak(5); |
  205. 59 : (* F1 - Show Intro again *)
  206. Intro; |
  207. 73 : (* PgUp *)
  208. CommUtil.DoUpload; |
  209. 81 : (* PgDn *)
  210. CommUtil.DoDownload; |
  211. 120..129 : (* ALT-0 to ALT-9 *)
  212. CommUtil.TransmitMacro((ORD(c)+1) MOD 10); |
  213. END;
  214. END SpecialKey;
  215. (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  216. PROCEDURE CheckKeyboard;
  217. VAR
  218. c : CHAR;
  219. BEGIN
  220. IF Term.KeyPressed() THEN
  221. c := Term.RdKey();
  222. IF c=0C THEN
  223. SpecialKey
  224. ELSIF (c=CHR(27)) AND (ScriptProcessor.ScriptState<>ScriptProcessor.Off) THEN
  225. ScriptProcessor.TerminateScript;
  226. ELSE
  227. RS232.SerialWrite(c,1);
  228. END;
  229. END;
  230. END CheckKeyboard;
  231. (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  232. PROCEDURE CheckRemote;
  233. VAR
  234. c : CHAR;
  235. Cnt : CARDINAL;
  236. BEGIN
  237. Cnt := 0;
  238. WHILE (Cnt<10) AND RS232.SerialRead(c,0) DO
  239. CommUtil.Screen(c);
  240. INC(Cnt);
  241. END;
  242. END CheckRemote;
  243. (*. . . . . . . . . . . . . . . . . . . . . . . .*)
  244. BEGIN (* Terminal *)
  245. EndSession := FALSE;
  246. Carrier := FALSE;
  247. REPEAT
  248. CheckCarrier;
  249. CheckRemote;
  250. CheckKeyboard;
  251. ScriptProcessor.SingleStep;
  252. UNTIL EndSession;
  253. END Terminal;
  254. (*...............................................*)
  255. VAR
  256. Def : Window.WinDef;
  257. BEGIN (* CommDemo *)
  258. Def := StatWin;
  259. WITH Def DO
  260. Foreground := CommUtil.Colors.StatFore;
  261. Background := CommUtil.Colors.StatBack;
  262. END;
  263. CommUtil.StatW := Window.Open(Def);
  264. Def := TermWin;
  265. WITH Def DO
  266. Foreground := CommUtil.Colors.TermFore;
  267. Background := CommUtil.Colors.TermBack;
  268. END;
  269. CommUtil.TermW := Window.Open(Def);
  270. Init;
  271. Intro;
  272. Terminal;
  273. RS232.UnInstall;
  274. CommUtil.SetLogMode(CommUtil.CloseLogging);
  275. Window.Close(CommUtil.TermW);
  276. Window.Close(CommUtil.StatW);
  277. Window.CursorOn;
  278. END CommDemo.
  279.