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

Login:
Pass:
 
 

Page 1 of 2
Topic:
Help with Prontoscript
This thread has 19 replies. Displaying posts 1 through 15.
Post 1 made on Wednesday July 8, 2020 at 00:07
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
Does any one have a working example of a script that works with either Eventghost and or a RS232 Global Cache device?

Thanks
Post 2 made on Wednesday July 8, 2020 at 17:24
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Which model of GlobalCache 232? There was the older GC100 then the ITach series and now the GC series. The new models appear to support HTTP and restful calls but as you want 232 I presume you want to be able to receive events.

On the older GC100, Serial port 0 was addressed via TCP/IP port 9000. Once you connected to 9000, you simply sent and received data over the socket. You did not have flexibility to configure the 232 hardware port parameters on the fly.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Thursday July 9, 2020 at 00:32
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
I have the IP2SL iTach TCP/IP to Serial (RS232). I don't know java and just starting to learn. I understand what your saying but need samples to learn form. Thanks for your help. I can control it from Python but do not know how to convert it to JAVA. Here is a sample in Python,


sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = '192.168.1.6'
PORT = 4999
sock.connect((HOST, PORT))
sock.settimeout(10)
sock.sendall("!1MVLUP\x0D\r")
Volume = sock.recv(4096)[2:-1]
sock.close()
del sock
Post 4 made on Thursday July 9, 2020 at 13:54
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
JavaScript is not Java. Download the prontoscript dev guide from the Pronto files section of this site and have a look at the tcpsocket examples. Based on the python you posted, the code will be very similar.

I authored a thread many years ago regarding what is prontoscript don’t have the link handy but hoping you can find it.

JavaScript is the language that makes web pages work and was extended by Philips with their own object types. Just like a web browser has a window object, pronto script has activity, page, widget, tcpsocket, udpsocket, etc.

As you are learning I do recommend this dev guide as it will help you get up to speed. I also recommend o’reilly book on JavaScript 5 by David Flanagan you only need chapters 1 to 10 out of that book for core JavaScript.


Also search this forum for tcpsocket or tcp socket and you will find many examples of setting up a socket to write the string you listed as well as to asynchronously receive any data from itach. Your example uses a synchronous read but asynchronous is easier to manage.

Here is one such link that is very close to what you need. ;-)
[Link: remotecentral.com]

Last edited by Lyndel McGee on July 9, 2020 14:08.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 5 made on Thursday July 9, 2020 at 16:13
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Here is an example that should work. I think your code above works but note that \x0D and \r are identical and you are sending 2 carriage returns with each command that does nothing except to cause extra processing on the receiver's end.

Put all this code into the Activity Script.


System.setDebugMask(9);

var socket;
var buffer = "";
var CR = "\r";


function onSocketConnect() {
// once connection is established, you can write anything
// write is not done here as we want to send commands based on button presses.
// sendCommand("!1MVLUP");
}

function onSocketData() {
var temp,first;
buffer+=socket.read();
// here, you have to use substring, split, or other methods to get actual messages.
// assuming that each response is delineated by a carriage return \r or \x0d, you can do the following:
first = buffer.indexOf(CR);
while (first >= 0) {
// do something with the data - extract first message up to but on including CR.
temp = buffer.substring(0, first);
buffer = buffer.substring(first + 1);
notifyMessageReceived(temp);
// find next CR.
first = buffer.indexOf(CR);
}
}

function onSocketIOError(e)
{
System.print("sock IO Error error:" + e);
}

function notifyMessageReceived(message) {
System.print("Received:");
// message will not have the terminating \r as it was stripped of as the message delimiter.
System.print(message);
}


function closeSocket() {
if (socket) {
if (socket.connected) socket.close;
socket = null;
}
}

function resetSocket() {
// if currently connected, clean things up.
closeSocket();
// create asynchronous socket.
socket = new TCPSocket(false);
// reset buffer clearing any data from previous socket.
buffer = "";

// assign callbacks for connect, data received, and ioError.
socket.onConnect = onSocketConnect;
socket.onData = onSocketData;
socket.onIOError = onSocketIOError;
}

function sendCommand(command) {
if (socket) socket.write(command + CR);
}

// create a new socket and connect
resetSocket();
// request connect to IP, port with a timeout
socket.connect("192.168.1.6",4999,10000);


Put this code into a button you create on a page in the same activity.

sendCommand("!1MVLUP");


On the same page, create a panel with ProntoScript Name of "_PS_DEBUG_" so you can see the output. See section 14.1 of the ProntoScript Dev Guide 1.4.3 from here [Link: files.remotecentral.com]
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 6 made on Friday July 10, 2020 at 01:51
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
OK so the code works but now I want to use this code across every Panel as well as use it in some of the hard buttons, how would you recommend doing that. I guess it may be best adding it to a library but have not had luck getting it to work.
Post 7 made on Friday July 10, 2020 at 13:56
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Did you have a look at the latest Dev Guide where I think there is an entire chapter dedicated to Libraries? The David Flanagan book also explains library modules and namespacing in either Chapter 11 or 12.

The code that goes into the Activity script should be in a library but of course you would want this to be namespaced, etc...

In order for your code to be referenced as a library, it must have a header on it that indicates Title, Author, and Version.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 8 made on Friday July 10, 2020 at 16:12
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
thanks for the reply. Yes I have been readying the guide but its all greek to me. LOL I got it working in a library now. I can send the command if I add it to a button on any pages. How do you call the script from the hard button vol + button on the remote? I tried adding sendCommand("!1MVLUP"); to the but that does not work. and of course you can figure that if I am trying to add it to the volume + button, how to you make a repeat.
Post 9 made on Saturday July 11, 2020 at 21:28
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
If your library is a 'System' library meaning active for all activities, then you can likely add this to the Volume+ button on the System Page.

However, in an activity where Volume+ does not use the System Properties (that check box in the top right of the properties dialog), you will have to add the script to Volume+ in each activity where this box is NOT checked.


If your library was added at the activity level, you will have to add script to all activities Volume + buttons.

A picture is worth 1000 words here. Can you take some screenshots from PEP2, post them somewhere, an link them here?

With regard to the repeating commands, have a look a the dev guide's Widget class specifically searching the PDF for onHold and repeatInterval.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 10 made on Saturday July 11, 2020 at 21:41
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
So I got it to work from a library. So that's good, thanks for your help.

So the library was added at the system properties activity level, so I did have to add script to all activities Volume buttons.

Here is the sample of the code I used for the volume.

var onHoldInterval = 50;
onHold = function()
{
sendCommand("!1MVLUP").executeActions();
onHoldInterval=1;
};
Post 11 made on Sunday July 12, 2020 at 00:54
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
You have to use keyword ‘this’ inside the button script


this.onHold = function ()...

this.onHoldInterval = 500;

If still struggling, email me the config.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 12 made on Sunday July 19, 2020 at 11:53
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
So another question regarding your sample script. So I got it working, I created a library and added it to my project. Works great, controls my AV Receiver perfectly. So then I took the sample scrip, modified the commands to control my Sony TV. Works great as well. Created another library and added it to my project. If both library are added to my project and active, only the TV script works. If I uncheck the TV library from the project then the first one will work again. Any thoughts on why? If I leave the first library active and manually add the TV script to each activity under the advanced tab, both works. So it seems to be limited tot the library's.
OP | Post 13 made on Sunday July 19, 2020 at 16:21
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
Never mind I figured it out. Was a conflict with Variables. Didn't know that Variables from Library carried over to one another. Once I changed them up they both work now.
Post 14 made on Sunday July 19, 2020 at 18:47
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Glad you got it sorted.

The key to libraries is defining them in such as way that they are nested objects and in what are called 'namespaces' using reverse domain naming.

com.lrmassoc.SqueezeLib

com.lrmassoc.YahooWeatherRss

at the top level, you declare a variable named 'com'.




var weather = new com.lrmassoc.YahoWeatherRSS.Weather();
var squeeze = new com.lrmassoc.SqueezeLib.SqueezeComet();


Now, you have 2 different instances of objects in a single activity named with 2 unique variable names. Reusing common variable names such as 'socket' outside of the library only asks for conflicts.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 15 made on Sunday July 19, 2020 at 20:24
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
Sorry I don't understand how to implement this. Still reading through all 200 plus pages. Also this is my first time dealing with JavaScripts. Not sure what you mean at the top level i declared a variable named com
Page 1 of 2


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