home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sybus.sybus.com!myrddin!tct!tscs!bailey
- From: ben@bailey.UUCP (Ben Bailey)
- Subject: Can't open com2r
- Newsgroups: comp.os.coherent
- Date: 24 Jan 93 00:54:35 GMT
- Distribution: world
- Message-ID: <146023@bailey.UUCP>
- Organization: Ben Bailey's Home..Tampa Fl.
- Sender: news@bailey.UUCP (GNEWS Version 2.0 news poster.)
- Lines: 118
-
- I can't seem to open a communications path to com2r (uucp/uucico work
- fine off of here). What's the problem with the following code? It
- just hangs at the open for the communications port.
-
-
- ========================
-
-
- #include <sys/fcntl.h>
- #include <sgtty.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <termio.h>
- #include <ascii.h>
-
- #define DEFLINE "/dev/com2r"
- #define DEFSPEED 9600
-
- usage();
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- char *ttyline;
- int ttyfd;
- struct sgttyb ttymode;
- char buff[80];
- int debug=0;
- char option;
-
- if(argc >1)
- {
- strcpy(buff,argv[1]);
- if(isupper(buff[0]))
- option=tolower(buff[0]);
- else
- option=buff[0];
- switch(option)
- {
- case 'd': debug=1;break;
- default: printf("Not a valid option.\n");
- exit(1);
- }
- }
-
- ttyline = DEFLINE;
-
-
- /* open the communication line */
- if(debug)
- {
- fprintf(stderr,"Opening communications line\n");
- fflush(stderr);
- }
-
- ttyfd = open(ttyline,O_RDWR); /* HANGS HERE; tried RDONLY, WRONLY too */
- if(ttyfd < 0)
- {
- fprintf(stderr,"Could not open %s.\n", ttyline);
- exit(1);
- }
-
- /* set exclusive use */
- if(debug)
- {
- fprintf(stderr,"Setting exclusive use\n");
- fflush(stderr);
- }
-
- if(ioctl(ttyfd,TIOCEXCL,NULL) < 0)
- {
- fprintf(stderr, "Could not lock %s.\n", ttyline);
- exit(1);
- }
-
- if(debug)
- {
- fprintf(stderr,"Getting terminal attributes.\n");
- fflush(stderr);
- }
- gtty(ttyfd,&ttymode); /* get terminal attributes */
- ttymode.sg_flags |= (RAW|TANDEM);
- ttymode.sg_flags &= ~(ECHO|CRMOD);
- ttymode.sg_ispeed = B9600;
- ttymode.sg_ospeed = B9600;
-
- /* put into raw mode */
- if(debug)
- {
- fprintf(stderr,"Putting into raw mode.\n");
- fflush(stderr);
- }
- stty(ttyfd,&ttymode);
-
- if(debug)
- {
- fprintf(stderr,"Writting to port %s\n",ttyline);
- fflush(stderr);
- }
- write(ttyfd,"ATDT6775021\n",11);
-
- scanf("%s\n",buff);
- if(debug)
- {
- fprintf(stderr,"You typed %s\n",buff);
- fflush(stderr);
- }
- close(ttyfd);
- }
-
-
-
- --
- Ben Bailey ben@bailey.uucp -- bailey!ben@uunet.uu.net
- 12210 Shady Forest Dr. ben@bailey.tscs.com
- Riverview, Fl. 33569 -- The main thing is to keep the main
- 813-677-5021 thing the main thing. Mainly.
-