LinHES Forums
http://forum.linhes.org/

directv external tuner serial ports Please please help
http://forum.linhes.org/viewtopic.php?f=6&t=5778
Page 1 of 2

Author:  alexvd [ Mon Aug 22, 2005 7:19 pm ]
Post subject:  directv external tuner serial ports Please please help

Need to fix one final thing.

I have a directv box with low speed serial port. I set the com ports in bios and reserved the irq's ( 3 and irq 4) I tested the cable and box by using the dtv channel change program in windows. It works fine.

I already setup everything in mythbackend sources and stuck the script in usr/local/bin. Script calls dev ttyS0 . I enabled permissions.

When i run the script from command prompt it gives me bad interpreter:file not found. it calls usr/bin/perl, (it exists)

How do I troubleshoot. What logs, the script is below. Can someone see help.



This is the script


#!/usr/bin/perl

# ORIGINALLY:
# dss_control: Remote control of a Sony DSS unit via the serial port
# By Josh Wilmes (http://www.hitchhiker.org/dss)
# Based on info from http://www.isd.net/mevenmo/audiovideo.html
#
# I take no responsibility for any damage this script might cause.
# Feel free to modify and redistribute this as you see fit, but please retain
# the comments above.
#
# BASED ON:
# sony.pl - Found at tarek.2y.net/myth/
#
# CURRENTLY:
# sony_dss.pl - Found at http://www.themonkeys.net/myth/sony_dss.pl
# 11.30.2003 Modifications By Michael Maley
# - Added explicit power_on call to ensure receiver is on for recording.
# - Added check_channel to prevent unnecessary channel change.
# Based on info from http://home.att.net/~mevenmo/sonydsscodes.html



$|=1;
use POSIX qw(:termios_h);
use FileHandle;

$verbose=0;

%pkt_decode=("0xF0" => "START PKT",
"0xF1" => "ERR 1",
"0xF2" => "GOT EXTENDED",
"0xF4" => "END PKT",
"0xF5" => "ERR 2",
"0xFB" => "PROMPT");

%terminal=("0xF1" => -1,
"0xF4" => 1,
"0xF5" => -1);


%keymap=(right => "0x9a",
left => "0x9b",
up => "0x9c",
down => "0x9d",
favorite => "0x9e",
select => "0xc3",
exit => "0xc5",
9 => "0xc6",
8 => "0xc7",
7 => "0xc8",
6 => "0xc9",
5 => "0xca",
4 => "0xcb",
3 => "0xcc",
2 => "0xcd",
1 => "0xce",
0 => "0xcf",
ch_up => "0xd2",
ch_dn => "0xd3",
power => "0xd5",
jump => "0xd8",
guide => "0xe5",
menu => "0xf7");

my $serial=init_serial("/dev/ttyS0","115200");

$ret=&change_channel(@ARGV);
exit(0);

sub change_channel {
my ($channel)=@_;
&power_on;
if ($channel != &check_channel) {
print ("Changing channel to $channel.\n") if ($verbose);
$_=sprintf("%4.4x",$channel);
($n1,$n2)=/(..)(..)/;
simple_command("0x46",$n1,$n2,"0x0");
}
}

sub power_on {
dss_command("0x02");
}

sub check_channel {
@currentChannel = dss_command("0x07");

print "Current Channel is: @currentChannel[0] \n" if ($verbose);
return (@currentChannel[0]);
}


sub simple_command {
if (defined(dss_command(@_))) {
return(1);
} else {
return(undef);
}
}

sub dss_command {
sendbytes("0xFA",@_);
return get_reply();
}


sub sendbytes {
(@send)=@_;
foreach (@send) { s/^0x//g; $_=hex($_); }
print "SEND: " if ($verbose);
foreach $num (@send) {
$str=pack('C',$num);
printf("0x%X [%s] ", $num, $str) if ($verbose);
syswrite($serial,$str,length($str));
}
print "\n" if ($verbose);
}

sub get_reply {
my $starttime=time();
my ($last,$ok,@ret);

print "RECV: " if ($verbose);

while (1) {
$ret=sysread($serial,$buf,1);
$str=sprintf("0x%2.2X", ord($buf));

# busy wait bad!
die ("Error ($str)\n") if (time() - $starttime > 8);
next if $str eq "0x00";

if ($pkt_decode{$str}) {
print $str if ($verbose);
print "[$pkt_decode{$str}] " if ($verbose);
} else {
$_=$str; s/^0x//g; $_=hex($_);
printf("$str(%3.3s) ",$_) if ($verbose);
push (@ret,$_);
}

$ok=1 if ($terminal{$str} > 0);
last if ($terminal{$str});
last if ($last eq "0xFB" && $str eq "0xFB");
$last=$str;
}
print "\n\n" if ($verbose);

return @ret if ($ok);
return undef;
}

sub init_serial {
my($port,$baud)=@_;
my($termios,$cflag,$lflag,$iflag,$oflag);
my($voice);

my $serial=new FileHandle("+>$port") || die "Could not open $port: $!\n";

$termios = POSIX::Termios->new();
$termios->getattr($serial->fileno()) || die "getattr: $!\n";
$cflag= 0 | CS8 | HUPCL | CREAD | CLOCAL;
$lflag= 0;
$iflag= 0 | IGNBRK | IGNPAR | IXON | IXOFF;
$oflag= 0;

$termios->setcflag($cflag);
$termios->setlflag($lflag);
$termios->setiflag($iflag);
$termios->setoflag($oflag);
$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";
eval qq[
\$termios->setospeed(POSIX::B$baud) || die "setospeed: \$!\n";
\$termios->setispeed(POSIX::B$baud) || die "setispeed: \$!\n";
];

die $@ if $@;

$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

# This gets rid of all the special characters..
$termios->getattr($serial->fileno()) || die "getattr: $!\n";
for (0..NCCS) {
if ($_ == NCCS) { last; }

# Dont mess up XON/XOFF..
if ($_ == VSTART || $_ == VSTOP) { next; }

$termios->setcc($_,0);
}
$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

return $serial;
}
1;

Author:  cesman [ Mon Aug 22, 2005 8:02 pm ]
Post subject: 

How many times to you intend to post?! Did you try contact whomever wrote this script?

Author:  alexvd [ Mon Aug 22, 2005 8:14 pm ]
Post subject:  till i get some help

Yes I did contact him. he sent it. he said he thinks it is a perl issue.

I searched and everthing seems correct.

Author:  davem [ Tue Aug 23, 2005 6:56 am ]
Post subject: 

Eliminate your script to debug perl. Repeat what I've done below and post your results back here.

Code:
davem@mythtv:~$ which perl
/usr/bin/perl
davem@mythtv:~$ ll /usr/bin/perl
-rwxr-xr-x  1 root root 1057324 Nov  6  2004 /usr/bin/perl
davem@mythtv:~$ vi /tmp/foo.pl
davem@mythtv:~$ chmod +x /tmp/foo.pl
davem@mythtv:~$ cat /tmp/foo.pl
#!/usr/bin/perl
print "hello world\n";

davem@mythtv:~$ /tmp/foo.pl
hello world
davem@mythtv:~$

Author:  alexvd [ Tue Aug 23, 2005 4:55 pm ]
Post subject:  question about vi

Thank you so much for your help.

I apologize for my ignorance. But when I get to the step to use vi . What exactly am i supposed to do in vi? I enter the editor but I don't know what to do. You said get rid of debug for perl. not sure if you mean to use vi to do this.

If i try to goto the next step it says blah foo.pl does not exist.

Author:  elgordo123 [ Tue Aug 23, 2005 5:35 pm ]
Post subject: 

You need to create the file /tmp/foo.pl
-vi /tmp/foo.pl
-press the insert key to get to insert mode then type
#!/usr/bin/perl
print "hello world\n";
-press the escape key then a colon then wq (press enter)
-The above will take it out of Insert mode, print a colon on the screen, then wq will write/quit. The chmod command makes that script executable.
-Continue with his instructions. The idea is to see if perl itself is working by doing a simple print of "hello world" to the screen.

Author:  alexvd [ Tue Aug 23, 2005 9:31 pm ]
Post subject:  response

so it successfully printed hello world when i excuted the script.

I guess that means perl is working. So that means the script is not working properly.

Does this mean it is a hardware error, as in something still amiss with ttyS0. Or is the script itself.

Author:  davem [ Wed Aug 24, 2005 8:14 am ]
Post subject: 

I don't think you'd get "bad interpreter" because of a problem with your serial port. Let us see the output of your command line attempt to run the program. Say the name of your script is sony.pl and it is in /usr/local/bin. Run the following commands (with your correct script and directory names) and copy/paste your interaction here.

cd /usr/local/bin
ll sony.pl
./sony.pl 200

Author:  alexvd [ Wed Aug 24, 2005 2:20 pm ]
Post subject:  output

root@alexvdmythtv:/home/alexvd# cd /usr/local/bin
root@alexvdmythtv:/usr/local/bin# ll sony0.pl
-rwxr-xr-x 1 root root 4841 Aug 4 17:28 sony0.pl
root@alexvdmythtv:/usr/local/bin# ./sony0.pl 200
: bad interpreter: No such file or directory
root@alexvdmythtv:/usr/local/bin#

Author:  alexvd [ Fri Aug 26, 2005 5:34 pm ]
Post subject:  bump

Bueller anyone bueller,


New shows are on this week. I really dont want to miss the new Rome show on HBO.

Please

Author:  davem [ Fri Aug 26, 2005 7:40 pm ]
Post subject: 

That's strange. I'd be chopping that file up and trying it in smaller bits to see what's up. Like for instance, save a copy of it: cp sony0.pl sony0.pl.bak

Now edit the original and delete everything except the #!/usr/bin/perl and try to run it. See if you still get the error. Maybe add a print line so verify that it runs if you don't see an error. That would be my process for determining what's wrong.

Here's my script, you could try to write it to a file with a different name and see if it will run for you. Remember to chmod +x the new file of course.
Code:
#!/usr/bin/perl

# This is only the necessary parts of the original script (found in the link
#bellow) necessary to change the channels in the box.
# dss_control: Remote control of a Sony DSS unit via the serial port
# By Josh Wilmes (http://www.hitchhiker.org/dss)
# Based on info from http://www.isd.net/mevenmo/audiovideo.html
#
# I take no responsibility for any damage this script might cause.
# Feel free to modify and redistribute this as you see fit, but please retain
# the comments above.

$|=1;
use POSIX qw(:termios_h);
use FileHandle;

$verbose=0;

%pkt_decode=("0xF0" => "START PKT",
"0xF1" => "ERR 1",
"0xF2" => "GOT EXTENDED",
"0xF4" => "END PKT",
"0xF5" => "ERR 2",
"0xFB" => "PROMPT");

%terminal=("0xF1" => -1,
"0xF4" => 1,
"0xF5" => -1);


%keymap=(right => "0x9a",
left => "0x9b",
up => "0x9c",
down => "0x9d",
favorite => "0x9e",
select => "0xc3",
exit => "0xc5",
9 => "0xc6",
8 => "0xc7",
7 => "0xc8",
6 => "0xc9",
5 => "0xca",
4 => "0xcb",
3 => "0xcc",
2 => "0xcd",
1 => "0xce",
0 => "0xcf",
ch_up => "0xd2",
ch_dn => "0xd3",
power => "0xd5",
jump => "0xd8",
guide => "0xe5",
menu => "0xf7");

my $serial=init_serial("/dev/ttyS0","9600");
#@ARGV = split //, join '', @ARGV;
$ret=&change_channel(@ARGV);

#foreach (@ARGV) {
#change_channel($_);
#}

exit(0);

sub change_channel {
my ($channel)=@_;

$_=sprintf("%4.4x",$channel);
($n1,$n2)=/(..)(..)/;

simple_command("0x46",$n1,$n2,"0x0");
}


sub simple_command {
if (defined(dss_command(@_))) {
return(1);
} else {
return(undef);
}
}

sub dss_command {
sendbytes("0xFA",@_);
return get_reply();
}

sub sendbytes {
(@send)=@_;
foreach (@send) { s/^0x//g; $_=hex($_); }
print "SEND: " if ($verbose);
foreach $num (@send) {
$str=pack('C',$num);
printf("0x%X [%s] ", $num, $str) if ($verbose);
syswrite($serial,$str,length($str));
}
print "\n" if ($verbose);
}

sub get_reply {
my $starttime=time();
my ($last,$ok,@ret);

print "RECV: " if ($verbose);

while (1) {
$ret=sysread($serial,$buf,1);
$str=sprintf("0x%2.2X", ord($buf));

# busy wait bad!
die ("Error ($str)\n") if (time() - $starttime > 8);
next if $str eq "0x00";

if ($pkt_decode{$str}) {
print $str if ($verbose);
print "[$pkt_decode{$str}] " if ($verbose);
} else {
$_=$str; s/^0x//g; $_=hex($_);
printf("$str(%3.3s) ",$_) if ($verbose);
push (@ret,$_);
}

$ok=1 if ($terminal{$str} > 0);
last if ($terminal{$str});
last if ($last eq "0xFB" && $str eq "0xFB");
$last=$str;
}
print "\n\n" if ($verbose);

return @ret if ($ok);
return undef;
}

sub init_serial {
my($port,$baud)=@_;
my($termios,$cflag,$lflag,$iflag,$oflag);
my($voice);

my $serial=new FileHandle("+>$port") || die "Could not open $port: $!\n";

$termios = POSIX::Termios->new();
$termios->getattr($serial->fileno()) || die "getattr: $!\n";
$cflag= 0 | CS8 | HUPCL | CREAD | CLOCAL;
$lflag= 0;
$iflag= 0 | IGNBRK | IGNPAR | IXON | IXOFF;
$oflag= 0;

$termios->setcflag($cflag);
$termios->setlflag($lflag);
$termios->setiflag($iflag);
$termios->setoflag($oflag);
$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";
eval qq[
\$termios->setospeed(POSIX::B$baud) || die "setospeed: \$!\n";
\$termios->setispeed(POSIX::B$baud) || die "setispeed: \$!\n";
];

die $@ if $@;

$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

# This gets rid of all the special characters..
$termios->getattr($serial->fileno()) || die "getattr: $!\n";
for (0..NCCS) {
if ($_ == NCCS) { last; }

# Dont mess up XON/XOFF..
if ($_ == VSTART || $_ == VSTOP) { next; }

$termios->setcc($_,0);
}
$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

return $serial;
}


Author:  tjc [ Fri Aug 26, 2005 9:29 pm ]
Post subject: 

Hunt for a posting by me about a dos2unix equivalent. Extend the tr command used there to eat all control characters other than 0x09 (\011)and 0x0A (\012) (HT and LF). Run your file through that.

Author:  davem [ Sat Aug 27, 2005 7:09 am ]
Post subject: 

crap, I didn't think of that.

Author:  alexvd [ Sat Aug 27, 2005 10:58 am ]
Post subject:  ok

TJC,

Thanks for the reply. Woahh, I know I have said this before but I am just a mere mortal who is probably quite stupid by your standards and has no business trying to do this with no knowledge of linux.

That being said "say whaaaattttt'.

Could Dave or yourself elaborate on what you said? Go slowly and step by step.

What I don't understand is the guy who sent me this scripts has the exact same SAT B55 and is running knoppmyth I think. Now I realize we are probably using different motherboards with different settings but I am thinking more and more it is a hardware issue. You see when I first tried to load knoppmyth I had all kinds of hardware issues so I did an installation doing minimal hardware detection. After I had most of that work through ( I think, my (3) Pchdtv cards, (2) PVR 250 as well, but I dont have a soundcard that gives me mutex destroy errors). I went backed and disable scsi in hardware and enabled and manually specified my (20 com ports (ttyS0,ttys1). I do have a mouse as well that I think uses the serial and what about the lirc serial stuff detected for the PVR-250.

The reason I say this is that when I try to run this script ( the original sony.pl) it gives me an error of 0x00 or something like that). The guy who gave me the sony0.pl script told me not to use it because it was not properly written. Isnt this close to the script everyone else uses?

Again when I run it i dont get that bad interpreter error.

#!/usr/bin/perl

# ORIGINALLY:
# dss_control: Remote control of a Sony DSS unit via the serial port
# By Josh Wilmes (http://www.hitchhiker.org/dss)
# Based on info from http://www.isd.net/mevenmo/audiovideo.html
#
# I take no responsibility for any damage this script might cause.
# Feel free to modify and redistribute this as you see fit, but please retain
# the comments above.
#
# BASED ON:
# sony.pl - Found at tarek.2y.net/myth/
#
# CURRENTLY:
#
# 02.08.2004 Modifications By Anthony
# - Added function to buy PPV, it will only buy certain channels, change
# to suit yourself
# - Fixed HUGE bug in check_channel
# - Added clear_osd() from RCA.pl
#
# 11.30.2003 Modifications By Michael Maley
# - Added explicit power_on call to ensure receiver is on for recording.
# - Added check_channel to prevent unnecessary channel change.
# Based on info from http://home.att.net/~mevenmo/sonydsscodes.html



$|=1;
use POSIX qw(:termios_h);
use FileHandle;

$verbose=0;

%pkt_decode=("0xF0" => "START PKT",
"0xF1" => "ERR 1",
"0xF2" => "GOT EXTENDED",
"0xF4" => "END PKT",
"0xF5" => "ERR 2",
"0xFB" => "PROMPT");

%terminal=("0xF1" => -1,
"0xF4" => 1,
"0xF5" => -1);


%keymap=(right => "0x9a",
left => "0x9b",
up => "0x9c",
down => "0x9d",
favorite => "0x9e",
select => "0xc3",
exit => "0xc5",
9 => "0xc6",
8 => "0xc7",
7 => "0xc8",
6 => "0xc9",
5 => "0xca",
4 => "0xcb",
3 => "0xcc",
2 => "0xcd",
1 => "0xce",
0 => "0xcf",
ch_up => "0xd2",
ch_dn => "0xd3",
power => "0xd5",
jump => "0xd8",
guide => "0xe5",
menu => "0xf7");

my $serial=init_serial("/dev/ttyS0","115200");

if(@ARGV[0] != -1 && @ARGV[0] <= 0){printf("Please use either \"-1\" (buy ppv) or \"n\" (channel change to n)\n");exit();}

if(@ARGV[0] == -1){
dss_buy_ppv();
exit(0);
}

$ret=&change_channel(@ARGV);
exit(0);


sub dss_buy_ppv {
system("usleep 100000");
my ($channel) = &check_channel;
if ((($channel > 0) && ($channel < 200)) || (($channel > 590) && (channel < 600))){
printf("Buying PPV...\n") if ($verbose);
simple_command("0x45","0x00","0x00","0xc3");
system("usleep 100000");
simple_command("0x45","0x00","0x00","0xf7");
system("usleep 100000");
simple_command("0x45","0x00","0x00","0xf7");
system("usleep 100000");
clear_osd();
} else {
printf("Skipping, not a defined PPV\n") if ($verbose);
}
}

sub change_channel {
my ($channel)=@_;
&power_on;
if ($channel != &check_channel) {
print ("Changing channel to $channel.\n") if ($verbose);
$_=sprintf("%4.4x",$channel);
($n1,$n2)=/(..)(..)/;
simple_command("0x46",$n1,$n2,"0x0");
system("usleep 100000");
clear_osd();
}
}

sub power_on {
dss_command("0x02");
system("usleep 100000");
}

sub check_channel {
my $realchan;
@currentChannel = dss_command("0x07");
if(@currentChannel[1]){ #means we're above 256... need to calculate
$realchan = (@currentChannel[0] * 256) + @currentChannel[1];
} else {
$realchan = @currentChannel[0];
}
print "Current Channel is: $realchan\n" if ($verbose);
return ($realchan);
}


sub simple_command {
if (defined(dss_command(@_))) {
return(1);
} else {
return(undef);
}
}

sub dss_command {
sendbytes("0xFA",@_);
return get_reply();
}

sub clear_osd {
printf("Clearing OSD") if ($verbose);
simple_command("0x45","0x00","0x00","0xf9");
}
sub sendbytes {
(@send)=@_;
foreach (@send) { s/^0x//g; $_=hex($_); }
print "SEND: " if ($verbose);
foreach $num (@send) {
$str=pack('C',$num);
printf("0x%X [%s] ", $num, $str) if ($verbose);
syswrite($serial,$str,length($str));
}
print "\n" if ($verbose);
}

sub get_reply {
my $starttime=time();
my ($last,$ok,@ret);

print "RECV: " if ($verbose);

while (1) {
$ret=sysread($serial,$buf,1);
$str=sprintf("0x%2.2X", ord($buf));

# busy wait bad!
die ("Error ($str)\n") if (time() - $starttime > 8);
next if $str eq "0x00";

if ($pkt_decode{$str}) {
print $str if ($verbose);
print "[$pkt_decode{$str}] " if ($verbose);
} else {
$_=$str; s/^0x//g; $_=hex($_);
printf("$str(%3.3s) ",$_) if ($verbose);
push (@ret,$_);
}

$ok=1 if ($terminal{$str} > 0);
last if ($terminal{$str});
last if ($last eq "0xFB" && $str eq "0xFB");
$last=$str;
}
print "\n\n" if ($verbose);

return @ret if ($ok);
return undef;
}

sub init_serial {
my($port,$baud)=@_;
my($termios,$cflag,$lflag,$iflag,$oflag);
my($voice);

my $serial=new FileHandle("+>$port") || die "Could not open $port: $!\n";

$termios = POSIX::Termios->new();
$termios->getattr($serial->fileno()) || die "getattr: $!\n";
$cflag= 0 | CS8 | HUPCL | CREAD | CLOCAL;
$lflag= 0;
$iflag= 0 | IGNBRK | IGNPAR | IXON | IXOFF;
$oflag= 0;

$termios->setcflag($cflag);
$termios->setlflag($lflag);
$termios->setiflag($iflag);
$termios->setoflag($oflag);
$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";
eval qq[
\$termios->setospeed(POSIX::B$baud) || die "setospeed: \$!\n";
\$termios->setispeed(POSIX::B$baud) || die "setispeed: \$!\n";
];

die $@ if $@;

$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

# This gets rid of all the special characters..
$termios->getattr($serial->fileno()) || die "getattr: $!\n";
for (0..NCCS) {
if ($_ == NCCS) { last; }

# Dont mess up XON/XOFF..
if ($_ == VSTART || $_ == VSTOP) { next; }

$termios->setcc($_,0);
}
$termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

return $serial;
}
1;

Author:  alexvd [ Sat Aug 27, 2005 11:00 am ]
Post subject: 

sorry meant to say 2 com ports. I realize my grammer is horrible. I apologize.

Page 1 of 2 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/