Difference between revisions of "Serialpedia"

From LinuxMCE
Jump to: navigation, search
m (Numbering of pins: fix typo)
m (Numbering of pins: fix typo properly)
Line 67: Line 67:
 
|
 
|
 
  5 4 3 2 1
 
  5 4 3 2 1
   9 7 6 5
+
   9 8 7 6
 
|}
 
|}
  

Revision as of 09:19, 6 July 2013

This page is for all things serial (RS232, RS422, RS485): how serial cables should be views, mistakes people make in the documentation, list of devices and the cables they require.

Serial theory

RS232

Physical channel

We'll refer to DE-9 connectors only.

RS232 was meant for communication between a computer (Data Terminal Equipment, DTE) and a non-computer (modem, Data Communication Equipment, DCE). The computer was master, and all the signal names were defined from the point of view of the computer.

Signals

As the signals are defined from the point of view of the computer, the names can be extended to refer to the wires on the serial cable themselves. The signals are:

Serial port pinouts

Pin Abbreviation Name Direction* Description
1 DCD Data Carrier Detect <- Modem tells computer the connection to the remote peer has been established
2 TxD Transmitted Data -> Computer sends data to modem over this line
3 RxD Received Data <- Computer receives data from modem over this line
4 DTR Data Terminal Ready -> Computer present, ready to talk
5 G Common Ground - Just your run of the mill electrical ground
6 DSR Data Set Ready <- Modem ready to receive commands or data from the computer
7 RTS Request To Send -> Computer wants to send data to the modem
8 CTS Clear To Send <- Modem responds to RTS signal to clear computer to send data
9 RI Ring Indicator <- Modem tells computer that there's an incoming call
  • * Computer = DTE is on the left side; Modem = DCE is on the right side

I'll repeat: all the signals are defined from the point of view of the computer. This can result in much confusion, because not many people expect something (the modem) to transmit on the receive line and receive on the transmit line. There are devices which take a [#Straight_cable straight cable] but their documentation errorneously describes a [#Crossed_cable crossed cable], for example.

Signal pairs

The signals that work in pairs are:

Pair Description
TxD, RxD Computer sends data through TxD and receives data through RxD. The modem receives data through TxD and transmits through RxD
DTR, DSR Computer sets DTR, telling the modem its there, and ready to send. The modem sets DSR back to tell the computer it can send data
RTS, CTS Computer sets RTS, telling the modem its there, and ready to send. The modem sets CTS back to tell the computer it can send data

The descriptions for DTR+DSR and RTS+CTS look the same, because that's how they are used when flow control is involved. An application can choose which pair to use for flow control. While with real modems weirder things happen with these signals, for our purposes, this is Accurate Enough(tm).

Numbering of pins

When looking at the DE-9 from the front, the pins are numbered like this:

Male DE-9 Female DE-9
1 2 3 4 5
 6 7 8 9
5 4 3 2 1
 9 8 7 6

Straight cable

A straight cable is usually a cable with one male end and one female end ([#Exceptions see exceptions]), with all pins on one end connected pins that have the same number on the other end.

Their main purpose was to connect a computer to a modem.

Male DE-9 Signal Female DE-9
1 DCD 1
2 TxD 2
3 RxD 3
4 DTR 4
5 G 5
6 DSR 6
7 RTS 7
8 CTS 8
9 RI 9

In practice, you'll need a simplified 3-wire cable only:

Male DE-9 Signal Female DE-9
2 TxD 2
3 RxD 3
5 G 5

Crossed cable - null modem

A crossed cable is usually cable with same gender at each end ([#Exceptions see exceptions]), with signals that come in pairs crossing over, to simulate a modem in the middle.

Their main purpose was to connect two computers to each other, while lying to them that modems are involved.

Left DE-9 Left Signal Right Signal Right DE-9
1 + 6 DCD* DCD* 1 + 6
2 TxD RxD 3
3 RxD TxD 2
4 DTR DSR 6
5 G G 5
6 DSR DTR 4
7 RTS CTS 8
8 CTS RTS 7
9 N/C** N/C** 9
  • * Pin 1 is jumpered to Pin 6 to piggy back on the other computer's DTR signal
  • ** Pin 9 has no meaning in this usage - nobody is going to ring you

In practice, you'll need a simplified 3-wire cable only:

Left DE-9 Left Signal Right Signal Right DE-9
2 TxD RxD 3
3 RxD TxD 2
5 G G 5

What is a "null modem"?

A null modem is an imaginary device that connects two computers together, just like a real modem does, but without involving phone lines.

In a normal setup, two computers speak to each other over the following setup:

Computer 1 -- straight cable -- Modem 1 -- telephone network -- Modem 2 -- straight cable -- Computer 2

The order of operations is this:

1. Computer 1 sends data out through its TxD pin (2) 2. Modem 1 receives data on its TxD pin (2) 3. Modem 1 sends the data to Modem 2 through the telephone network 4. Modem 2 receives the data from Modem 1 through the telephone network 5. Modem 2 sends data though its RxD pin (3) 6. Computer 2 receives data through its RxD pin (3)

Remember that the signal lines are named relative to the computer, not the modem.

If we abstract the modem, the order of operations becomes:

1. Computer 1 sends data out through its TxD pin (2) 2. Computer 2 receives data through its RxD pin (3)

The other pins that cross over are RTS to CTS, and DTR to DSR. This is so that one computer appears to be a modem to the other computer. Or so that a modem appears to be between them, happily signaling backwards and forwards. Pin 1 is jumpered to Pin 6 to piggy back on the other computer's DTR signal, completing the modem-in-the-middle illusion.

The modem-in-the-middle illusion is what is called a "null modem".

Exceptions

As if the above weren't confusing enough, there are situations like these:

  • Same gender at both ends, but straight cable
  • Male gender at one end, female gender at the other end, but crossed cable

I named these "weird", for lack of a better term.

Shortcuts

  • If a USB serial adapter plugs directly into your device, and you can communicate, you need a normal straight cable (male-female straight)
  • If a USB serial adapter plugs directly into your device, but works only after you added a null modem adapter in the middle, you need a weird crossed cable (male-female crossed)
  • If you need a gender changed between the USB serial adapter and your device, and you can communicate, you need a weird straight cable (female-female straight)
  • If you need a gender changer and a null modem adapter between the USB serial adapter and your device, you need a normal crossed cable (female-female crossed)

Table of hardware

This table contains devices have have been encountered, and the type of serial cable they require for a computer to speak to them.

Brand Model Class Cable Notes
Triax HMX 8x8V HDMI matrix normal straight The manual is wrong and specifies a weird crossed configutation
RTI AD-4 audio matrix amplifier normal straight The manual doesn't make the type of cable clear at all
RTI AD-8 audio matrix amplifier normal straight The manual doesn't make the type of cable clear at all
HDAnywhere HKHA414SW_V2 HDMI matrix normal crossed Baud rate: 600
HDAnywhere HKHA414SW_V3 HDMI matrix normal crossed? Serial codes don't work, UDP codes don't work, have to abuse the web control interface using wget/curl to control it.