djhayman has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I want to control some tv displays using a perl socket. The displays accept a connection on port 1515 a accept a hexadecimal command.

For example:
AA 11 FF 01 01 12

I have found the following code to open a socket and send text.

1 use IO::Socket; 2 my $sock = new IO::Socket::INET ( 3 PeerAddr => '192.168.1.2', 4 PeerPort => '1515', 5 Proto => 'tcp', 6 ); 7 die "Could not create socket: $!\n" unless $sock; 8 print $sock "Hello there!\n"; 9 close($sock);

After doing a bit of research I think I want to use pack to convert the hex string into bytes. I have taken the following from teh pack manual / tutorial

my $s = pack( 'H*', $hexcommand );
Can I use 'print $sock $s' ? If you need any more info just shout, this is my first perl script so bare with me. Thanks, Dan

Replies are listed 'Best First'.
Re: Pack hex string and send to socket
by choroba (Cardinal) on Jun 02, 2012 at 10:41 UTC
    You should remove spaces from the $hexcommand before running pack on it:
    $hexcommand =~ s/ //g;
    Printing to socket should be ok, but consult the protocol documentation on when to print.
Re: Pack hex string and send to socket
by Anonymous Monk on Jun 02, 2012 at 10:30 UTC

    I want to control some tv displays ...

    What is the name of the protocol?

Re: Pack hex string and send to socket
by djhayman (Initiate) on Jun 02, 2012 at 11:49 UTC
    Hello

    Thanks for the speedy replies, the protocol used is MDC. The display is a Samsung Ue46a. I can't find the specofoc protocol manual for the display but I have found the manaual for the same protocol for different displays.
    http://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0CHAQFjAD&url=http%3A%2F%2Fwww.samsung.com%2Fus%2Fpdf%2FUX_DX.pdf&ei=5_nJT-SVF9Ok0AXGmLXMAQ&usg=AFQjCNHatN0wjTPyYbD_usYJHdZxWr9GsQ&sig2=SMl1v_sfjFLTjy3L-B1X5g

    What do you mean 'when' to print? Do you mean after handshakes etc.?

    Dan