home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / coherent / 6924 < prev    next >
Encoding:
Text File  |  1993-01-24  |  2.5 KB  |  130 lines

  1. Path: sparky!uunet!sybus.sybus.com!myrddin!tct!tscs!bailey
  2. From: ben@bailey.UUCP (Ben Bailey)
  3. Subject: Can't open com2r
  4. Newsgroups: comp.os.coherent
  5. Date: 24 Jan 93 00:54:35 GMT
  6. Distribution: world
  7. Message-ID: <146023@bailey.UUCP>
  8. Organization: Ben Bailey's Home..Tampa Fl.
  9. Sender: news@bailey.UUCP (GNEWS Version 2.0 news poster.)
  10. Lines: 118
  11.  
  12. I can't seem to open a communications path to com2r (uucp/uucico work
  13. fine off of here).  What's the problem with the following code?  It
  14. just hangs at the open for the communications port.
  15.  
  16.  
  17. ========================
  18.  
  19.  
  20. #include <sys/fcntl.h>
  21. #include <sgtty.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <termio.h>
  25. #include <ascii.h>
  26.  
  27. #define DEFLINE "/dev/com2r"
  28. #define DEFSPEED 9600
  29.  
  30. usage();
  31.  
  32. main(argc, argv)
  33. int argc;
  34. char **argv;
  35. {
  36.     char *ttyline;
  37.     int  ttyfd;
  38.     struct sgttyb ttymode;
  39.     char buff[80];
  40.     int debug=0;
  41.     char option;
  42.  
  43.     if(argc >1)
  44.     {
  45.         strcpy(buff,argv[1]);
  46.         if(isupper(buff[0]))
  47.             option=tolower(buff[0]);
  48.         else
  49.             option=buff[0];
  50.         switch(option)
  51.         {
  52.             case 'd': debug=1;break;
  53.             default: printf("Not a valid option.\n");
  54.                 exit(1);
  55.         }
  56.     }
  57.             
  58.     ttyline = DEFLINE;
  59.  
  60.  
  61.     /* open the communication line */
  62.     if(debug) 
  63.     {
  64.         fprintf(stderr,"Opening communications line\n");
  65.         fflush(stderr);
  66.     }
  67.  
  68.     ttyfd = open(ttyline,O_RDWR);  /* HANGS HERE; tried RDONLY, WRONLY too */
  69.     if(ttyfd < 0)
  70.     {
  71.         fprintf(stderr,"Could not open %s.\n", ttyline);
  72.         exit(1);
  73.     }
  74.  
  75.     /* set exclusive use */
  76.     if(debug) 
  77.     {
  78.         fprintf(stderr,"Setting exclusive use\n");
  79.         fflush(stderr);
  80.     }
  81.  
  82.     if(ioctl(ttyfd,TIOCEXCL,NULL) < 0) 
  83.     {
  84.         fprintf(stderr, "Could not lock %s.\n", ttyline);
  85.         exit(1);
  86.     }
  87.  
  88.     if(debug) 
  89.     {
  90.         fprintf(stderr,"Getting terminal attributes.\n");
  91.         fflush(stderr);
  92.     }
  93.     gtty(ttyfd,&ttymode);     /* get terminal attributes */
  94.     ttymode.sg_flags |= (RAW|TANDEM);
  95.     ttymode.sg_flags &= ~(ECHO|CRMOD);
  96.     ttymode.sg_ispeed = B9600;
  97.     ttymode.sg_ospeed = B9600;
  98.  
  99.     /* put into raw mode */
  100.     if(debug) 
  101.     {
  102.         fprintf(stderr,"Putting into raw mode.\n");
  103.         fflush(stderr);
  104.     }
  105.     stty(ttyfd,&ttymode);
  106.  
  107.     if(debug) 
  108.     {
  109.         fprintf(stderr,"Writting to port %s\n",ttyline);
  110.         fflush(stderr);
  111.     }
  112.     write(ttyfd,"ATDT6775021\n",11);
  113.  
  114.     scanf("%s\n",buff);
  115.     if(debug) 
  116.     {
  117.         fprintf(stderr,"You typed %s\n",buff);
  118.         fflush(stderr);
  119.     }
  120.     close(ttyfd);
  121. }
  122.  
  123.     
  124.  
  125. --
  126. Ben Bailey                 ben@bailey.uucp -- bailey!ben@uunet.uu.net
  127. 12210 Shady Forest Dr.     ben@bailey.tscs.com
  128. Riverview, Fl. 33569       -- The main thing is to keep the main
  129. 813-677-5021                  thing the main thing.  Mainly. 
  130.