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:
Issue with Calling Extender from a Pronto Library Function
This thread has 7 replies. Displaying all posts.
Post 1 made on Thursday September 4, 2014 at 09:27
schmick71
Lurking Member
Joined:
Posts:
August 2011
6
Have struck a problem with coding whilst trying to query an sound bar through RS-232.

Below code works when linked to a Button, but when I move the code to a Library and run the function from the button it keeps coming up 'undefined'.

Can an extender be called from a Library Function or does it need to be done within an Button script? Maybe I've missed something completely?

Library Function:

panoramatest()
{
var s;
var t,v;

var e = CF.extender[1]; // RFX 9600
if(!e)
{
t="Extender 1 is not defined";
}
else
{
s=e.serial[0]; // Serial Port 1
s.bitrate=19200;
s.databits = 8;
s.parity=0; //None
s.stopbits=1;
if(!s)
{
t="Extender 1 is not a serial extender";
}
else
{
// Request Values from Panorama 2
s.match("Q\r","\r",1000);
s.onData = function(v)
{
if(!v)
{
t="Extender Error";
}
else
{
t = v;
}
};
}
}
};


Button Script:

var t;
t=panoramatest();

// Set on screen label
CF.widget("RS232COMMS").label=t;
Post 2 made on Thursday September 4, 2014 at 15:12
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Did you put any try/catch logic around your code and have the error logged to either the diagnostic log or the display?

What does your button script do when you execute this?

Button Script:

var t=panoramatest;

System.print(t);

Does it print something '[Object object]' or does it print 'undefined'.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Thursday September 4, 2014 at 17:47
schmick71
Lurking Member
Joined:
Posts:
August 2011
6
Yes I used a _PS_DEBUG_ window in the same Page to trap the error and then used some very simple System.print("Text"); to determine what position the script was working to.

The System.print(t); just prints 'undefined'.

This script was the first step in trying to obtain a return string of the format 'Qaxcdef' read each of the values and then use these to drive logic in various Activities i.e. Power on, Selecting Inputs etc.

I've had a TSU 9400 for some time but decided to venture into two way communications using a recently purchased RFX9600. Both are on the latest firmware versions (1.4.8 and 7.3.3). I could replicate the script in each area that I need to use it, but thought using a Library was a lot neater.
Post 4 made on Friday September 5, 2014 at 17:52
Lowpro
Select Member
Joined:
Posts:
March 2004
2,081
On September 4, 2014 at 17:47, schmick71 said...
I could replicate the script in each area that I need to use it, but thought using a Library was a lot neater.

Short of using a Library you could place the given script within the label of a panel, then execute that script throughout your configuration file when needed using eval(). I use PEP v1 exclusively which doesn't offer Libraries, so I make use of eval() quite extensively. Works beautifully for my purposes anyway. My PEP v1 configuration file is available for download here if you'd like to check out a real-world example.
LP Related Links:
View my profile to access various
links to key posts and downloads.
Post 5 made on Friday September 5, 2014 at 18:10
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
The line that I said to print was the definition of the function itself, not the results of the function call. Since the result was 'undefined', this means that your javascript code was not interpreted and added to the 'global' scope.

This could be because of several things, including syntax errors in your file.
So, I will ask the following in the hopes that you can figure out where you went wrong:

1. Did you run your library text file through any kind of syntax checker prior to just putting on the Pronto? I recommend JSLint or other tools for this and have script mode of strict. This will allow you to see where you might have syntax errors.

2. What editor are you using? Verify you checked the box to include your global script at the Activity Level.

3. Are you doing System.include('myfile.js') as required on some environments.

4. Do you have the latest firmware in your remote that support PEP2/PEP3 constructions that you are using.

5. Anything in the diagnostics log when execute the code that prints undefined?

6. Have you referred to the requirements of providing comments in your library js file that include author and other information? Maybe your library is considered invalid? See sections 9.2.1 and 9.3 of the 1.4.3 Dev Guide.

Finally, please note that PS_DEBUG will not work for showing syntax errors in your library code as PS_DEBUG will only contain System.print results from the time the page was loaded. Library scripts are loaded/compiled before the current activity is initialized. This being said, your function is failing to compile.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 6 made on Friday September 5, 2014 at 23:57
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
I just noticed that you did not use the function keyword in front of:

panoramatest() {
}

Start there.

Next You are calling s.match() before you define and assign a function to s.OnData.

I would recommend that as you are expecting a value in variable 't' at the end of your button press, you would not want to do asynchronous serial activity. Therefore, don't bother assigning OnData of the serial port.:

// Create a function and variable t outside of the function so that value is available
// from code inside a button in case you want to use asynchronous access.

var t;

function OnSerialData(v)
{
if(!v)
{
t="Extender Error";
}
else
{
t = v;
}
};

function panoramatest()
{
var e = CF.extender[1]; // RFX 9600
if(!e)
{
t="Extender 1 is not defined";
}
else
{
var s=e.serial[0]; // Serial Port 1
s.bitrate=19200;
s.databits = 8;
s.parity=0; //None
s.stopbits=1;
if(!s)
{
t="Extender 1 is not a serial extender";
}
else
{
// Request Values from Panorama 2
// Don't use the async version.
s.onData = OnSerialData;
//s.match("Q\r","\r",1000);
// Instead use the synchronous version.
t = s.match("Q\r","\r",1000);
}
}
return t;
}

Give this a try.

FYI, during the life of the Pronto, I, and other put lots of effort into testing the Javascript engine under the Pronto. There are times when something baffles me. But when someone says something does not plain work, there is usually a user misinterpretation or just simple syntax errors. I have bolded your initial syntax errors and items missed.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 7 made on Sunday September 14, 2014 at 10:18
schmick71
Lurking Member
Joined:
Posts:
August 2011
6
Lyndel,

Many thanks for the update it has highlighted my minor errors, clearly straight forward newbie mistakes when trying to achieve something more complex than my skill levels would allow at the time.

Along with your suggestions I've gone away and invested in the Flanagan book and spent a few more hours testing the code, and also used JSLint.com so thank you it now works well.

I removed the asynchronous code as you suggested as I'm receiving a definitive answer from the Panorama when the s.match code is sent.

I've tested it over and over and have now been able to strip the various codes from the return string and return those values based on the initial function call i.e. panoramatest("Volume");.

Now onto building a Volume indicator overlay!

I'm gaining a new respect for the power of my TSU9400 with extenders! It's not an iPad but I've got the power to make it work with my components!
Post 8 made on Sunday September 14, 2014 at 13:58
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Schmick71,

I am VERY happy to see you took the plunge and stuck with it. My mother was a teacher and as a software engineer and a child of my Mom, I also like to help others grow and my hopes are that the nudge/guidance has led you down the path of building self-confidence and knowing that coding is somewhat like building a house, if you know what tools and use them for their intended purpose, things are much easier.

I have several threads over the years that I have posted, some with regard to direct questions and some with regard to thoughts or my "journey" through ProntoScript.

Some are on debugging topics using try/catch and others are just general things mapping the web environment back onto the Pronto. IIRC, that thread is entitled "But Really, what is ProntoScript".

Best of luck and I look forward to seeing you in the forums here for assistance with Script questions. I would also like to have feedback as to your "journey" and things you find that were awkward that others might also benefit from.

Now that you are building out your tool belt, if using PEP2, you might want to consider installing Jon Welfinger's simulator mod that will allow you to test on the Pronto Simulator with real TCP. Note that the simulator cannot test protected javascript.

Warm Regards,
Lyndel McGee
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