home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / PMCOMMST.ZIP / PMCOMM.MOD < prev    next >
Text File  |  1990-10-25  |  19KB  |  624 lines

  1. MODULE PMComm;
  2.  
  3. (* ////////////////////////////////////////////////////////////// *)
  4. (* /  This is a Presentation Manager program  used  to set the  / *)
  5. (* /  comm ports.                                               / *)
  6. (* /                                                            / *)
  7. (* /  There is two ways to operate the PMComm program. Loading  / *)
  8. (* /  PMComm directly without  command line parameters, allows  / *)
  9. (* /  interactively set  and save the comm port paramters.  If  / *)
  10. (* /  the /S command line directive  is added then when PMComm  / *)
  11. (* /  is called, it sets the comm port then emmeadiatly ends.   / *)
  12. (* /                                                            / *)
  13. (* /  Example:                                                  / *)
  14. (* /    [C:\] PMCOMM          ; Loads in interactive mode       / *)
  15. (* /    [C:\] PMCOMM /S       ; Sets comm port then ends        / *)
  16. (* /                                                            / *)
  17. (* ////////////////////////////////////////////////////////////// *)
  18.  
  19.   IMPORT Win,Gpi,Dos,Err;  (* mod  *)
  20.  
  21.   FROM OS2DEF IMPORT
  22.     HAB,                   (* type *)
  23.     HPS,                   (* type *)
  24.     HWND,                  (* type *)
  25.     HBITMAP,
  26.     POINTL,                (* type *)
  27.     RECTL,                 (* type *)
  28.     LSET,                  (* type *)
  29.     BOOL,                  (* var  *)
  30.     NULL;                  (* var  *)
  31.  
  32.   FROM SYSTEM IMPORT
  33.     Seg;                   (* proc *)
  34.  
  35.   FROM Strings IMPORT
  36.     Pos,
  37.     Assign,
  38.     Concat,
  39.     Delete,
  40.     Copy,
  41.     Length;
  42.  
  43.   FROM Str IMPORT
  44.     StrToCard,
  45.     CardToStr,
  46.     Caps;
  47.  
  48.   FROM FIO IMPORT
  49.     MkDir,
  50.     Erase,
  51.     Create,
  52.     Open,
  53.     Close,
  54.     File,
  55.     EOF,
  56.     IOcheck,
  57.     IOresult,
  58.     Exists,
  59.     RdBin,
  60.     RdChar,
  61.     RdStr,
  62.     WrBin,
  63.     WrStr,
  64.     WrLn,
  65.     WrChar;
  66.  
  67.   FROM Lib IMPORT
  68.     Exec,
  69.     ParamCount,
  70.     ParamStr;
  71. (*
  72.   FROM PMPlotFile IMPORT
  73.     FileName,
  74.     IDD_OPEN,
  75.     OpenDlgProc;
  76.  
  77.   FROM PMPlotHelp IMPORT
  78.     HelpDlgProc;
  79. *)
  80.   FROM PMPlotGlobal IMPORT
  81.     WorkPath;
  82.  
  83.   CONST
  84.     WindowId = 255;
  85.  
  86.     ID_ICON   = 255;
  87.     ID_BITMAP = 25;
  88.  
  89.     IDM_HELP    = 2;
  90.     IDM_EXIT    = 4;
  91.     IDM_CONFIG  = 9;
  92.  
  93.     IDD_CONFIG  = 275;
  94.     IDD_HELP    = 257;
  95.  
  96.     IDD_COM1 = 284;
  97.     IDD_COM2 = 285;
  98.  
  99.     IDD_9600 = 287;
  100.     IDD_4800 = 288;
  101.     IDD_2400 = 289;
  102.  
  103.     IDD_NONE = 291;
  104.     IDD_ODD  = 292;
  105.     IDD_EVEN = 293;
  106.  
  107.     IDD_DB7 =  296;
  108.     IDD_DB8 =  295;
  109.  
  110.     IDD_SB1 =  298;
  111.     IDD_SB2 =  299;
  112.  
  113.     IDD_XON =  301;
  114.     IDD_DSR =  302;
  115.  
  116.     IDD_WRKPATH = 313;
  117.  
  118.   TYPE
  119.     QueueInfoType = RECORD
  120.                       CharsInQueue : CARDINAL;
  121.                       QueueSize    : CARDINAL;
  122.                     END;
  123.  
  124.     Func41Type = RECORD
  125.                    BaudRate : CARDINAL;
  126.                  END;
  127.  
  128.     LineControlType = RECORD
  129.                         DataBits   : BYTE;
  130.                         Parity     : BYTE;
  131.                         StopBits   : BYTE;
  132.                         TransBreak : BYTE;
  133.                       END;
  134.  
  135.     DCBType = RECORD
  136.                 WriteTimeout         : CARDINAL;
  137.                 ReadTimeout          : CARDINAL;
  138.                 CtlHndShake          : BYTE;
  139.                 FlowReplace          : BYTE;
  140.                 Timeout              : BYTE;
  141.                 ErrorReplacementChar : BYTE;
  142.                 BreakReplacementChar : BYTE;
  143.                 XONChar              : BYTE;
  144.                 XOFFChar             : BYTE;
  145.               END;
  146.  
  147.     CommPortType = RECORD
  148.                     Name     : ARRAY[0..14] OF CHAR;
  149.                     BaudRate : CARDINAL;
  150.                     Parity   : BYTE;
  151.                     DataBits : BYTE;
  152.                     StopBits : BYTE;
  153.                     XonXoff  : BOOLEAN;
  154.                     Speed    : CARDINAL;
  155.                   END;
  156.  
  157.   VAR
  158.     ActivePort,
  159.     result      : CARDINAL;
  160.     mresult     : Win.MRESULT;
  161.     Func41      : Func41Type;
  162.     LineControl : LineControlType;
  163.     DCB         : DCBType;
  164.     Hab         : HAB;
  165.     Hps         : HPS;
  166.     hwndFrame,
  167.     frame       : HWND;
  168.     hmq         : Win.HMQ;
  169.     qmsg        : Win.QMSG;
  170.     hwndWndw,
  171.     client      : HWND;
  172.     hbmAbleIcon : HBITMAP;
  173.     createfl    : LSET;
  174.     SetThenExit,
  175.     ok          : BOOLEAN;
  176.     cxChar,
  177.     cyChar,
  178.     cxClient,
  179.     cyClient    : LONGINT;
  180.     DriveStr    : ARRAY[0..5] OF CHAR;
  181.  
  182.     OldCommPort,
  183.     CommPort     : ARRAY[1..3] OF CommPortType;
  184.  
  185.  
  186.   PROCEDURE ReadConfiguration();
  187.  
  188.   (* /////////////////////////////////////////////////// *)
  189.   (* /  This routine reads the configuration file and  / *)
  190.   (* /  sets the program's variables.                  / *)
  191.   (* /////////////////////////////////////////////////// *)
  192.  
  193.     VAR
  194.       CfgFile : File;
  195.       CfgName,
  196.       Str     : ARRAY[0..79] OF CHAR;
  197.       i,j     : CARDINAL;
  198.       ok      : BOOLEAN;
  199.  
  200.   BEGIN
  201.     CfgName := 'PMCOMM.CFG';
  202.     IF  Length(WorkPath) > 0  THEN
  203.       IF  WorkPath[Length(WorkPath)] # '\'  THEN
  204.         Concat('\',CfgName,CfgName);
  205.       END;
  206.       Concat(WorkPath,CfgName,CfgName);
  207.     END;
  208.     IF  Exists(CfgName)  THEN
  209.       CfgFile := Open(CfgName);
  210.       FOR  i := 1  TO  2  DO
  211.         FOR  j := 1  TO  6  DO
  212.           RdStr(CfgFile,Str);
  213.           CASE  j  OF
  214.             1 : CommPort[i].BaudRate := CARDINAL(StrToCard(Str,10,ok));|
  215.             2 : CommPort[i].Parity   := BYTE(StrToCard(Str,10,ok));|
  216.             3 : CommPort[i].DataBits := BYTE(StrToCard(Str,10,ok));|
  217.             4 : CommPort[i].StopBits := BYTE(StrToCard(Str,10,ok));|
  218.             5 : CommPort[i].XonXoff  := BOOLEAN(StrToCard(Str,10,ok));|
  219.             6 : CommPort[i].Speed    := CARDINAL(StrToCard(Str,10,ok));
  220.           END;
  221.         END;
  222.       END;
  223.       RdStr(CfgFile,Str);
  224.       Assign(Str,WorkPath);
  225.       Close(CfgFile);
  226.     ELSE
  227.       WorkPath  := '';
  228.       FOR  i := 1  TO  2  DO
  229.         CommPort[i].BaudRate := 9600;
  230.         CommPort[i].DataBits := 8;
  231.         CommPort[i].StopBits := 1;
  232.         CommPort[i].Parity   := 0;
  233.         CommPort[i].XonXoff  := FALSE;
  234.       END;
  235.     END;
  236.   END ReadConfiguration;
  237.  
  238.  
  239.   PROCEDURE WriteConfiguration();
  240.  
  241.   (* //////////////////////////////////////////////////////////// *)
  242.   (* /  This routine writes the PMPLOT program's configuration  / *)
  243.   (* /  to the PMPLOT.CFG file.                                 / *)
  244.   (* //////////////////////////////////////////////////////////// *)
  245.  
  246.     VAR
  247.       CfgFile : File;
  248.       CfgName,
  249.       Str     : ARRAY[0..79] OF CHAR;
  250.       i,j     : CARDINAL;
  251.       ok      : BOOLEAN;
  252.  
  253.   BEGIN
  254.     CfgName := 'PMCOMM.CFG';
  255.     IF  Length(WorkPath) > 0  THEN
  256.       IF  WorkPath[Length(WorkPath)] # '\'  THEN
  257.         Concat('\',CfgName,CfgName);
  258.       END;
  259.       Concat(WorkPath,CfgName,CfgName);
  260.     END;
  261.     CfgFile := Create(CfgName);
  262.     FOR  i := 1  TO  2  DO
  263.       FOR  j := 1  TO  6  DO
  264.         CASE  j  OF
  265.           1 : CardToStr(LONGCARD(CommPort[i].BaudRate),Str,10,ok);|
  266.           2 : CardToStr(LONGCARD(CommPort[i].Parity),Str,10,ok);|
  267.           3 : CardToStr(LONGCARD(CommPort[i].DataBits),Str,10,ok);|
  268.           4 : CardToStr(LONGCARD(CommPort[i].StopBits),Str,10,ok);|
  269.           5 : CardToStr(LONGCARD(CommPort[i].XonXoff),Str,10,ok);|
  270.           6 : CardToStr(LONGCARD(CommPort[i].Speed),Str,10,ok);
  271.         END;
  272.         WrStr(CfgFile,Str);
  273.         WrLn(CfgFile);
  274.       END;
  275.     END;
  276.     WrStr(CfgFile,WorkPath);
  277.     WrLn(CfgFile);
  278.     Close(CfgFile);
  279.   END WriteConfiguration;
  280.  
  281.  
  282.   PROCEDURE SetCfgPortStatus(hwnd : HWND; ActivePort : CARDINAL);
  283.  
  284.   (* //////////////////////////////////////////////////////// *)
  285.   (* /  This routine sets the radio buttons to the current  / *)
  286.   (* /  status for the active port.                         / *)
  287.   (* //////////////////////////////////////////////////////// *)
  288.  
  289.   BEGIN
  290.     CASE  CommPort[ActivePort].BaudRate  OF
  291.       9600 : Win.SendDlgItemMsg(hwnd,IDD_9600,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  292.       4800 : Win.SendDlgItemMsg(hwnd,IDD_4800,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  293.       2400 : Win.SendDlgItemMsg(hwnd,IDD_2400,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  294.     END;
  295.     CASE  CARDINAL(CommPort[ActivePort].Parity)  OF
  296.       0 : Win.SendDlgItemMsg(hwnd,IDD_NONE,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  297.       1 : Win.SendDlgItemMsg(hwnd,IDD_ODD,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  298.       2 : Win.SendDlgItemMsg(hwnd,IDD_EVEN,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  299.     END;
  300.     CASE  CARDINAL(CommPort[ActivePort].DataBits)  OF
  301.       7 : Win.SendDlgItemMsg(hwnd,IDD_DB7,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  302.       8 : Win.SendDlgItemMsg(hwnd,IDD_DB8,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  303.     END;
  304.     CASE  CARDINAL(CommPort[ActivePort].StopBits)  OF
  305.       0 : Win.SendDlgItemMsg(hwnd,IDD_SB1,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  306.       2 : Win.SendDlgItemMsg(hwnd,IDD_SB2,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);|
  307.     END;
  308.     IF  CommPort[ActivePort].XonXoff  THEN
  309.       Win.SendDlgItemMsg(hwnd,IDD_XON,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);
  310.     ELSE
  311.       Win.SendDlgItemMsg(hwnd,IDD_DSR,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);
  312.     END;
  313.   END SetCfgPortStatus;
  314.  
  315. (*# save, call(near_call=>off, reg_param=>(), reg_saved=>(di,si,ds,st1,st2)) *)
  316.  
  317.   PROCEDURE ConfigureDlgProc(hwnd : HWND;
  318.                              msg  : CARDINAL;
  319.                              mp1,
  320.                              mp2  : Win.MPARAM) : Win.MRESULT;
  321.  
  322.   (* ///////////////////////////////////////////// *)
  323.   (* /  Configure Dialog Box Control Procedure.  / *)
  324.   (* ///////////////////////////////////////////// *)
  325.  
  326.     VAR
  327.       ok      : BOOLEAN;
  328.       i,
  329.       id,
  330.       result  : CARDINAL;
  331.       mresult : Win.MRESULT;
  332.       Param   : Win.MPARAM;
  333.       Command : Win.COMMANDMSG;
  334.       hps     : HPS;
  335.       pt      : POINTL;
  336.       iresult : LONGINT;
  337.       Com     : File;
  338.  
  339.   BEGIN
  340.     CASE  msg  OF
  341.  
  342.       Win.WM_INITDLG:
  343.  
  344.         Win.SendDlgItemMsg(hwnd,IDD_COM1,Win.BM_SETCHECK,Win.MPARAM(LONGCARD(TRUE)),0);
  345.         ActivePort := 1;
  346.         Win.SetDlgItemText(hwnd,IDD_WRKPATH,WorkPath);
  347.         SetCfgPortStatus(hwnd,ActivePort);
  348.         OldCommPort[1] := CommPort[1];
  349.         OldCommPort[2] := CommPort[2];
  350.         RETURN 0;|
  351.  
  352.       Win.WM_CONTROL:
  353.  
  354.         id := CARDINAL(mp1 MOD 65536);
  355.         IF  id = IDD_COM1  THEN
  356.           ActivePort := 1;
  357.           SetCfgPortStatus(hwnd,ActivePort);
  358.         ELSIF  id = IDD_COM2  THEN
  359.           ActivePort := 2;
  360.           SetCfgPortStatus(hwnd,ActivePort);
  361.         ELSE
  362.           CASE  id  OF
  363.             IDD_DB7 : CommPort[ActivePort].DataBits := 7;|
  364.             IDD_DB8 : CommPort[ActivePort].DataBits := 8;|
  365.  
  366.             IDD_SB1 : CommPort[ActivePort].StopBits := 0;|
  367.             IDD_SB2 : CommPort[ActivePort].StopBits := 2;|
  368.  
  369.             IDD_9600 : CommPort[ActivePort].BaudRate := 9600;|
  370.             IDD_4800 : CommPort[ActivePort].BaudRate := 4800;|
  371.             IDD_2400 : CommPort[ActivePort].BaudRate := 2400;|
  372.  
  373.             IDD_NONE : CommPort[ActivePort].Parity := 0;|
  374.             IDD_ODD  : CommPort[ActivePort].Parity := 1;|
  375.             IDD_EVEN : CommPort[ActivePort].Parity := 2;|
  376.  
  377.             IDD_XON : CommPort[ActivePort].XonXoff := TRUE;|
  378.             IDD_DSR : CommPort[ActivePort].XonXoff := FALSE;|
  379.  
  380.             IDD_WRKPATH : Win.QueryDlgItemText(hwnd,IDD_WRKPATH,SIZE(WorkPath),WorkPath);|
  381.           END;
  382.         END;
  383.         RETURN 0;|
  384.  
  385.       Win.WM_COMMAND:
  386.  
  387.       Command := Win.COMMANDMSG(mp2);
  388.       CASE  Command.cmd  OF
  389.         Win.DID_OK:
  390.           WriteConfiguration();
  391.  
  392.           FOR  i := 1  TO  2  DO
  393.             IF  i = 1  THEN
  394.               Com := Open('COM1');
  395.             ELSE
  396.               Com := Open('COM2');
  397.             END;
  398.  
  399.             Func41.BaudRate := CommPort[i].BaudRate;
  400.             WITH  LineControl  DO
  401.               DataBits := CommPort[i].DataBits;
  402.               Parity   := CommPort[i].Parity;
  403.               StopBits := CommPort[i].StopBits;
  404.             END;
  405.  
  406.             Dos.DevIOCtl(NIL,ADR(LineControl),42H,1,Com);
  407.             Dos.DevIOCtl(NIL,ADR(Func41),41H,1,Com);
  408.             Dos.DevIOCtl(ADR(DCB),NIL,73H,1,Com);
  409.  
  410.             IF  CommPort[i].XonXoff  THEN
  411.               WITH  DCB  DO
  412.                 CtlHndShake := 0;
  413.                 FlowReplace := 3;
  414.               END;
  415.             ELSE
  416.               WITH  DCB  DO
  417.                 CtlHndShake := 89;
  418.                 FlowReplace := 64;
  419.               END;
  420.             END;
  421.  
  422.             Dos.DevIOCtl(NIL,ADR(DCB),53H,1,Com);
  423.  
  424.             Close(Com);
  425.           END;
  426.  
  427.           Win.DismissDlg(hwnd, CARDINAL(TRUE));
  428.           RETURN 0;|
  429.  
  430.         Win.DID_CANCEL:
  431.           CommPort[1] := OldCommPort[1];
  432.           CommPort[2] := OldCommPort[2];
  433.           Win.DismissDlg(hwnd, CARDINAL(FALSE));
  434.           RETURN 0;
  435.         END;
  436.      ELSE
  437.        RETURN Win.DefDlgProc(hwnd, msg, mp1, mp2);
  438.      END;
  439.      RETURN 0;
  440.   END ConfigureDlgProc;
  441.  
  442.  
  443.   PROCEDURE WindowProc(hwnd : HWND        (* in *);
  444.                        msg  : CARDINAL    (* in *);
  445.                        mp1,               (* in *)
  446.                        mp2  : Win.MPARAM  (* in *)) : Win.MRESULT  (* out *);
  447.  
  448.   (* ////////////////////////////// *)
  449.   (* /  Window control procedure  / *)
  450.   (* ////////////////////////////// *)
  451.  
  452.     VAR
  453.       hps     : HPS;
  454.       rect    : RECTL;
  455.       swp     : Win.SWP;
  456.       Command : Win.COMMANDMSG;
  457.       fm      : Gpi.FONTMETRICS;
  458.       cresult : CARDINAL;
  459.       id      : CARDINAL;
  460.       pt      : POINTL;
  461.       result  : POINTER TO CARDINAL;
  462.       ok      : BOOLEAN;
  463.       Str     : ARRAY[0..39] OF CHAR;
  464.       Msg     : POINTER TO ARRAY[0..39] OF CHAR;
  465.  
  466.   BEGIN
  467.     CASE msg OF
  468.  
  469.       Win.WM_CREATE :
  470.  
  471.         hwndFrame   := Win.QueryWindow(hwnd,Win.QW_PARENT,B_FALSE);
  472.         hps         := Win.GetPS(hwnd);
  473.         hbmAbleIcon := Gpi.LoadBitmap(hps,NULL,ID_BITMAP,0,0);
  474.         Gpi.QueryFontMetrics(hps,SIZE(fm),fm);
  475.         cxChar    := fm.AveCharWidth;
  476.         cyChar    := fm.MaxBaselineExt;
  477.         Win.ReleasePS(hps);
  478.         hwndWndw := hwnd;|
  479.  
  480.       Win.WM_SIZE :
  481.  
  482.         Win.QueryWindowRect(hwnd, rect);
  483.         Win.MapWindowPoints(hwnd, Win.HWND_DESKTOP, POINTL(rect), 2);
  484.         WITH  rect  DO
  485.           xRight  := xLeft + 38 * cxChar;
  486.           yTop    := yBottom + 12 * cyChar;
  487.         END;
  488.         Win.CalcFrameRect(hwndFrame, rect, B_FALSE);
  489.         Win.SetWindowPos(hwndFrame, Win.HWND_TOP,
  490.                          INTEGER(rect.xLeft),
  491.                          INTEGER(rect.yBottom),
  492.                          INTEGER(rect.xRight - rect.xLeft),
  493.                          INTEGER(rect.yTop - rect.yBottom),
  494.                          Win.SWP_SIZE + Win.SWP_MOVE);|
  495.  
  496.       Win.WM_PAINT :
  497.  
  498.         hps := Win.BeginPaint(hwnd, HPS(NULL), rect);
  499.         Win.FillRect(hps, rect, Gpi.CLR_WHITE);
  500.         pt.x := 5 * cxChar;
  501.         pt.y := 10 * cyChar;
  502.         Gpi.CharStringAt(hps,pt,24,'AEC-Able Engineering Co.');
  503.         pt.x := 8 * cxChar;
  504.         pt.y := 7 * cyChar;
  505.         Gpi.CharStringAt(hps,pt,17,'COMM SET UTILITY');
  506.         pt.x := 2 * cxChar;
  507.         pt.y := 2 * cyChar;
  508.         Gpi.CharStringAt(hps,pt,13,'Jim Billmeyer');
  509.         pt.x := 2 * cxChar;
  510.         pt.y := 1 * cyChar;
  511.         Gpi.CharStringAt(hps,pt,8,'Ver 1.00');
  512.  
  513.         pt.x := 26 * cxChar;
  514.         pt.y := 1 * cyChar DIV 2;
  515.         rect.xLeft   := 0;
  516.         rect.xRight  := 64;
  517.         rect.yBottom := 0;
  518.         rect.yTop    := 64;
  519.  
  520.         Win.DrawBitmap(hps,hbmAbleIcon,rect,pt,Gpi.CLR_BLACK,Gpi.CLR_BLUE,Win.DBM_NORMAL);
  521.  
  522.         Win.EndPaint(hps);|
  523.  
  524.       Win.WM_HELP :
  525.  
  526.         ;|
  527.  
  528.       Win.WM_COMMAND :
  529.  
  530.         Command := Win.COMMANDMSG(mp2);
  531.         CASE  Command.cmd  OF
  532.  
  533.           IDM_CONFIG :
  534.  
  535.             Win.DlgBox(Win.HWND_DESKTOP,hwnd,ConfigureDlgProc,NULL,IDD_CONFIG,NIL);|
  536.  
  537.           IDM_EXIT :
  538.  
  539.             Win.SendMsg(hwnd,Win.WM_CLOSE,0,0);|
  540.  
  541.         END;|
  542.  
  543.     ELSE
  544.       RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2);
  545.     END;
  546.     RETURN Win.MPARAM(FALSE);
  547.   END WindowProc;
  548.  
  549. (*# restore *)
  550.  
  551.   VAR
  552.     Com       : File;
  553.     i         : CARDINAL;
  554.     Str       : ARRAY[0..128] OF CHAR;
  555.     WinResult : Win.MPARAM;
  556.  
  557. BEGIN
  558.   ReadConfiguration();
  559.  
  560.   IF  ParamCount() > 0  THEN
  561.     FOR  i := 1  TO  2  DO
  562.       IF  i = 1  THEN
  563.         Com := Open('COM1');
  564.       ELSE
  565.         Com := Open('COM2');
  566.       END;
  567.       Func41.BaudRate := CommPort[i].BaudRate;
  568.       WITH  LineControl  DO
  569.         DataBits := CommPort[i].DataBits;
  570.         Parity   := CommPort[i].Parity;
  571.         StopBits := CommPort[i].StopBits;
  572.       END;
  573.       Dos.DevIOCtl(NIL,ADR(LineControl),42H,1,Com);
  574.       Dos.DevIOCtl(NIL,ADR(Func41),41H,1,Com);
  575.       Dos.DevIOCtl(ADR(DCB),NIL,73H,1,Com);
  576.       IF  CommPort[i].XonXoff  THEN
  577.         WITH  DCB  DO
  578.           CtlHndShake := 0;
  579.           FlowReplace := 3;
  580.         END;
  581.       ELSE
  582.         WITH  DCB  DO
  583.           CtlHndShake := 89;
  584.           FlowReplace := 64;
  585.         END;
  586.       END;
  587.       Dos.DevIOCtl(NIL,ADR(DCB),53H,1,Com);
  588.       Close(Com);
  589.     END;
  590.   ELSE
  591.     Hab := Win.Initialize(NULL);
  592.     hmq := Win.CreateMsgQueue(Hab,0);
  593.     Win.RegisterClass(Hab,"PMComm",WindowProc,Win.CS_SIZEREDRAW,0);
  594.  
  595.     createfl := Win.FCF_TITLEBAR +
  596.                 Win.FCF_SYSMENU +
  597.                 Win.FCF_DLGBORDER +
  598.                 Win.FCF_MINBUTTON +
  599.                 Win.FCF_MENU +
  600.                 Win.FCF_SHELLPOSITION +
  601.                 Win.FCF_ICON;
  602.  
  603.     frame := Win.CreateStdWindow(Win.HWND_DESKTOP,        (* Desktop window is parent     *)
  604.                                  Win.WS_VISIBLE,          (* Class Style                  *)
  605.                                  createfl,                (* Frame control flag           *)
  606.                                  "PMComm",                (* Client window class name     *)
  607.                                  "Comm Set",              (* Title                        *)
  608.                                  0,                       (* No special class style       *)
  609.                                  NULL,                    (* Resource is in .EXE file     *)
  610.                                  WindowId,                (* Frame window identifier      *)
  611.                                  client);                 (* Client window handle         *)
  612.  
  613.     WHILE  (Win.GetMsg(Hab, qmsg, HWND(NULL), 0, 0))  DO
  614.       Win.DispatchMsg(Hab, qmsg);
  615.     END;
  616.  
  617.     Win.DestroyWindow(frame);
  618.     Win.DestroyMsgQueue(hmq);
  619.     Win.Terminate(Hab);
  620.   END;
  621. END PMComm.
  622.  
  623.  
  624.