home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / sun / hardware / 3569 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  3.6 KB

  1. Path: sparky!uunet!darwin.sura.net!jvnc.net!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!wotan.compaq.com!moxie!texsun!cronkite.Central.Sun.COM!news2me.ebay.sun.com!exodus.Eng.Sun.COM!appserv.Eng.Sun.COM!oobleck!bender
  2. From: bender@oobleck (Duke of Canterbury)
  3. Newsgroups: comp.sys.sun.hardware
  4. Subject: Re: Using STTY to change TTY characteristics
  5. Message-ID: <l78of4INNpm6@appserv.Eng.Sun.COM>
  6. Date: 27 Jul 92 20:51:48 GMT
  7. References: <1392@sousa.ltn.dec.com>
  8. Reply-To: bender@oobleck.eng.sun.com
  9. Distribution: na
  10. Organization: SPARK's R US
  11. Lines: 74
  12. NNTP-Posting-Host: oobleck
  13. X-Newsreader: Tin 1.1 PL3
  14.  
  15. tarsa@elijah.mv.com (Greg Tarsa) writes:
  16. : In trying to do this I have encountered a strange problem: I cannot seem to
  17. : set the terminal line characteristics with stty.  As far as I can tell, the
  18. : stty call is either having no effect, or something is changing the
  19. : characteristics back as soon as my stty request is complete.
  20. :
  21. : I am using the UCB version of stty as follows (for example):
  22. :     stty > /dev/ttya
  23. : and the speed indicated is 9600.  When I execute the following:
  24. :     stty 19200 > /dev/ttya
  25. :
  26. : I expect the speed to change to 19200 and it does not, likewise for any other
  27. : terminal characteristic.  Executing the command as superuser or regular user
  28. : does not change the outcome.  The terminal line is turned off in ttytab,
  29. : that is the entry in /etc/tty (produced at startup) is "02ttya".
  30.  
  31. What is happening is the following:
  32.  
  33.     1. shell opens /dev/ttya as stdout for stty
  34.  
  35.     2. stty issues the ioctl(B19200) that sets the line characteristics
  36.     (i.e. sets the baud rate to 19.2K in your example)
  37.  
  38.     3. stty exits, the shell closes /dev/ttya
  39.  
  40.     4. /dev/ttya is still at 19.2K baud, but the port is closed
  41.  
  42.     5. another process comes along and does an open(/dev/ttya)
  43.  
  44.     6. the device driver, as part of it's open() routine, sets up the serial
  45.     port to default parameters (baud rate, parity, etc...)
  46.  
  47.     7. the driver returns from the open(/dev/ttya) call and the user process
  48.     gets control again; it does a write(foo...)  to the serial port, but
  49.     the data goes out at the default baud rate (9600 in this case).
  50.  
  51. The trick is to keep /dev/ttya open after stty is finished mucking with the
  52. port parameters; one way that I've done it is:
  53.  
  54.     % ( stty 19200 ; command_to_run ) >/dev/ttya
  55.  
  56. This of course has the nasty side effect of sending "command_to_run"'s
  57. stdout to the serial port as well, but that might not be a problem in some
  58. cases.  The other thing you could do is:
  59.  
  60.     % ( stty 19200 ; sleep 1000000 ) >/dev/ttya &
  61.     % command_to_run
  62.  
  63. This assumes that "command_to_run" will open /dev/ttya as well; if not, them
  64. you can of course do:
  65.  
  66.     % ( stty 19200 ; sleep 1000000 ) >/dev/ttya &
  67.     % command_to_run >/dev/ttya
  68.  
  69. BTW - the sllep should keep the port open for about 11-1/2 days...
  70.  
  71. This whole thing begs the question, however, of why the application that you
  72. are trying to run doesn't explicitly set the serial port baud rate (and
  73. perhaps other characteristics)?  If you are familiar with Sun's SPC/S, the
  74. 8-port serial card (with 1 parallel port), there is a mechanism that allows
  75. you to establish various default settings on a per-port basis, so that for
  76. example you could set up /dev/ttyz02 to have a default of 1200 baud, 8
  77. bits/char and no parity whenever the driver opened that port.  Normal
  78. ioctl()'s to change port parameters issued by the application that opened
  79. the port will still work, of course.
  80.  
  81. : I have perused the stty(1v) and tty(4) manual pages but have no clue as to
  82. : what I am doing wrong.  This command seqence works fine under ULTRIX.
  83.               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  84. Well, that's not surprising.
  85.  
  86. mike
  87.