- Forward


Serial Communication
Including the History of the RS-232 Protocol


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Two Approaches to Data Communication
Back SMYC Forward
  • Serial:
    • One bit is sent and received at a time
    • Originally involved a terminal (Data Terminal Equipment) and a modem (Data Communications Equipment)
  • Parallel:
    • Multiple bits are sent and received simultaneously
    • Originally used for printers
Serial Communications
Back SMYC Forward
  • The (Almost) Simplest System:
    • One wire (i.e., circuit) is used to transmit a sequence of bits by raising and lowering the signal
    • Another wire is used as a ground
  • Problems with this System:
    • Bits can easily be lost
    • One lost bit contaminates the remainder of the transmission
Serial Communications (cont.)
Back SMYC Forward
  • Reducing Errors with Timing:
    • Have a specific, carefully measured, amount of time between data bits
  • Reducing Errors with Markers:
    • Send a specific bit pattern between data "words"
History: The RS-232 Protocol
Back SMYC Forward
  • The Standards Organization:
    • The Electronic Industries Association (EIA)
  • The Timeline:
    • 1960 - Original adoption
    • 1969 - Third version (RS-232C)
History: Common Connectors
Back SMYC Forward
  • DB-25 Connector:
    • images/db25-connector.gif
  • DB-9 Connector:
    • images/db9-connector.gif
History: One Popular Scheme
Back SMYC Forward
  • Data Words:
    • 7 or 8 bits
    • Least significant bit first
  • Markers:
    • 1 start bit before the word
    • 1 parity bit and 1 stop bit after the word
  • Possible Parity Bits:
    • Mark - always 1
    • Space - always 0
    • Even - make the number of 1s even
    • Odd - make the number of 1s odd
    • None
History: RS-232C Pins/Signals (DB-25, DB-9)
Back SMYC Forward
  • Clear to Send (5, 8)
  • Data Carrier Detect (8, 1)
  • Data Set Ready (6, 6)
  • Data Terminal Ready (20, 4)
  • Signal Ground (7, 5)
  • Transmitted Data, DTE to DCE (2,3)
  • Received Data, DCE to DTE (3,2)
  • Request to Send (4, 7)
  • Ring Detector (22, 9)
History: RS-232C Details
Back SMYC Forward
  • Voltages:
    • Low (logical 1) is between -5 and -15 volts
    • High (logical 0) is between +5 and +15 volts
  • Transmitted Data:
    • Transmits when low on CTS, DTR, DSR, DCD
  • Received Data:
    • Transmits when low on RTS, DTR, DSR, DCD
Universal Serial Bus (USB)
Back SMYC Forward
  • History:
    • Designed to replace serial ports and parallel ports
  • Why Serial?
    • Speed advantages outweight the fact that only one bit is transmitted at a time
  • Today:
    • A standard that replaces almost all common ports (including power)
    • Managed by the USB Implementers Forum (USB-IF)
Accessing USB Ports in Java
Back SMYC Forward
  • usb4java (usb4java.org):
    • A complete library for accessing USB ports
    • Fairly complicated
  • jSerialComm (fazecast.github.io/jSerialComm):
    • A library for RS-232 communication using a USB port
    • Easy to use
An Example: Locating the Serial Port
Back SMYC Forward
SerialPort[] ports = SerialPort.getCommPorts(); for (SerialPort port:ports) { String description = port.getPortDescription(); String path = port.getSystemPortPath(); System.out.println(description + "\t" + path); }
An Example: Getting an InputStream
Back SMYC Forward
SerialPort port = SerialPort.getCommPort(path); port.openPort(); port.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0); InputStream is = port.getInputStream();
There's Always More to Learn
Back -