home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / windows / winterm / line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-27  |  2.3 KB  |  97 lines

  1. /*** line ***/
  2.  
  3. #include "windows.h"
  4. #include "line.h"
  5. #include "pcl4w.h"
  6. #include "config.h"
  7. #include "term.h"
  8. #include "expect.h"
  9. #include "sioerror.h"
  10. #include "term_io.h"
  11.  
  12. extern HWND hMainWnd;
  13. extern int FatalFlag;
  14. extern int OnLineFlag;
  15.  
  16. /* private */
  17. static WORD RxSelector = 0;
  18. static WORD LockCount = 0;
  19. static void FreeDOSmemory(void);
  20.  
  21. void GoOnLine(void)
  22. {DWORD dwValue;
  23.  int RetCode;
  24.  int Port;
  25.  HMENU hMenu;
  26.  if(OnLineFlag) return;
  27.  /* allocate windows/DOS memory for receive buffer */
  28.  dwValue = GlobalDosAlloc(2<<(3+RXBUFFERCODE));
  29.  if(dwValue)
  30.    {/* get selector */
  31.     RxSelector = LOWORD(dwValue);
  32.     LockCount = GlobalPageLock(RxSelector);
  33.     if(LockCount==0) FatalFlag = TRUE;
  34.    }
  35.  else FatalFlag = TRUE;
  36.  /* memory allocation error ? */
  37.  if(FatalFlag)
  38.    {RxSelector = 0;
  39.     ErrorMessage("Cannot allocate memory");
  40.     return;
  41.    }
  42.  /* pass selector to PCL4C */
  43.  Port = GetPort();
  44.  RetCode = SioRxBuf(Port,RxSelector,RXBUFFERCODE);
  45.  if(RetCode<0)
  46.    {SioError(RetCode,"SioRxBuf");
  47.     FreeDOSmemory();
  48.     return;
  49.    }
  50.  else
  51.    {/* reset Port */
  52.     RetCode = SioReset(Port,GetBaud());
  53.     if(RetCode<0)
  54.       {SioError(RetCode,"SioReset");
  55.        FreeDOSmemory();
  56.        return;
  57.       }
  58.     /* set DTR & RTS */
  59.     SioDTR(Port,'S');
  60.     SioRTS(Port,'S');
  61. #if RTS_CTS_CONTROL
  62.     /* set flow control */
  63.     SioFlow(Port,TRUE);
  64. #endif
  65.     /* Set FIFO level for 16550 */
  66.     if( SioFIFO(Port,LEVEL_14) ) DisplayLine("INS16550 detected");
  67.     /* clear PCL4C receive buffer */
  68.     SioRxFlush(Port);
  69.    }
  70.  OnLineFlag = TRUE;
  71.  SetTitle();
  72.  hMenu = GetMenu(hMainWnd);
  73.  CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_UNCHECKED);
  74.  CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_CHECKED);
  75. } /* end GoOnLine */
  76.  
  77. void GoOffLine()
  78. {HMENU hMenu;
  79.  FreeDOSmemory();
  80.  if(OnLineFlag)
  81.    {SioDone((int)GetPort());
  82.     SetTitle();
  83.     hMenu = GetMenu(hMainWnd);
  84.     CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_UNCHECKED);
  85.     CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_CHECKED);
  86.     OnLineFlag = FALSE;
  87.    }
  88. } /* end GoOffLine */
  89.  
  90. void FreeDOSmemory(void)
  91. {
  92.  if(RxSelector)
  93.    {GlobalPageUnlock(RxSelector);
  94.     GlobalDosFree(RxSelector);
  95.     RxSelector = 0;
  96.    }
  97. } /* end FreeDOSmemory */