Controlling DirecTV Set Top Box (STB) via USB or Serial

From MythTV Official Wiki
Revision as of 18:21, 30 May 2010 by Klk (talk | contribs) (DirecTV H24 Satellite STB)

Jump to: navigation, search

Overview

DirecTV supplies and has supplied a variety of set top boxes (referred to as "STB" from here on) to consumers. Nearly all of them have the ability, although not directly advertised, to be controlled from an external device, such as a MythTV BackEnd.

Cable Options

WARNING: Not all USB to Serial port adapters are compatible with linux. There are a few well known ones that are made with compatible chipsets (the PL-2303 comes to mind), but there are many more that do not work with any flavor of linux. Please choose your cable with care.

Known good adapters are:

  1. The Sabrent USB->Serial port adapter (http://www.newegg.com/Product/Product.aspx?Item=N82E16812156008)
  2. WARNING: I ordered one of these and it no longer works with the DirecTV box. These are now using the pl2303X chips instead of the pl2303 and do not work.
  3. IOGEAR GUC232A, ATEN UC-232A (pl2303), BAFO BF-810, QVS UR-2000M2, Sabrent SBT-USC1M and other PL2303 based adapters are known working.
  4. WARNING: I ordered two of these and they no longer work with the DirecTV box. These are now using the pl2303X chips instead of the pl2303 and do not work.
  5. http://www.cablestogo.com/product.asp?cat%5fid=1529&sku=26886
  6. July 06, 2007 Update: It has been reported that EMTC (http://www.emtcompany.com/products/adapters/dxubdb9-usb-to-serial-db9-adapter-cable.htm) is no longer shipping linux compatible (PL2303) cables. Previously, they were a good and inexpensive supplier, but the replacement cables are not compatible. DO NOT BUY THESE
  7. GWC UC320 (http://www.newegg.com/Product/Product.asp?Item=N82E16812107108). This has been reported to work on both the HD20-100 and D11-500 boxes as of November, 2007.
  8. http://www.dtvcontrol.com/index.aspx?content=cable, which shows up under linux as "Prolific Technology, Inc. PL2303 Serial Port"
  9. Dynex DX-UBDB9 purchased off of ebay (February 2009 and August 2009) work fine on the H20-600, H20-100 and H21-200.
  10. Other cables/adapters are unknown (use at your own risk).
  11. Be careful, a lot of these adapters are no longer pl2303 based although they carry the same Model number. Try http://www.cooldvr.com. He carries a complete set of cables (pc or mac to stb) that are tested to work. Cost about the same as buying the parts individually
  12. Paterson Technology USB TV Translator. Works flawlessly on an H23 receiver (also works with D11, D12, and H20) and has additional logic to eliminate the channel banner quickly.

Official USB to Serial Cable Support

According to the Installers Guide V2.2, the following USB to Serial Adapters are fully supported:

Supported USB-Serial Adapters
Manufacturer Model USB Vendor ID USB Product ID
IOGEAR GUC232A 0x067B 0x2303
ATEN UC-232A 0x067B 0x2303
BAFO BF-810 0x067B 0x2303

Therefore, it is possible (though not guaranteed) that your particular USB-Serial adapter will work if it has:

  • USB Vendor ID= 0x067B
  • USB Product ID= 0x2303

To find this out, use the lsusb command after plugging in your device. If it shows a line of output like the following, it should theoretically work.

$ lsusb
Bus 002 Device 003: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

The USB port on most set top boxes (STBs) should support hot-plugging. However, if you are having troubles with your USB-Serial adapter, try plugging it in before the STB is booted. Particularly, the Installer's guide mentions that the HR20 and HR21 work this way. To do this, simply:

  1. Unplug the STB
  2. Plug in the serial adapter
  3. Plug in the STB and wait until it boots

Afterwards, make sure your device on the mythtv box is correct when you pass it to the script. For me, it was /dev/ttyUSB0.

A simple test command for using the correct device is the following:

# This should make the guide pop up on the D11 & D12 boxes.  Substitute your box_type below.
$ ./directv.pl port /dev/ttyUSB0 box_type D11 key guide

If you get "Error excessive retries", you probably are using the wrong serial port. Set it with the port command as in the above example.

The D10 & RCA Satellite STB

Many of the older (pre 2007) STB's that were sold or leased by DirecTV have a small phone-style port on the back of the unit that is labeled as "Low Speed Data Port" or simply "Low Speed Data". This port, although it can be initially be mistaken as a standard RJ-11 phone jack, is actually quite a bit smaller (in technical terms, it is called an RJ-22) and is sometimes referred to as a "mini RJ-11" port. If you take a look at the coil handset cable on your non-cordless phone (you still have one of those, right?), you will see that the plug on that cord is the same as the port on the back of the STB.

You will need the following components in order to create a connection from your MythTV backend to the STB:

  1. a USB->Serial Adapter (USB Male to 9-pin Male)
  2. a handset cord for a corded phone
  3. a Serial->RJ45 adapter
  4. a short length of ethernet cable with RJ-45 connectors already crimped down on each end

If you prefer to get your hands on a modular serial hood, you can omit the Serial->RJ45 adapter and the ethernet cable. I used the items listed above because that was what I had readily available.

The DirecTV D11/H20 Satellite STB

The DirecTV D11/H20 Satellite set top box contains a USB port that can be used as a serial port to change channels and perform other tasks on the box. To do this, you need the following cables:

  1. USB->Serial Adapter (usb male to 9 male).
  2. 9-pin Null-Modem Adapter (9 female to 9 female)
  3. 9 pin serial cable. (9 female to 9 male)

The end result of this is a null modem serial connection between computers. I assume that using two USB->Serial adapters would also work, (see note below) given that the Null Modem adapter was still used.

I used the BAFO BF-810 adapter (found for $9 online) and a pair of 9pin DSub to RJ45 adapters wired as a crossover serial cable, along with a straight-through ethernet cable.

I started with the directv.pl script used to control the D10 box. I had to change the speed to 115200 from 9600 (contrary to the installers guide which says 9600 or 155200, which must be a typo). I also had to enable hardware flow control in order to get reliable operation.

NOTE: I was using 115,200 baud for months with two D-11 boxes. Around the middle of January 2007 I started getting channel change failures. Switching it to 9600 baud fixed it. My theory is that DirecTV sent down a firmware upgrade to change the all the D-11 boxes to 9600.

NOTE: D11 and H20 boxes require baud rate = 115200 (May 25, 2007)

NOTE: If baud rate = 115200 does not work with the H20 box using the CablesToGo usb->serial adapters, try 9600 (Oct 22, 2007)

NOTE: For Mac OS X connecting to a D11 or H20 use directv.pl ver 1.8 which supports baud rates (for Mac and Linux) >38400. A usb to serial adapter on both ends connected by a null modem cable works fine.(May 25, 2007)

NOTE: I have 2 D11 boxes hooked up to my motherboard that has only 1 serial port connection. One is connected as described above, the other uses the exact same scenario except with an extra USB to Serial adaptor to plug the cable into the motherboard's USB port. This was an extra USB to Serial Adaptor I had bought that didn't work when plugged into the D11 box, but works just fine on the other end. I now have two serial devices connected (ttyS0 and ttyUSB0) and am controlling two boxes without a problem.

The DirecTV H21 Satellite STB

While most of the info listed for the H20 should be applicable to the H21, here are a few specifics of usb->serial adapters which did and didn't work in addition to the configuration and directv.pl settings. This particular setup is: H21 <-> USB/serial converter <-> null modem adapter <-> mb serial port

USB-Serial Adapter Info
Manufacturer Model Purchase Location Status Notes
Micro Connectors E07-160 Fry's Didn't work On 3/10/2010 I purchased one of these from Fry's and it worked with a D12-300
Cables Unlimited USB-2920 Fry's Didn't work
Dynex DX-UBDB9 Best Buy Worked

Keep in mind that there is also this possible combination: H21 <-> USB/serial converter <-> null modem adapter <-> USB/serial converter <-> computer which was not tested.

The following parameters were given to the directv.pl script (v1.9): box_type H20 baud 9600 port /dev/ttyS0

The DirecTV H23 Satellite STB

This STB works as well using the H20 commands, version 1.9 of the script and the USB to USB cable set from http://www.cooldvr.com/Buy.html, but it works better for me using the direct channel change command rather than the keypress command. (probably a delay timing thing, but sometimes it would miss the keypresses. it would do this directly from the remote control as well, so it may just be my particular unit) Everything else in the H20 command list seems to work.

DirecTV H24 Satellite STB

The latest version of DirecTV's set top box is the H24. It has a USB port like the previous versions. The directv.pl script (see the External Links section below to download the script) works to change the channels. I used a usb-serial converter with a PL2303 chip and a null modem adapter to hook it to the serial port on the motherboard.

Making Your Own Custom Cable (D10/RCA)

You can either buy a cable to convert from the low speed data port to a serial port from http://www.dtvcontrol.com/index.aspx?content=cable or, using the pinout either on that page or within this page (they are the same),you can make one on your own.

Overall difficulty of making your own cable is rather low. Take your time, and be prepared to test it once (or twice) before taping everything up to make sure you got it right.

Using the items listed aboce, I grabbed with the handset cable, two serial to RJ-45 adapters, and a short RJ-45 ethernet cable and I:

  • Cut the headset cable in half, giving me two pieces of the same approx. length.
  • Cut the RJ-45 cable in half giving me two pieces of the same approx. length.
  • Cut back the outer sheathing on the RJ-45 cables at the point where I cut it in half.
  • Cut back the outer sheathing on the headset cables at the point where I cut it half (this was a pain)
  • Cut back the sheathing on the individual exposed wires on the RJ-45 cables and the headset cables.
  • Plugged the RJ-45 cables in to the Serial-RJ45 adapters.
  • Using a 9-volt battery and a cheap DC tester, I mapped out what pins on the serial side of the adapter mapped to which exposed wires on the cut end of the RJ45 cable. WRITE THEM DOWN. I cannot stress this enough. Because you will be dealing with two different wires, it is easy to get confused. I have these written down at home, and, after making my third adapter, I can tell you that the entire mapping is usually custom since serial-to-RJ45 adapters are not all created equal, the handset cables are not always color coded, and you can use any variant of RJ45 cabling.
  • Using your mapping of the serial port adapter to the individual wires in the ethernet cable, write down the proper mapping of the wires from the handset cable to the individual wires of the ethernet cable.
  • Following the mapping you just created, hand twist the appropriate wires together and use electrical tape to hold it.

Because I had the DC tester (with the little light on it), I was able to do a final test of the completed connection to confirm that the wires were connected properly. Connect the serial port end to either your MythTV backend's serial port, or, if you don't have one available (most machines now-a-days don't have more than two, and many only have one), plug it in to the USB->Serial port adapter, and plug the USB->Serial port adapter in to an available USB port. Plug the other end of the cable you just made (the mini RJ-11) in to the STB.

Now, test it and make sure it changes channels. /usr/local/bin/directv.pl setup_channel 10

If it does not work, you will get something on the command line like "excessive retries to port" or some similar error. This means, more than likely, that you reversed the mapping of the pins. I say this because that is exactly what I did. I had looked at the mini RJ11 port, and the exposed wires (all of the wires on the one that I had were the same color: gray!) and asked myself "Which end is pin 1?"

Custom Channel Change Configuration

In order to configure MythTV to call the directv.pl script, you must add the command with desired options to the tuner section of mythtv-setup( User Manual:Detailed configuration Backend ).

  1. Run mythtv-setup
  2. Select Input connections
  3. Choose the connection you would like to control
  4. Add the script to the External channel change command parameter

For example, I set mine to...

 /usr/local/bin/directv.pl

The help text for this parameter says, "If specified, this command will be run to change the channel for inputs which have an external tuner device such as a cable box. The first argument will be the channel number." I interpreted this to mean that the channel will be added to whatever is specified here. This would mean that parameters could be added such as [hide, retries_number n,...]. It appears that once a command is sent like "hide" it is persistent. So you could specify it in a command window at any time.

Watch out for Xwindows using the serial port by default

In some stock /etc/X11/xorg.conf files, a serial mouse may be configured by default. If this is the case, you may notice unreliable communication with your directv box. Channel changes may not function correctly, multiple timeouts, etc. can occur. You can verify that the serial port is not in use by using the lsof command. For example,

 grigio # lsof /dev/ttyS0
 COMMAND    PID   USER  FD   TYPE DEVICE SIZE NODE NAME
 X         5479   root mem    CHR    1,5      3943 /dev/ttyS0
 grigio # 

shows that X has the /dev/ttyS0 file open. We can fix this by commenting out the appropriate device section in your /etc/X11/xorg.conf file and restarting X.

udev rules

If you are using a USB->serial adapter on the computer side of things, and are trying control multiple STBs, you will likely need to use udev rules for predictable naming of the USB->serial device. Instructions for udev can be found on the Device_Filenames_and_udev page.

An example rule might look like:

SUBSYSTEMS=="usb",KERNELS=="5-1:1.0",DRIVERS=="pl2303",SYMLINK+="STBChannel0"

In that example, the KERNELS=="5-1:1.0" indicates which USB port the adapter is plugged into on the computer. If the USB->serial adaptor does not report any unique identification, using the USB port is the only way.

Note that some distributions come with a gpsd udev rule, which can get in the way. There is probably a more "proper" way to handle this problem, but on my system I just removed 99-gpsd.rules to fix the problem.


Working around some missing functionality on the channel change script

Note: This user may have been able to fix this problem by both: making sure his box_type was correct, and adjusting the delay sent to the script. Both options are documented in the script's help output.

In my situation, some of the features of the directv.pl script did not function in the way that I liked, or simply did not function with my STB. Specifically, with my STB, the "setup_channel" function, which is defined in the documentation as "turning the unit on, changing the channel, and hiding the on screen display" really only did the first two pieces, leaving the OSD up for an obscenely long amount of time. I simply wanted the script to change the channel and hide the OSD immediately.

While the directv.pl script can take the options out of order (eg: directv.pl port /dev/ttyUSB0 hide setup_channel 29), it did not seem to make any difference. This limitation required me to write a small wrapper script called "/usr/local/bin/change_channel.sh" :

#!/bin/sh
if [ "X$1" = "X" ] || [ "X$2" = "X" ]; then
       echo "Usage: $0 <port> <channel number>"
       echo
       exit;
fi
/usr/local/bin/directv.pl port $1 setup_channel $2 hide

I then used "/usr/local/bin/change_channel" in the field as outlined above in the "Custom Channel Change Configuration" section. Be sure to specify the corresponding port for each of your tuners.

Mini RJ11 (RJ22 or 4P4C) Port Pinout

1 Black
2 Red
3 Green (unused)
4 Yellow

Mini RJ11 (RJ22 or 4P4C) to Serial Port mapping

When everything is built, the pinout of the resulting cable should be:

DB9 Pin 5 -> mini RJ11 Pin 1
DB9 Pin 2 -> mini RJ11 Pin 2
DB9 Pin 3 -> mini RJ11 Pin 4

Null Modem Cable Pinout

This is a standard Null-modem cable, but here is the pinout for the sake of being complete:

TD (Transmit Data) 3 -> 2 RD
RD (Receive Data) 2 -> 3 TD
RTS (Request To Send) 7 -> 8 CTS
CTS (Clear To Send) 8 -> 7 RTS
SG (Signal Ground) 5 -> 5 SG

Serial -> RJ45 (Pin to Wire) Mapping

I used a standard SUN supplied serial to RJ45 adapter and got the following mapping of the serial port pins to the individual wires on the RJ45 cable plugged in to the serial port adapter. I also used a snort length of off-the-shelf pre-made RJ-45 (Cat5) wire.

Serial Port RJ45 (standard coloring)
1 (none) --
2 Orange/White
3 Green
4 Brown/White
5 Orange and Green/White
6 Blue
7 Brown
8 (none) --
9 (none) --

Hardware Compatibility

  • DirecTV D10
  • DirecTV D11-100: Same results as D11-500.
  • DirecTV D11-300: Works using 9600 baudrate (as of 6/9/09).
  • DirecTV D11-500: Channel changing works (by key). On/Off, OSD On/Off, Remote Input On/Off all work. Other features not working yet.
  • DirecTV D12: Same as D11-100. Except the D12 supports get_channel where the D11 does not.
  • DirecTV D12-100: Works.
  • DirecTV D12-300: Works.
  • DirecTV H20: Same results as D11-500
  • Most DirecTV RCA STB's

Controlling D11 from Windows

I know this isn't myth-related at all, but here is how to control the D11 from windows!

  1. Install Perl (I recommend [ActivePerl])
  2. Start Perl Package Manager (PPM)
  3. Add the BdP Repository: repository add BdP http://www.bribes.org/perl/ppm
  4. Install Win32::SerialPort: install Win32-SerialPort
  5. Install Win32::API: install Win32-API
  6. Install Time::HiRes: install Time-HiRes
  7. Download the Windows version of the DirecTV Serial Control Script (see links below). Save it to C:\perl\
  • Example Execution:

perl.exe c:\perl\directv2.pl port com1 baudrate 115200 flow none box_type D11 25


External Links

  • PortMon Windows software to monitor traffic on a com port
  • Com Port Toolkit Windows software to send specific commands to the serial port.

For More Information