-
-
Save paragontechgroup/1348208 to your computer and use it in GitHub Desktop.
// 1) Created global token (in global token manager) called "ProcessorPort" with default value 8020 and checked persist. | |
// 2) Created system called "Localhost" to 127.0.0.1 | |
// 3) Created setup page with text input field with serial join 9999 with command "setPort" in "Send Value Actions > command" | |
// 4) Created command in "Localhost" system called "setPort" with following Javascript: | |
CF.setToken(CF.GlobalTokensJoin, "[ProcessorPort]", "[@s9999]"); | |
// 5) Made button on setup page called "What is my port" with code: | |
CF.getJoin(CF.GlobalTokensJoin, function(j, v, tokens) { var guiPort = tokens["[ProcessorPort]"]; CF.setJoins([{join: "s590", value: guiPort}]); }); | |
// This grabs the global token "[ProcessorPort]" and displays it in serial join s590 for testing. All works like a champ until I restart guiDesigner. I'd assume that from a fresh start and navigating to the setup page and pressing the "What is my port" button that the set persistent global token value would be displayed. Also, even from a fresh start pressing the "What is my port" button does not display the peristent global token "[ProcessorPort]" value, I'd think it would at least display 8020 since that was set as the default. | |
// Also just tested an init.js fle in the script manager with the intention to prepopulate the port input field with the port defined in the global persistent tokens. This seems to have no effect: | |
// Initialize GUI | |
CF.userMain = function() { | |
// iViewer initialization is now complete and the CF environment is fully available | |
// Read the global context that we need | |
restoreContext(); | |
}; | |
function restoreContext() { | |
// Read the contents of the ProcessorPort token | |
CF.GetJoin(CF.GlobalTokensJoin, function(join, value, tokens) { | |
var contextStr = tokens["ProcessorPort"]; | |
if (contextStr != null && contextStr.length > 0) { | |
CF.setJoins([{join: "s9999", value: contextStr}]); | |
} | |
}); | |
} |
Thanks that helped!
However, now it seems that its still not storing into the persistent token across gui sessions. If I restart the GUI and go to setup page and click "What is my port" button, it shows the "ProcessorPort" persistent token default of 8020 instead of the port I entered into the setup page. Setting default to 0 then overwrites with 0. Seems the default persisten token value keeps overwriting my setting. My iViewer Next settings are :
Reload Gui Layout: on
Reload GUI Assets: on
Remember past gui file: off
Preoad images: off
show preload status: off
multitasking: off
ivewer next version number: 4.0.184 build 184.
Any idea what Im screwing up?
Also, CF.userMain = function() {} doesnt seem to be firing. I restructured my init.js to:
// Initialize GUI CF.userMain = function() { // iViewer initialization is now complete and the CF environment is fully available // Read the global context that we need restorePort(); CF.log("Starting..."); }; function restorePort() { // Read the contents of the ProcessorPort token CF.log("Restore port"); CF.getJoin(CF.GlobalTokensJoin, function(join, value, tokens) { var contextStr = tokens["ProcessorPort"]; if (contextStr != null && contextStr.length > 0) { CF.setJoins([{join: "s999", value: contextStr}]); CF.log("Getting ProcessorPort: " + contextStr ); } }); }
Yet none of the CF.log entries are ever posted to the debugger which leads me to believe its not firing or I dont have it called properly. CF.userMain is like jQuery's $(document).ready(function() { }) no?
P.S. I changed my serials to 999 instead of 9999 during prior troubleshooting so that is not an error in the code.
I solved the init.js not loading problem. Apparently the *.js file in script manager cannot be in a subfolder to the project. E.g. I had my init.js in /images/js/init.js and it would not work. When I moved my init.js file to be in the same root folder as my *.gui file it worked perfectly. Is this intended behavior?
Still cant seem to get the global tokens from being overwritten by their default values in token manager.
FYI, This is now my init.js and works like a champ in the same folder as the *.gui file.
CF.userMain = function() { // Restore the setup page fields with global token values restoreFields("ProcessorPort","s999"); restoreFields("ProcessorIP","s997"); }; function restoreFields(str,j) { // Read the contents of the token CF.getJoin(CF.GlobalTokensJoin, function(join, value, tokens) { var contextStr = tokens[str]; if (contextStr != null && contextStr.length > 0) { CF.setJoins([{join: j, value: contextStr}]); CF.log("Getting " + str + ": " + contextStr ); } }); }
Reload GUI Layout will cause the tokens to be overwritten, it's how you set the default values. Turn off reload, and it will load the GUI from cache and the persistent token values will not be overwritten.
SWEET! Worked like a champ. Now, can you enlighten me on the CF.setSystemProperties() parameters real quick to change the control system config using those persistent tokens? I couldnt find it in your docs. I have everything setup now and working and ready for that. Then I can deploy this sucker to beta testing in our company. THANKS!
Replace the system name with an empty string and it should manipulate the main control system:
http://www.commandfusion.com/docs/scripting-beta/net.html#cF.setSystemProperties
// Change the port on the main control system
CF.setSystemProperties("", {port: newPort});
Hey Jarrod,
I have everytihing setup but still a small issue. My init file is this:
CF.userMain = function() { // Setup control system connection CF.getJoin(CF.GlobalTokensJoin, function(join, value, tokens) { // Get persistent global token values var p = tokens["ProcessorPort"]; var a = tokens["ProcessorIP"]; // Set system properties CF.setSystemProperties("", {port: p, address: a, enabled: true}); // Log settings to console CF.log("Control system IP address set to: " + a ); CF.log("Control system port set to: " + p ); // Restore fields with updated values restoreFields("ProcessorPort","s999"); restoreFields("ProcessorIP","s997"); }); // Watch for page flips and set default digital joins CF.watch(CF.PageFlipEvent, onPageFlip); }; // apply current global token values to setup fields function restoreFields(str,j) { // Read the contents of the token CF.getJoin(CF.GlobalTokensJoin, function(join, value, tokens) { var contextStr = tokens[str]; if (contextStr != null && contextStr.length > 0) { CF.setJoins([{join: j, value: contextStr}]); } }); } // Callback function for page flips function onPageFlip(previousPage, newPage) { // We get called when switching pages switch (newPage) { case 'SETUP_Main_Page': CF.setJoins([{join: "d990", value: 1},{join: "d991", value: 0}]); break; default: } CF.log("Flipped from page " + previousPage + " to page " + newPage); }
Now if I put a bogus IP in my setup page the system will not connect a throw an error. If I put a bogus port (and correct IP) I get this:
11:10:55> SCRIPT: Javascript interface up and running, opening connection with iViewer 11:10:55> SCRIPT: Established connection with iViewer 11:10:55> SCRIPT: Javascript starting up. iViewer version: v4.0.184 build 184 11:10:55> SCRIPT: Set control system ProcessorPort: 8021 11:10:55> SCRIPT: Set control system ProcessorIP: 10.10.200.20 11:10:55> SCRIPT: Control system port is: 8021 11:10:55> SCRIPT: Control system IP address is: 10.10.200.20 11:10:56> s999 = 8021 11:10:56> s997 = 10.10.200.20 11:10:56> Control System trying to connect 11:10:56> Control System: connected to 10.10.200.20:8020
It's like the system is reverting back to the in the project properties of the *.gui file. I tried not entering the ip and port info in the project properties but then get the error "System ' ' Does not exist" when I try to set the port and IP via setSystemProperties.
I also tried a test. Set the port to 9000 in the project properties of the *.gui file, then set the project IP in the setup page to 10.10.200.20 and port to 8020. The debugging monitor now reports:
13:46:01> SCRIPT: Javascript interface up and running, opening connection with iViewer 13:46:01> SCRIPT: Established connection with iViewer 13:46:01> SCRIPT: Javascript starting up. iViewer version: v4.0.184 build 184 13:46:01> SCRIPT: Control system IP address set to: 10.10.200.20 13:46:01> SCRIPT: Control system port set to: 8020 13:46:02> s997 = 10.10.200.20 13:46:02> Control System trying to connect 13:46:02> Control System failed connecting 13:46:02> Control System trying to connect 13:46:03> Control System failed connecting 13:46:03> Control System trying to connect 13:46:03> Control System failed connecting 13:46:05> Control System trying to connect
It's like it's totally disregarding the port from the setSystemProperties and using the one from the project settings.
There seems to be an issue with CF.setSystemProperties() where it won't really take the change if you only change the port when accessing the control system using a direct IP address. Thanks for nailing this.
I noted your comments on IRC regarding the fact that setting a different IP address in the GUI, then updating it using CF.setSystemProperties() fails to connect. I'll figure out what's wrong and fix it in a couple days ( and will add proper logging of the address it's trying to connect to in the Script system log for good measure).
Florent
One thing to note is that you are referencing the token with a different name sometimes, [ProcessorPort] is not the same as ProcessorPort
var guiPort = tokens["[ProcessorPort]"];
should be:
var guiPort = tokens["ProcessorPort"];
and also:
CF.setToken(CF.GlobalTokensJoin, "[ProcessorPort]", "[@s9999]");
should be:
CF.setToken(CF.GlobalTokensJoin, "ProcessorPort", "[@s9999]");