home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / pascal / 7510 < prev    next >
Encoding:
Text File  |  1992-12-16  |  5.0 KB  |  152 lines

  1. Path: sparky!uunet!think.com!rpi!ghost.dsi.unimi.it!univ-lyon1.fr!cismibm.univ-lyon1.fr!ppollet
  2. From: ppollet@cismibm.univ-lyon1.fr (Patrick POLLET)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: TurboVision & COM routines
  5. Date: Wed, 16 Dec 1992 11:38:53 GMT
  6. Organization: INSA  CENTRE INFORMATIQUE DU 1er CYCLE
  7. Lines: 140
  8. Message-ID: <ppollet.74.724505933@cismibm.univ-lyon1.fr>
  9. References: <BzBEIq.9vG@nic.umass.edu>
  10. NNTP-Posting-Host: 134.214.232.25
  11.  
  12. In article <BzBEIq.9vG@nic.umass.edu> mcrocker@titan.ucc.umass.edu (MATTHEW S CROCKER) writes:
  13. >From: mcrocker@titan.ucc.umass.edu (MATTHEW S CROCKER)
  14. >Subject: TurboVision & COM routines
  15. >Date: Tue, 15 Dec 1992 19:08:50 GMT
  16.  
  17.  
  18. >I'm using TP 6.0 and will be getting BP7.0 soon.  I'm looking for some
  19. >good TurboVision Com port routines.  I'm going to need to run upto 4
  20. >COM ports at 9600 BPS (1 modem, 2 data,1 FAX).. I'll be using a 486 machine
  21. >I am considering writing this in C++ but I know Pascal better
  22.  
  23. >Anyway,  Are there any good TV com routines outthere? which use
  24. >tApplication.Idle or somesuch thing.  I would prefer something shareware 
  25. >but will consider Comercial programs.
  26.  
  27.  
  28. >PLEASE RESPOND VIA E-MAIL!!!!!!!
  29.     
  30.        NO!!! SEE TIMO'S F.A.Q . This may be of general interest....
  31.  
  32.  
  33.    Here is some hints taken from a terminal emulator I wrote
  34.     (without tTerminal which is slow). but i will checkout that
  35.     article of PC-Technics !!!!!)
  36.  
  37. the technic is as follow:
  38.    - declare a new event mask that will be processed only by
  39.      terminal window and includes it in the FocusedEvents
  40.      Turbovision global mask (in the application constructor)
  41.  
  42. Const evRS232=$1000;   (* unused flag *)
  43.  
  44. Constructor tMyApp.Init;
  45. begin
  46.   FocusedEvents:=FocusedEvents+evRS232;  (* signal processing of ComEvents*)
  47. end;
  48.  
  49.    -overload tapplication.Getevent to include in the event polling
  50.    the COM ports.
  51.  
  52. Procedure tMyApp.GetEvent(var Event:tEvent);
  53. begin
  54.   tApplication.GetEvent(Event);
  55.       { give a lower priority to com events !!!!!!}
  56.       { otherwise no commands (Break..) are possible while}
  57.       { receiving a flow of char !!!!! }
  58.    If Event.What=evNothing then  GetComEvent(Event);
  59. end;
  60.  
  61.   The customized GetComEvent(), created on the same model as GetKeyEvent()
  62.   and GetMouseEvent() . It return in the parameter Event the com event
  63.   or evNothing if none...
  64.   I use a commercial RS232 library that has the following entry points:
  65.        ComError() return value of last error (0 if OK)
  66.        ComInReady() return true if a char is available at the specified port
  67.        CominChar() fectch the char at the port
  68.        ComOutChar() emit
  69.        ComtextError()  text of the last com error 
  70.       You just will have to customize any P.D. RS232 library to get 
  71.       equivalent calls.
  72.  
  73. Const cmComError=1;     (* event contains an error code *)
  74.       cmCharIn=2;       (* event contais the code of the receive char *)
  75.  
  76. Procedure GetComEvent(var Event:tEvent);
  77. var Ce:Word;
  78. begin
  79.   Ce:=ComErreur(ThePort);  (* check any communication error *)
  80.   With Event do
  81.     If Ce <>0 then
  82.       begin
  83.         what:=evRs232;
  84.         Command:=cmComError; (* signal error *)
  85.         InfoInt:=Ce
  86.       end
  87.    else
  88.     if ComInReady(ThePort) then  (* any char at the port ? *)
  89.       begin
  90.         what:=evRS232;
  91.         Command:=cmCharIn;
  92.         ComInChar(ThePort,InfoChar)      (* Get that char *)
  93.       end
  94.    else What:=evNothing;
  95. end;
  96.  
  97.   Here is the important part of the evnt loop in the terminal window:
  98.  
  99. Procedure tTerminalWindow.HandleEvent(var Event:tEvent);
  100. begin
  101.   tWindow.handleEvent(Event);
  102.   With Event do
  103.     case What of
  104.       evCommand:
  105.         begin
  106.           .........
  107.         end;
  108.       evKeyDown:
  109.         begin
  110.           ..........
  111.            Do something with the pressed key  (store....)
  112.           .................
  113.           ComOutChar(ThePort,CharCode) ; (* emit the char *)
  114.           ...........
  115.           ClearEvent(Event);
  116.         end;
  117.      evRS232:   (* <=========== processing of the new event type *)
  118.        case Command of
  119.          cmCharIn:
  120.            begin
  121.             ...........
  122.             a character as arrived store it or whatever...
  123.             .......
  124.             ClearEvent(Event);
  125.           end;
  126.          cmComError:  (* an error has occured . say it....*)
  127.            begin
  128.              MessageBox(ComErreurText(InfoWord),NIL,mfOkButton+mfError);
  129.              ........
  130.              ClearEvent(Event)
  131.            end
  132.        end;
  133.      end;
  134. end;
  135.     I did get that event loop runs at 9600 bauds (if the processing of
  136.     incoming char is not too long. ) It is true that with a tTerminal
  137.     object inserted in the tTerminalWindow I had some problems. 
  138.  
  139.  
  140. Hope it helps......
  141. ppollet@cismibm.univ-lyon1.fr (Patrick POLLET)
  142. --------------------------------------------------------
  143. Dr Patrick L.Pollet
  144. Institut National des Sciences Appliquées
  145. Centre Informatique du 1er Cycle  Bat 110
  146. 20 Avenue A.Einstein
  147. 69621 Villeurbanne Cedex France
  148. --------------------------------------------------------
  149. Phone: 72 43 83 80 -   la premiere erreur c'est
  150. Fax  : 72 43 85 33 -   de se lever le matin  ... GASTON
  151. -------------------------------------------------------
  152.