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

Login:
Pass:
 
 

Original thread:
Post 11 made on Thursday September 9, 2010 at 11:53
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,778
You must read from the socket and analyze the data inside the OnData function. Please see the Dev Guide for additional examples.

You posted this:

var socket= new TCPSocket(false);
socket.connect("192.168.10.35",8005,3000);
socket.onConnect = function()
{
socket.write("192.168.10.25",8005,3000);
};
var result=" ";
socket.onData = function()
{
result+=socket. read();

};
if (result== "05380001013F")
{
socket.write("\\053801007901\r");
}
else
{
socket.write("\\053801000101\r");
}
socket.close();
socket.onIOError = function(e)
{
label1 = "socket error:"+e;
};


Which should look like this instead - Processing code moved inside the OnData and obvious bugfix in connect - I have also taken liberties of pointing out what I believe may be potential problems you will encounter:


var result=""; // note change to empty string.
var socket= new TCPSocket(false);
socket.connect("192.168.10.35",8005,3000);
socket.onConnect = function()
{
result = ""; // reset buffer.
socket.write("stringtosend");
};
socket.onData = function()
{
result+=socket. read();
// Note that this if clause moved inside of the function.
// Note that result may have trailing Carriage Return and if so, this clause will never report true.
if (result== "05380001013F")
{
socket.write("\\053801007901\r");
}
else
{
// you may have to account for incomplete data here and not do this write.
socket.write("\\053801000101\r");
}
socket.close();

};

socket.onIOError = function(e)
{
// Is this a bug? Presume label1 is a widget so may need to be label1.label
label1 = "socket error:"+e;
};
Lyndel McGee
Philips Pronto Addict/Beta Tester


Hosting Services by ipHouse