[mythtv-users] Last Ditch Attempt - HD DirecTV and MythTV

mythtv at hundekeandroyal.com mythtv at hundekeandroyal.com
Fri Jun 25 11:30:55 EDT 2004


To all,

My issue is solved!  I now have MythTV talking to the Samsung SIR-TS360 
DirecTV set top box via the RS232 port!  I was given some code (in C) to 
accomplish this.  The author stated that he was unable to get a perl 
program to work, so he wrote some C code instead.  It is working on both 
his and my system.  He's asked me to post the code since he's unable to 
post the mailing list yet.

First, edit the source to make sure the correct serial port is in there 
for your particular setup.  It's currently set to /dev/ttyS0.  To 
compile, simply save the source code attached to this email.  Then, at 
the prompt, do a simple C compile with the command "cc channel.c".  This 
will spit out a program called a.out.  I renamed a.out to 
channel.changer and moved into /usr/bin.  I then had to change 
permissions on my serial port which happened to be /dev/ttyS0.  I then 
ran "mythtvsetup" and went to option 4 (if I remember right).  In that 
option, I chose the value that was being used by MythTV (for me this is 
S-Video 0) and selected it.  In the box that says external channel 
changer (or something like that anyway), I entered "channel.changer".  I 
works.

PLEASE...if anyone improves this code, post back to the list.  If anyone 
can hack up a perl script, please post back.  I've included at the 
bottom of this email the codes for some of the functions (each code 
starts with *DTV...funny).  Feedback on how this program works on your 
setup would be appreciated too.

Thanks again to DVH for taking the time to contact me off list and pass 
along the code.  The community wins again!

Geoff




> 
> In searching through the net, I came across a post over in the AVS 
> forums concerning this stb (Samsung SIR-TS360) and the RS232 port. 
> Someone had picked apart the software (Crestron software) that the 
> engineers at Samsung use, presumably with MS boxes, to talk to the stb. 
>  He was able to get some codes and he listed them as follows:
> 
> <snip>
> 
> Com port setting need to be: none 8 1 none 5760
> Off 2A6474764A0D0A
> On 2A647476490D0A
> 5 2A647476350D0A
> 0 2A647476300D0A
> 9 2A647476390D0A
> Enter 2A647476480D0A
> 1 2A647476310D0A
> 2 2A647476320D0A
> 3 2A647476330D0A
> 4 2A647476340D0A
> 6 2A647476360D0A
> 7 2A647476370D0A
> 8 2A647476380D0A
> ch+ 2A6474763E0D0A
> ch- 2A6474763D0D0A
> 
> </snip>
> 
> I'm assuming the "5760" is missing a zero...?


-------------- next part --------------
/* This program written by DVH - 6/25/04                             */
/* For use with Samsung SIR-TS360 set top box from DirecTV           */
/* Compile using "cc channl.c"                                       */
/*                                                                   */
/* Please post back any improvements to MythTV users mailing list at */
/* mythtv-users at mythtv.org                                           */

#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <poll.h>
#include <fcntl.h>
#include <string.h>

#define SLEEP 250000.0

struct termios serial;
int fd, status, i;
speed_t input_speed, output_speed;
char buffer[20];
char command[] = {'*','d','t','v','I','\r','\n','\0'};
char *channel_string;
char *digit;

main(int argc, char **argv) {

   int debug = 1;

   /* initialize the serial port */

   fd = open("/dev/ttyS0", O_NDELAY | O_NONBLOCK | O_RDWR);
   status = tcgetattr(fd,&serial);
   if(debug) printf("initial status: %d\n\n",status);

   input_speed = cfgetispeed(&serial);
   output_speed = cfgetospeed(&serial);

   if(debug) printf("initial ispeed: %d\n",input_speed);
   if(debug) printf("initial ospeed: %d\n",output_speed);

   cfsetispeed(&serial,B57600);
   cfsetospeed(&serial,B57600);

   serial.c_cc[VMIN] = 1;
   serial.c_cc[VTIME] = 1;
  
   serial.c_cflag &= ~CSIZE;     /* Mask the character size bits */
   serial.c_cflag &= ~(PARENB);  /* clear parity enable */
   serial.c_cflag &= ~(CSTOPB);  /* one stop bit */
   serial.c_cflag |= (CS8 | CREAD);

   serial.c_cflag |= (IXON | IXOFF);  /* sw flow control */
   serial.c_iflag &= ~(INPCK);   /* disable input parity checking */
   serial.c_iflag |= IGNBRK;      /* ignore break */
   serial.c_cflag &= ~CRTSCTS;    /* hw flow control off */
   serial.c_lflag  = 0;
   serial.c_oflag  = 0 | NL1;

   status = tcsetattr(fd, TCSANOW, &serial);
   if(debug) printf("final status: %d\n\n",status);

   fcntl(fd, F_SETFL, FNDELAY);   /* don't wait on read */

   /* now make sure the 360 is powered on */
   /* do this by sending the "on" string  */

   status = write(fd,command,7);
   if(debug) printf("to port: %s",command);
   tcdrain(fd);
   usleep(SLEEP);
   
   /* ok, now we need to get the channel from the command line */

   channel_string = argv[1];

   i=0;
   while(channel_string[i]) {
      command[4]=channel_string[i++];
      status = write(fd,command,7);
      if(debug) printf("to port: %s",command);
      tcdrain(fd);
      usleep(SLEEP);
   }

   /* sent "enter" to force the change immediately */

   command[4]='H';
   status = write(fd,command,7);
   usleep(SLEEP);
   if(debug) printf("to port: %s",command);

   close(fd);
   return;
}


More information about the mythtv-users mailing list