home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d03xx / d0326.lha / MicroTerm / serial.c < prev    next >
C/C++ Source or Header  |  1990-03-05  |  2KB  |  82 lines

  1. /** serial.c
  2.  
  3.             Written by Stephen Vermeulen (403) 282-7990
  4.  
  5.             PO Box 3295, Station B,
  6.             Calgary, Alberta, CANADA, T2M 4L8
  7.  
  8.     various serial support routines
  9.  **/
  10.  
  11. /** open the needed libraries **/
  12.  
  13. open_libs()
  14. {
  15.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0L);
  16.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L);
  17.   if (!GfxBase || !IntuitionBase) return(FALSE);
  18.   return(TRUE);
  19. }
  20.  
  21. close_libs()
  22. {
  23.   if (IntuitionBase) CloseLibrary(IntuitionBase);
  24.   if (GfxBase)       CloseLibrary(GfxBase);
  25. }
  26.  
  27. /** open up a serial port of given name and unit, returns a pointer to
  28.     a MySer structure if successful, NULL if not.
  29.  **/
  30.  
  31. struct MySer *open_ser(name, unit)
  32. char *name;
  33. int unit;
  34. {
  35.   struct MySer *ms;
  36.  
  37.   ms = (struct MySer *) AllocMem(SIZE(MySer), MEMF_CLEAR);
  38.   if (ms)
  39.   {
  40.     if (ms->readport = CreatePort(NULL, 0L))
  41.     {
  42.       if (ms->writeport = CreatePort(NULL, 0L))
  43.       {
  44.         if (ms->readio = (struct IOExtSer *)
  45.             CreateExtIO(ms->readport, SIZE(IOExtSer)) )
  46.         {
  47.           if (ms->writeio = (struct IOExtSer *)
  48.              CreateExtIO(ms->writeport, SIZE(IOExtSer)) )
  49.           {
  50.             if (!OpenDevice(name, (long) unit, ms->readio, 0L))
  51.             {
  52.               ms->writeio->IOSer.io_Device = ms->readio->IOSer.io_Device;
  53.               ms->writeio->IOSer.io_Unit = ms->readio->IOSer.io_Unit;
  54.               return(ms);
  55.             }
  56.             DeleteExtIO(ms->writeio, SIZE(IOExtSer));
  57.           }
  58.           DeleteExtIO(ms->readio, SIZE(IOExtSer));
  59.         }
  60.         DeletePort(ms->writeport);
  61.       }
  62.       DeletePort(ms->readport);
  63.     }
  64.     FreeMem(ms, SIZE(MySer));
  65.   }
  66.   return(NULL);
  67. }
  68.  
  69. close_ser(ms)
  70. struct MySer *ms;
  71. {
  72.   if (ms)
  73.   {
  74.     CloseDevice(ms->readio);
  75.     DeleteExtIO(ms->writeio, SIZE(IOExtSer));
  76.     DeleteExtIO(ms->readio, SIZE(IOExtSer));
  77.     DeletePort(ms->writeport);
  78.     DeletePort(ms->readport);
  79.     FreeMem(ms, SIZE(MySer));
  80.   }
  81. }
  82.