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 2 made on Sunday November 7, 2010 at 12:15
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,006
Inside onWake when you create the new socket, you must assign the onData and onConnect functions to the new socket. Note that with each socket instantiation, you MUST assign new callback functions. You cannot reuse a socket after it has been closed. If you replace an existing socket, you should first check to see if it is non-null and connected and if so, close it and assign null to the variable to release the underlying TCP resource (limited to 64 concurrent sockets IIRC).

Summary of activity script changes/validation

var socket = null;

function onSocketConnect() {
System.print("Connection to DHC 40.1 sucessful!");
System.setGlobal("gIPaddr", IPaddr);
System.print("gIPaddr onConnect= " + System.getGlobal("gIPaddr"));

result = ""; //clear receive buffer
replyMsg = "";//parse string
doInit(); //load up page
}

function onSocketData(){
// do your reads here...
}

function cleanupSocket()
{
if (socket && socket.connected)
{
try{socket.close();}catch(toIgnore){}
}
socket = null;
}

CF.activity().onSleep = function()
{
// close socket if connected and cleanup.
cleanupSocket();
}


CF.activity().onWake = function(){

// make sure to cleanup previous socket.
cleanupSocket();

socket = new TCPSocket(false);
socket.onData = socketOnData;
socket.onConnect = socketOnConnect;
socket.connect(IPaddr, 60128, 3000);// port 60128, 3000 s\msec

}

// make sure to cleanup previous socket.
cleanupSocket();

socket = new TCPSocket(false);
socket.onData = socketOnData;
socket.onConnect = socketOnConnect;

if (socket.connected === false)
{
socket.connect(IPaddr, 60128, 3000);
}
else
{
doInit(); //sends queries for display data
}

Also, try a search for try catch debug and you can find some examples where I've posted about using try/catch along with System.print to capture possible script errors that might be occurring.

You can wrap entire activity/page/button scripts with try/catch to allow you to debug them. Note that this approach does not trap things like mismatched braces or parentheses. These will cause compilation failures.

Without try/catch, if the script compiles but during runtime, encounter an error, you might not see things initialize properly or the System.print statements make it to a _PS_DEBUG_ panel. This approach is very useful with PEPv1 but has become less useful with PEPv2 and the Debugger Console. However, I still do most of my debugging in PEPv1 and use this quite often.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Hosting Services by ipHouse