From: ppollet@cismibm.univ-lyon1.fr (Patrick POLLET)
Newsgroups: comp.lang.pascal
Subject: Re: TurboVision & COM routines
Date: Wed, 16 Dec 1992 11:38:53 GMT
Organization: INSA  CENTRE INFORMATIQUE DU 1er CYCLE
NNTP-Posting-Host: 134.214.232.25

In article <BzBEIq.9vG@nic.umass.edu> mcrocker@titan.ucc.umass.edu (MATTHEW S CROCKER) writes:
>From: mcrocker@titan.ucc.umass.edu (MATTHEW S CROCKER)
>Subject: TurboVision & COM routines
>Date: Tue, 15 Dec 1992 19:08:50 GMT


>I'm using TP 6.0 and will be getting BP7.0 soon.  I'm looking for some
>good TurboVision Com port routines.  I'm going to need to run upto 4
>COM ports at 9600 BPS (1 modem, 2 data,1 FAX).. I'll be using a 486 machine
>I am considering writing this in C++ but I know Pascal better

>Anyway,  Are there any good TV com routines outthere? which use
>tApplication.Idle or somesuch thing.  I would prefer something shareware 
>but will consider Comercial programs.


>PLEASE RESPOND VIA E-MAIL!!!!!!!
    
       NO!!! SEE TIMO'S F.A.Q . This may be of general interest....


   Here is some hints taken from a terminal emulator I wrote
    (without tTerminal which is slow). but i will checkout that
    article of PC-Technics !!!!!)

the technic is as follow:
   - declare a new event mask that will be processed only by
     terminal window and includes it in the FocusedEvents
     Turbovision global mask (in the application constructor)

Const evRS232=$1000;   (* unused flag *)

Constructor tMyApp.Init;
begin
  FocusedEvents:=FocusedEvents+evRS232;  (* signal processing of ComEvents*)
end;

   -overload tapplication.Getevent to include in the event polling
   the COM ports.

Procedure tMyApp.GetEvent(var Event:tEvent);
begin
  tApplication.GetEvent(Event);
      { give a lower priority to com events !!!!!!}
      { otherwise no commands (Break..) are possible while}
      { receiving a flow of char !!!!! }
   If Event.What=evNothing then  GetComEvent(Event);
end;

  The customized GetComEvent(), created on the same model as GetKeyEvent()
  and GetMouseEvent() . It return in the parameter Event the com event
  or evNothing if none...
  I use a commercial RS232 library that has the following entry points:
       ComError() return value of last error (0 if OK)
       ComInReady() return true if a char is available at the specified port
       CominChar() fectch the char at the port
       ComOutChar() emit
       ComtextError()  text of the last com error 
      You just will have to customize any P.D. RS232 library to get 
      equivalent calls.

Const cmComError=1;     (* event contains an error code *)
      cmCharIn=2;       (* event contais the code of the receive char *)

Procedure GetComEvent(var Event:tEvent);
var Ce:Word;
begin
  Ce:=ComErreur(ThePort);  (* check any communication error *)
  With Event do
    If Ce <>0 then
      begin
        what:=evRs232;
        Command:=cmComError; (* signal error *)
        InfoInt:=Ce
      end
   else
    if ComInReady(ThePort) then  (* any char at the port ? *)
      begin
        what:=evRS232;
        Command:=cmCharIn;
        ComInChar(ThePort,InfoChar)      (* Get that char *)
      end
   else What:=evNothing;
end;

  Here is the important part of the evnt loop in the terminal window:

Procedure tTerminalWindow.HandleEvent(var Event:tEvent);
begin
  tWindow.handleEvent(Event);
  With Event do
    case What of
      evCommand:
        begin
          .........
        end;
      evKeyDown:
        begin
          ..........
           Do something with the pressed key  (store....)
          .................
          ComOutChar(ThePort,CharCode) ; (* emit the char *)
          ...........
          ClearEvent(Event);
        end;
     evRS232:   (* <=========== processing of the new event type *)
       case Command of
         cmCharIn:
           begin
            ...........
            a character as arrived store it or whatever...
            .......
            ClearEvent(Event);
          end;
         cmComError:  (* an error has occured . say it....*)
           begin
             MessageBox(ComErreurText(InfoWord),NIL,mfOkButton+mfError);
             ........
             ClearEvent(Event)
           end
       end;
     end;
end;
    I did get that event loop runs at 9600 bauds (if the processing of
    incoming char is not too long. ) It is true that with a tTerminal
    object inserted in the tTerminalWindow I had some problems. 


Hope it helps......
ppollet@cismibm.univ-lyon1.fr (Patrick POLLET)
--------------------------------------------------------
Dr Patrick L.Pollet
Institut National des Sciences Appliques
Centre Informatique du 1er Cycle  Bat 110
20 Avenue A.Einstein
69621 Villeurbanne Cedex France
--------------------------------------------------------
Phone: 72 43 83 80 -   la premiere erreur c'est
Fax  : 72 43 85 33 -   de se lever le matin  ... GASTON
-------------------------------------------------------