COMPUTER AND NETWORK
                         SYSTEM  ADMINISTRATION
                         Summer 1996 - Lesson 11


                           Serial Devices


A. RS-232 standard

   0. Synchronous versus asynchronous serial devices

      - Sync: there is a reference signal (timing pulse)
		- bisync modems used in older SNA network, for example

      - Async: self-timing:
		- start "bit"
		- data bits (8 bits w/ no parity, 7 with parity that
			     can be even or odd)
		- stop "bits" (1, 1.5, 2)
      - Due to async overhead on a per-byte basis, it is actually
	slower than doing it synchronously.

   1. Intro

      - Electronic Industries Association (EIA) standard 
        > originally described standard for computer to modem connection
	> used for sync & async connections
        > has been extended to terminals, modems, printers, other computers

      - RS-232 consists of up to 25 wires
        > 2 are used for data tranmission
        > the others are control lines

      - the "standard" is not very standard ("RS" = "recommended standard", after all :)
        > you will frequently refer to vendors wiring diagrams
        > may be building cables if you are connecting
          equipment from several different vendors

   2. Important pin assignments (using DB25 connector)
      (full list is in Table 8.1, page 111)
	
      2 - transmit data
      3 - receive data
      4 - RTS (ready to send)
      5 - CTS (clear to send)
      6 - DSR (data set read)
      7 - signal ground
      8 - DCD (data carrier detect)
     20 - DTR (data terminal ready)

      - grounding
        > pin 1 is frame ground
        > if used, should make cable more resistant
          to electrical fluctuations
        > must be connected to the device frame
        > pin 7 is signal ground
        > this is the reference voltage from which the other
          signals measure their voltage
      - voltages
        > a pin is "asserted" when a voltage greater than
          + or - 3 volts is present 
        > data lines 
                < -3 volts is a binary one
                > +3 volts is a binary zero
        > control lines 
                < -3 volts is  off
                > +3 volts is  on
      - DTE and DCE
        > DTE - piece of equipment is a terminal device ("Data Terminal Equipment")
        > DCE - piece of equipment is a computer device ("Data Communications Equipment")
        > not always intuitively obvious
        > to determine whether a device is DTE or DCE              
          check the voltage on pins 2 and 3
        > the transmitter should always have a negative ("one")
          voltage even when idle
        > pin 2 negative - DTE    
        > pin 3 negative - DCE 
  
   3. minimum configuration

      - for some applications only 2, 3, and 7 are needed
      - a console vt100 terminal is an example

   4. carrier detection (DCD = Data Carrier Detect)

      - DCD is needed only if you are not sure if the device
        is connected (modem)
      - if DCD is expected this is called hard carrier detection
        > a console terminal can be counted on to stay connected
      - if DCD is not expected this is called soft carrier
        detection
        > you may (rarely!) have to tell UNIX not to expect DCD
      - "ttysoftcar -y tty..."
      
   5. Flow control

      - keeps one device from overflowing the other devices
        buffers

      - can a 9600 baud computer serial port outpace a local
        vt100 terminal?
        > not usually, so 2, 3, and 7 are still OK for console
          terminal

      - what about printers? modem? PPP or SLIP connections?
        > yes

      - the CTS and RTS signals are used to implement hardware
        flow control

      - without them you can implement software flow control
        using control special characters on the data lines
        (CTL-S and CTL-Q; aka XON and XOFF) -- potential problem:
	using two data byte values for flow control
      
   6. example session between a modem and computer

      DEVICE    SIGNAL   meaning
      -----------------------------------------------------
      Computer  DTR+     I want to call out, are you ready?
      Modem     DSR+     I'm turned on. Go ahead and dial.
      Modem     DCD+     I've got your party!
      Computer  RTS+     Can I send data now?
      Modem     CTS+     Sure, go ahead.
      Computer  TxD...   Data sent out.
      Modem     ...RxD   Data received.
      Modem     CTS-     Hold on for a moment!
      Modem     CTS+     I'm OK again. Go ahead.
      ...
      ...                repeat transmission and handshaking
      ...
      Computer  DTR-     I'm done. Please hang up.
      Modem     DCD-     Whatever you say.


   7. null modem cables

      - used to connect two DCE or two DTE devices together     
	w/out requiring two modems in between

      - full null modem cable crosses:

                2 and 3
                4 and 5
                8 and 20

         (Exhibit B, page 111)
                
B. Types of connectors and other parts

   DB-25   

   DIN-8

   DB-9

   RJ-45

C. Yost system

   - use DB-25, RJ-45 converter

   - make two types DTE and DCE

   - permanently connect them to the devices

   - use 8-wire ribbon cable to connect any serial devices!
     (Details in Table 8.4, page 115)

D. /etc/ttytab - BSD, SunOS

     upsilon:/etc/ttytab
   #
   # @(#)ttytab 1.6 89/12/18 SMI
   #
   # name  getty                           type            status  comments 
   #
   console "/usr/etc/getty std.9600"       vt100           on local secure
   ttya    "/usr/etc/getty std.9600"       unknown         off local secure
   ttyb    "/usr/etc/getty std.9600"       unknown         off local secure
   tty00   "/usr/etc/getty std.9600"       unknown         off local secure


   1. name field

   - device name

   2. getty

   - command to be executed (doesn't have to be getty - could be
     a uucp process, for instance)

   - /etc/gettytab file contains some common port configurations
     to use as paramters to getty (std.9600, for example)

   3. status field

   - on and off: specify whether init should execute the command given 
     in the second field
   - secure: in addition to on allows "root" to login on this line
   - if the console is not marked "secure," the system prompts for the 
     root password before coming up in single-user  mode
   - local: in addition to on indicates the modem control signals for 
     this line, such as Carrier Detect, will be ignored (soft mode)

   #
   #  Printcap file for upsilon (drives pclab)
   #
   pclab:lp=/dev/ttyb:sd=/usr/spool/pclab:br#9600:sb:sh:fs#06320:\
	    ^^^^^^^^^                     ^^^^^^^
        :lf=/usr/adm/lpd-errs:mc#1:mx#50:sc:tr=\f:if=/usr/pclab/pf:


   4. note that printer runs off of serial port b
      > no change in ttytab (terminal control)
      > baud rate and other serial configuration is specified in
        /etc/printcap

E. /etc/inittab - SysV, Linux

  1. inittab defines actions that occur at certain run levels

  c1:12345:respawn:/sbin/agetty 38400 tty1
  c2:12345:off:/sbin/agetty 38400 tty2

  - init reads inittab
       calls agetty for port tty1, agetty calls login
       does not call agetty for port tty2

F. Terminal control

   - a rich area

   - look at "man stty"; esp. the term "canonical" (authoritative)

   - "reset" (BSD), "stty sane" are useful; may need to use
     CONTROL-J (linefeed) to actually terminate the command string
     if the terminal is insane :)

G. Modems

   - modem = "modulator de-modulator"

   - another rich area; only touched on here

   - baud (transitions per second) != bps (bits per second)

   - Table 8.8 page page 128

   - Missing: "V.fast" *vs* "V.34"; not equal!

   - present/near future: 33.6K bps, ISDN (128K bps, 
     ADSL [Asymmetric Digital Subscriber Line] (2-6 Mbps), cable modems (2-10 Mbps)

Here's an excellent source of latest & greatest high speed gear!

H. Debugging a serial line

   1. init not reset
      
      TRY: "kill -1 1" after editing /etc/ttytab or /etc/inittab

   2. soft carrier detection not enabled

      TRY: ttysoftcar -a /dev/tty?

      TRY: local flag in /etc/ttytab

   3. wrong cable pin configuration

      TRY: breakout box to check several wiring

      TRY: finding cable configuration chart in your device
           manual, it may be non-standard

   4. bad cable

      TRY: another cable

      TRY: looking at pin length, is one shorter than the
           others?

   5. nothing appears to go out serial port

      TRY: cat  > /dev/ttya

   6. wrong baud rate

      SYMPTOM: garbage characters emanating from connected device