Dynamic botton

122 views
Skip to first unread message

Alexander S Argollo

unread,
Jul 6, 2013, 4:56:19 AM7/6/13
to comman...@googlegroups.com
Hi Guys, ,
i would like to say tanks a lot for assistance that i received here! That is a best tool and group!!!!

I have a new question, a little miss to end my project, would like to associate a value on botton dynamically. i will tray to explain better below:

I have a  ligth switch that have a specific switch ID (SW ID). I need to discovery the SW ID dynamically, This part i was finished in my JS code, after founded the SW ID i will pass it to a turn ON or turn OFF functions. For example:

SW(a) -> POWER ON COMMAND / POWER OFF (two separeted bottons on Iviewer). I think that i need to use two CF.Setjoin on a botton PW ON and another to PW OFF, but i need to pass the SW ID value, dinamically discovered, to a functions PW ON and PW OFF.

I have a follow challenges:
Associated the SW ID for each botton (PW ON and PW OFF) dinamically on JS.
Call the Functions PW ON and PW OFF on Iviewer  and pass the SW ID for specific switch got on JS.

 I dind't know how can make it. Please someone have any idea to help me?


BR
Alex


Alexander S Argollo

unread,
Jul 6, 2013, 7:42:25 PM7/6/13
to comman...@googlegroups.com
Hi Guys, i found a litle examples with CF.setJoin and CF.getJoin, but i have a doubts, as i told i need to link the the SW ID got during feedback and a bottom dinamically.

I wrote here part of my code:
Set the variables:

var value=parseInt(matches[3],16);
CF.setJoin("d2", value); // store the SW ID

Code on Command (on Iviewer Bottom):
ZB.actions("POWER","ON");

Get the Variable:
case "POWER": if(b.toUpperCase()=="ON")  CF.getJoin("d2", ZB.sendToZBPServer_GetNode(j)); // I would like to pass the "value" got on CF.setJoin to a bottom with "j" variable . But i didnt know if it is correctly.

Bellow we can see on the log the error, we can see that the j variable is not initialized !!!!

ZB.actions: function started, input a=POWER, input b=ON
> Exception running code received from iViewer: ReferenceError: Can't find variable: j
> Code that caused the exception: (function(){var join="d2",tokens={"[join]":"d2"},list=null,listIndex=0;ZB.actions("POWER","ON");})();

Please let me know how can i solve it?

BR
Alex


2013/7/6 Alexander S Argollo <alexande...@gmail.com>


--
You received this message because you are subscribed to a topic in the Google Groups "CommandFusion Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commandfusion/9e_WL5IdfM4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
atenciosamente,
Alexander S Argollo
11-99468494
mailto: alexande...@gmail.com

Jarrod Bell

unread,
Jul 7, 2013, 8:13:00 AM7/7/13
to comman...@googlegroups.com
Instead of changing the join value (which is limited depending on the join type - digital can only be 0 or 1. See here: http://www.commandfusion.com/wiki2/software/gui-designer/joins)

...you should use Tokens: http://www.commandfusion.com/wiki2/software/gui-designer/tokens

CF.setToken("d2", "[tokenName]", value); // Wrap the name in square brackets to make it easier to identify later on

Then to get the variable, you can use JavaScript, or use the token name directly in a command attached to the button.
CF.getJoin("d2", function(j,v,t) {
CF.log("Token value is: " + t["[tokenName]"]);

Or just use [tokenName] anywhere in your command value attached to the button, and it will be replaced with the token's value at the time the command is sent.

As for your error, it's simply saying that your 'j' variable has not been defined before it's used. You need to check your code and the scope at which you are accessing the 'j' variable in this instance.

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.

alexande...@gmail.com

unread,
Jul 7, 2013, 11:42:08 AM7/7/13
to comman...@googlegroups.com
Hi Jarrod, I will study about join and tokens.

Thanks a lot
BR
Alex

Enviado do meu smartphone BlackBerry 10.
De: Jarrod Bell
Enviada: domingo, 7 de julho de 2013 09h13
Assunto: Re: Dynamic botton

Alexander S Argollo

unread,
Jul 7, 2013, 8:14:10 PM7/7/13
to comman...@googlegroups.com
Hi Jarrod, thanks a lot!!!

Now its working well!!!

BR
Alex

Alexander S Argollo

unread,
Jul 9, 2013, 10:23:58 PM7/9/13
to comman...@googlegroups.com
Hi Jorrod,
Please could you give your assistance?

I trying to initialize a variable using CF.getJoin as you can see below:

a) 1st option
var Cond=0;
CF.getJoin("d1", function(j,v,t) {Cond=t["[RecordID]"]});
if(ZB.trace) CF.log("ZB.feedback: Match pattern was reached GetJoin Result ="+Cond);

b) 2st option

i trying to use also:
var Cond=0;
Cond=CF.getJoin("d1", function(j,v,t) {t["[RecordID]"]});


In the two cases i seeing on CF.LOG that it isn't working. Boths i didnt have a success,  in the 1st i got Zero and in the 2st i got error.

Please let me know how to fix it?




2013/7/7 Alexander S Argollo <alexande...@gmail.com>

Terence

unread,
Jul 9, 2013, 10:48:22 PM7/9/13
to comman...@googlegroups.com
For the first option you're missing ; at the end of the Cond=t["[RecordID]"] line, so it should be : CF.getJoin("d1", function(j,v,t) {Cond=t["[RecordID]"];});
For the second option, equating a variable with a JS call will give you an error.

Alexander S Argollo

unread,
Jul 9, 2013, 11:02:41 PM7/9/13
to comman...@googlegroups.com
Hi Terence, thanks a lot for your assistance!!!!
 I changed as you told me, But the Cond variable still assume zero. As you see the code below:

var Cond=0;
CF.getJoin("d1", function(j,v,t) {Cond=t["[RecordID]"];});
if(ZB.trace) CF.log("ZB.feedback: Match pattern was reached GetJoin Result ="+Cond);
if (matches!=null && matches.length>0) {
if(ZB.trace) CF.log("ZB.feedback: The Object NodeSignalName matches was found *** test condition sucessfull ***");
if (parseInt(matches[5],16)==Cond) {
if(ZB.trace) CF.log("ZB.feedback: The Object Trigger NodeSignalName matches was found *** test condition sucessfull ***");
};

If i change the Cond variable to a specific value (1155) that the condiction variable can be assume the code last if will matched.

Let me know if you can see another errors, please?

Below you can see the logs:
> ZB.feedback: The Object NodeSigName matches was found *** test condition sucessfull *** > ZB.feedback: Match pattern was reached GetJoin Result =0 > ZB.feedback: The Object NodeSignalName matches was found *** test condition sucessfull ***


2013/7/9 Terence <terry...@gmail.com>
For the first option you're missing ; at the end of the Cond=t["[RecordID]"] line, so it should be : CF.getJoin("d1", function(j,v,t) {Cond=t["[RecordID]"];});
For the second option, equating a variable with a JS call will give you an error.

--
You received this message because you are subscribed to a topic in the Google Groups "CommandFusion Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commandfusion/9e_WL5IdfM4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alexander S Argollo

unread,
Jul 9, 2013, 11:10:03 PM7/9/13
to comman...@googlegroups.com
Terence,
i included the CF.Log from the Token [RecordID] below the CF.Log from variable Cond, you can see that the token assume the value 16453. Bellow you can see the log again: 

if(ZB.trace) CF.getJoin("d1", function(j,v,t) {CF.log("ZB.feedback: The Token value (u16DevAdd or RecordID1) is = " + t["[RecordID]"])});

The Log including the CF.Log from the Token:

> ZB.feedback: The Object NodeSigName matches was found *** test condition sucessfull ***
> ZB.feedback: Match pattern was reached GetJoin Result =0
> ZB.feedback: The Object NodeSignalName matches was found *** test condition sucessfull ***
> ZB.feedback: The Token value (u16DevAdd or RecordID1) is = 16543

I using the variable Cond to get the Token value (16543).

Please let me know.

BR
Alex


2013/7/10 Alexander S Argollo <alexande...@gmail.com>

Clayton Vicente

unread,
Jul 9, 2013, 11:10:11 PM7/9/13
to comman...@googlegroups.com
When using callback functions try to insert everything inside the callback, because this is asynchronous (CF.getJoin will run later or soon, you will never now).
var Cond=0;
CF.getJoin("d1", function(j,v,t) {
    Cond=t["[RecordID]"];
  //all your functions here.

});
Clayton



Date: Wed, 10 Jul 2013 00:02:41 -0300
Subject: Re: Dynamic botton
From: alexande...@gmail.com
To: comman...@googlegroups.com
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.

Terence

unread,
Jul 9, 2013, 11:22:56 PM7/9/13
to comman...@googlegroups.com
From looking at the statement : if (parseInt(matches[5],16)==Cond), the variable Cond must be assigned as an integer.
All values returned by CF.getJoin are always a string. To convert to integer, use parseInt(). Try :

var Cond=0;
CF.getJoin("d1", function(j,v,t) {
    Cond=parseInt(t["[RecordID]"]);

Barry Gordon

unread,
Jul 9, 2013, 11:58:42 PM7/9/13
to comman...@googlegroups.com

 parseInt will convert strings whose leading characters are digits forming a legal number e.g. parseInt( -123alpha) will result in -123.

-123alpha is not a numeric string but rather a string whose leading characters form a number.

 

 

As a general shortcut for converting a string which is truly a number the following will work and is very fast

x= (numericstring-0);  This is handy because of the overloading of addition as an operator, and can be used as a term of an expression

The above handles all sorts of numbers fixed point (integers), floating point , etc.

 

var x="1" var y=2;

z=x+y    results in z="12"

z=(x-0)+y results in z=3

 

When comparing two things one of which is a numericstring and the other a number no conversion should be necessary as JS will automatically do the conversion unless you are testing for absolute equality (===).

 

var x=123; var y="123";  x==y  should be true but x===y should be false

--

Alexander S Argollo

unread,
Jul 10, 2013, 7:02:50 AM7/10/13
to comman...@googlegroups.com
Guys i would like to say THANKS.

I included my code inside the CF.getJoin and its work well. 

BR
Alex


2013/7/10 Barry Gordon <ba...@the-gordons.net>

--
You received this message because you are subscribed to a topic in the Google Groups "CommandFusion Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commandfusion/9e_WL5IdfM4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commandfusio...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages