Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Any idea why this TCP PS doesn't work?
This thread has 7 replies. Displaying all posts.
Post 1 made on Tuesday December 12, 2017 at 15:18
peteS
Long Time Member
Joined:
Posts:
June 2003
13
Hi All

I'm trying to write a PS to control my Sky satellite box from my 9400 directly via TCP. I can connect fine, and using the information at [Link: github.com], I can read and write the data, but nothing happens. The relevant section in the nodejs .js is

function sendCommand(code, cb) {
var commandBytes = [4,1,0,0,0,0, Math.floor(224 + (code/16)), code % 16];

var client = net.connect({
host: host,
port: port || 49160
});

var l = 12;
client.on('data', function(data) {
clearTimeout(connectTimeoutTimer)
// Clear timeout
if (data.length < 24) {
client.write(data.slice(0, l))
l = 1;
} else {
client.write(new Buffer(commandBytes), function() {
commandBytes[1]=0;
client.write(new Buffer(commandBytes), function() {
client.destroy();
cb(null)
});
});
}
});

.. which I've replaced with

function onData(){
System.print("Ondata.");
receivedText = socket.read();
System.print(receivedText.length)
var len =12;
if (receivedText.length < 24){
socket.write(receivedText.slice(0,len));
len = 1;
} else {
System.print("Writing Data")

socket.write [0x04,0x01,0x00,0x00,0x00,0x00,0xE0,0x00];
socket.write [0x04,0x00,0x00,0x00,0x00,0x00,0xE0,0x00];

socket.close;
socket=null;
}

}

I've just hardcoded code=0 in effect, so 0xE0 is Math.floor(224 + (code/16)) and 0x00 is code % 16. But, nothing happens. I'm guessing that you can't just write the hex values to the socket, but Buffer doesn't seem to exist in ProntoScript.

Any ideas how I could change this? Also, any ideas how to debug?

Thanks

pete S
Post 2 made on Sunday December 17, 2017 at 03:07
Rene Lou
Long Time Member
Joined:
Posts:
January 2008
19
Hi peteS
Did you check what errors you get on the debug panel and did you initialize the socket as described in the PS developer manual ?
It seems you have included a space after socket.write and used [ and ] instead of ( and ).
Use round brackets for writing to a socket, eg: AV_Socket.write("?V\r");
Rene
OP | Post 3 made on Sunday December 17, 2017 at 05:51
peteS
Long Time Member
Joined:
Posts:
June 2003
13
Hi Rene

Yes, with a bit of searching and judicious use of Wireshark, I got it sorted. Bottom line is that socket.write doesn't support writing a byte array - hence the []. Looking at wireshark, it just sends nothing at all. You need to convert it to a string.

Use ...

function ArrayToString(arr){

var stringToSend = '';
var i;
for (i = 0; i < arr.length; i++)
stringToSend += String.fromCharCode(arr[i]);
return stringToSend
}

then call

socket.write (ArrayToString([0x04,0x01,0x00,0x00,0x00,0x00,0xE0,0x00]));

Now have a fully working IP control version for the Sky box ...

pete S
Post 4 made on Sunday December 17, 2017 at 09:29
Rene Lou
Long Time Member
Joined:
Posts:
January 2008
19
Hi pete S

If you need to send hex data, this method will work as well:

socket.write("\x04\x01\x00\x00\x00\x00\xE0\x00");
socket.write("\x04\x00\x00\x00\x00\x00\xE0\x00");

or

var string_1 = "\x04\x01\x00\x00\x00\x00\xE0\x00";
var string_2 = "\x04\x00\x00\x00\x00\x00\xE0\x00";
socket.write(string_1);
socket.write(string_2);

or

var cmd_array = ["\x04\x01\x00\x00\x00\x00\xE0\x00", "\x04\x00\x00\x00\x00\x00\xE0\x00"];
socket.write(cmd_array[0]);
socket.write(cmd_array[1]);

or a combination, eg:

var cmd_array = ["\x01", "\x00"];
var string_header = "\x04";
var end_of_package = "\x00\x00\x00\x00\xE0\x00";
socket.write(string_header + cmd_array[0] + end_of_package);
socket.write(string_header + cmd_array[1] + end_of_package);

Just use \x before the hex and put it between "" since it has to be a string.

Rene
OP | Post 5 made on Sunday December 17, 2017 at 12:15
peteS
Long Time Member
Joined:
Posts:
June 2003
13
On December 17, 2017 at 09:29, Rene Lou said...
Hi pete S

If you need to send hex data, this method will work as well:

socket.write("\x04\x01\x00\x00\x00\x00\xE0\x00");
socket.write("\x04\x00\x00\x00\x00\x00\xE0\x00");

or

var string_1 = "\x04\x01\x00\x00\x00\x00\xE0\x00";
var string_2 = "\x04\x00\x00\x00\x00\x00\xE0\x00";
socket.write(string_1);
socket.write(string_2);

or

var cmd_array = ["\x04\x01\x00\x00\x00\x00\xE0\x00", "\x04\x00\x00\x00\x00\x00\xE0\x00"];
socket.write(cmd_array[0]);
socket.write(cmd_array[1]);

or a combination, eg:

var cmd_array = ["\x01", "\x00"];
var string_header = "\x04";
var end_of_package = "\x00\x00\x00\x00\xE0\x00";
socket.write(string_header + cmd_array[0] + end_of_package);
socket.write(string_header + cmd_array[1] + end_of_package);

Just use \x before the hex and put it between "" since it has to be a string.

Rene

Yep - that's what I thought as well. That works fine for serial, but just doesn't send anything (according to wireshark) on a tcpsocket. Hence, the need to convert it to a string. Oh well, works now.
Post 6 made on Sunday December 17, 2017 at 17:15
Rene Lou
Long Time Member
Joined:
Posts:
January 2008
19
Hi pete S

I can confirm that all versions I mentioned above do work without any problem. Before posting those I made some tests with my Pronto with all four versions and everything worked as expected - if not for you, you will have an error elsewhere.

FYI: My 9600er is sending this code over a tcp-socket to a GC-100, and this converts it to serial. I have a RFX9600 as well and used similar codes before - and those worked as well.

Rene
OP | Post 7 made on Wednesday December 20, 2017 at 14:21
peteS
Long Time Member
Joined:
Posts:
June 2003
13
Thanks Rene

Not sure what I was doing earlier - as you say, your form now works fine. Might have had a stray , in there I think....

Anyway, the form I'm using is now

writeText = "\x04\x01\x00\x00\x00\x00"+chr[Math.floor(224 + (code/16))]+chr[code % 16];
socket.write (writeText);

I've borrowed the chr[] array definition from Barry - nice easy lookup method.

So, all good there now. thanks for your help.

pete S
Post 8 made on Wednesday December 20, 2017 at 15:02
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,171
Here are some useful tips as well.

// Just copies pointer to function into variable chr.
var chr = String.fromCharCode;
// Invokes function chr (String.fromCharCode) with the arguments in parenthesis.
var result = chr(Math.floor(224 + (code/16)));

I sometimes do this as well.

var $f=false;
var $t=true;
var $b=' ';
var $c = '\r\n';
var $n = null;

Note that $n works as 'null' is a special value of a JavaScript Object. You cannot do the same for keyword/value 'undefined'.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse