Home AMX User Forum NetLinx Studio

Data event multiple or....

Hi

I would like to know wich way is better to do?

I have to monitoring a line feedback for 20 loads from Vantage controler. I get many answer depending wich event will go on.

In my program, wich is better to use... a DATA_EVENT with multiple nested IF ELSE ? Or multiple DATA_EVENT for the same device ?

Can I use multiple DATA_EVENT for the same device ?

ex:
DATA_EVENT [dvVANTAGE]
        {
        Statement1
        }

DATA_EVENT [dvVANTAGE]
         {
         Statement 2
         }

Comments

  • Denis wrote:
    Hi

    I would like to know wich way is better to do?

    I have to monitoring a line feedback for 20 loads from Vantage controler. I get many answer depending wich event will go on.

    In my program, wich is better to use... a DATA_EVENT with multiple nested IF ELSE ? Or multiple DATA_EVENT for the same device ?

    Can I use multiple DATA_EVENT for the same device ?

    ex:
    DATA_EVENT [dvVANTAGE]
            {
            Statement1
            }
    
    DATA_EVENT [dvVANTAGE]
             {
             Statement 2
             }
    


    Use one DATA_EVENT with a SELECT - ACTIVE format.

    See AMX tech note 616.
    http://www.amx.com/techsupport/PDNTechNote.asp?id=616
  • DenisDenis Posts: 163
    Thanks

    Thanks for this info
  • DHawthorneDHawthorne Posts: 4,584
    To elaborate, you can use multiple data events, but if you do too much of that, it is likely to impact performance. All of your events are kept in tables that are loaded on startup, so multiple events for the same device are going to result in multiple entries in the event tables, and more stuff for the interpreter to iterate through.

    Also, it will almost certainly cause confusion down the road as the code needs updating. It's much more programmer-friendly to have everything in one spot. If there are more than a few lines of code in an event, I prefer as well to put them in a function or call that is triggered by the event. That also cuts down on redundant code for similar functions.
  • DenisDenis Posts: 163
    Hi guys!

    I'm followed your recommandations on tech note, and I get some problems as results.

    When I monitoring the complete feedback <nLOAD_STATUS> I get the good feedback, but during the process, after 2 or three 3 press button, <nSTATUS> has a reverse result ( it's 0 when it must be greater than 0 and greater than 0 when it must be 0 )

    The ending results is my flag is always on...

    why ?
    {
        STRING:
        {
        LOCAL_VAR CHAR nLOAD_STATUS [100] INTEGER nSTATUS
        STACK_VAR CHAR nV_REPLY [12] 
            nLOAD_STATUS = "nLOAD_STATUS,DATA.TEXT"
    	WHILE (FIND_STRING (nLOAD_STATUS,'LO',1))
    	{
    	nV_REPLY = REMOVE_STRING (nLOAD_STATUS,'LO',1)
    	    SELECT
    		{
    		ACTIVE (FIND_STRING(nV_REPLY,'1 2 1 4',1)):
    			{
    			nSTATUS = nV_REPLY [10]
    			SEND_COMMAND dvTP_LIGHT_PISCINE, "'@TXT',70,nSTATUS"
    			IF (nSTATUS =! 0)
    			{
    			nLOAD_STATUS_104 = 1
    			}
    			ELSE
    			{
    			nLOAD_STATUS_104 = 2
    			}
    			}
    			
    		}
    	}
        }
    }
    
  • DHawthorneDHawthorne Posts: 4,584
    Not being familiar with how your feedback strings are formatted, I would venture a guess that you have an ASCII conversion problem. You are populating nStatus with a single character from an array. If your string, for example, was sExample = '10101' and nStatus = sExample[2], then nStatus would be 30, not 0. If the feedback is ASCII and not a raw numeric value, you need to run it through an ASCII conversion - nStatus = ATOI("sExample[2]"). That would give you a 0. The double quotes, by the way, are necessary in the ATOI function when giving it a single character as a parameter (converting the CHAR to CHAR[1]). YOu could, alternately, bypass all this by changing your flag check to read IF(nStatus != '0'), which perhaps is more elegant - the single quotes tell the compiler you are comparing to an ASCII value in the first place. But if you need a numeric value for other purposes (like for using the non-zero values), use ATOI(). Likewise your nLOAD_STATUS variable - you need to make sure everything is ASCII or non-ASCII; mixing them is going to casue unexpected results.
  • DenisDenis Posts: 163
    Hi
    Concerning feedback format,

    < LO 1 2 1 4 0 > or < LO 1 2 1 4 XX > XX = any value between 1 and 100
    Explain: <LO> LOAD <1> Master 1 <2> Enclosure 2 <1> Module 1 <4> Load 4 <0 0r XX> Value of power in %

    < LO 1 2 1 4 95 > in this string the value is 95 %

    9 is 10th character in nREPLY array

    In my program, I want when the value is 0 as my flag is off and On when the value is greather than 0

    In help file is indicate "data sent and received over the RS232 interface should be in ASCII format and in all capitol letters."
  • jjamesjjames Posts: 2,908
    Assuming your flag is nLOAD_STATUS_104, you can try replacing your active statement with this:
    ACTIVE (REMOVE_STRING(nV_REPLY,'1 2 1 4',1)):
    {
    	nSTATUS = ATOI(nV_REPLY)
    	SEND_COMMAND dvTP_LIGHT_PISCINE, "'@TXT',70,nSTATUS"
    	IF(nSTATUS)
    		ON[nLOAD_STATUS_104]
    	ELSE
    		OFF[nLOAD_STATUS_104]
    }
    

    I'm also going to assume you have more than one load you'll want to track. If so, you'll have to parse out the master, module, and loads an put them into an array.
  • Denis wrote:
    nV_REPLY = REMOVE_STRING (nLOAD_STATUS,'LO',1)
    ...
    Concerning feedback format,
    ...
    < LO 1 2 1 4 95 > in this string the value is 95 %

    Given the format of the string, you should not be doing REMOVE_STRING() using 'LO' as the string to find and remove.

    Given the example you had (including the < and > which I am not sure are part of the string, or are just there to show the string), the string nV_REPLY would contain '< LO' and the string nLOAD_STATUS would contain ' 1 2 1 4 95 >'.

    If there is a string delimiter (such as > in your format listed), you should change it to:
    nV_REPLY = REMOVE_STRING (nLOAD_STATUS,'>',1)
    

    As for which character(s) in the nV_REPLY array is Value of the load power, I can't tell from what you said, but it doesn't look like the 10th character in your example.
  • DenisDenis Posts: 163
    Hi CWPartridge

    < > it's only for delimitate de string ( if it will do confuse please advise me what can I take to do that )

    The string like this LO 1 2 1 4 95

    I get 9 only if I ask for the 10th character

    In other word I need to know if this character is 0 or greather 0 to put my flag on or off

    JJames

    Indeed, I have 20 loads to check status. In the lighting system there are some timed event controled by lightning control, and I need to know all status change for my LCD panel
  • jjamesjjames Posts: 2,908
    Ok, again running off of some assumptions, this is what I've come up with to manage all your loads. Since you want to track 20 loads, you'll probably need to track three different modules. So make an array like so:
    DEFINE_VARIABLE
    VOLATILE INTEGER nLOAD_STAT[3][8]	// NUMBER OF MODULES, NUMBER OF LOADS
    

    Next, use this as a baseline your DATA_EVENT:
    DATA_EVENT[dvVANTAGE]
    {
    	STRING:
    	{
    		LOCAL_VAR CHAR Buffer[100]
    		STACK_VAR CHAR Reply[100]
    		LOCAL_VAR INTEGER nMASTER	// HOLDS MASTER
    		LOCAL_VAR INTEGER nMODULE	// HOLDS MODULE
    		LOCAL_VAR INTEGER nLOAD		// HOLDS LOAD
    		LOCAL_VAR INTEGER nPERCENT	// HOLDS PERCENT OF LOAD
    		
    		WHILE(FIND_STRING (DATA.TEXT,"$0D",1))			// WHILE WE FIND A CARRIAGE RETURN
    		{
    			Reply = "Buffer, REMOVE_STRING(DATA.TEXT,"$0D",1)"
    			CLEAR_BUFFER Buffer
    			REMOVE_STRING(Reply,'LO ',1)					// REMOVE 'LO ' PART OF STRING
    			nMASTER = ATOI(REMOVE_STRING(Reply,' ',1))		// REMOVE AND PLACE AS MASTER
    			nMODULE = ATOI(REMOVE_STRING(Reply,' ',1))		// REMOVE AND PLACE AS MODULE
    			nLOAD   = ATOI(REMOVE_STRING(Reply,' ',1))		// REMOVE AND PLACE AS LOAD
    			nPERCENT= ATOI(Reply)							// PLACE AS PERCENT
    			nLOAD_STAT[nMODULE][nLOAD] = nPERCENT	// ASSIGN PERCENT TO ARRAY
    		}
    		Buffer = "Buffer,DATA.TEXT"
    	}
    }
    

    From here, your flags will be ON or OFF based on the load's percentage. If it's zero, it will be considered off. Anything greater than zero, will be considered on. So, if you evaulate like this:

    IF(nLOAD_STAT[1][6]) // IF THE LOAD IS ON . . .

    or

    IF(!nLOAD_STAT[1][6])// IF THIS LOAD IS OFF . . .
  • DenisDenis Posts: 163
    Hi Jeremiah

    Hi tried your code but I get this report from compiler, I tried some tricks with this code but I get other problem report

    I created LOC_VAR CHAR for nLOAD_STATUS ( I think as you have forget it)

    Vantage support confirm me as the string results is in ASCII format

    Starting NetLinx Compile - Version[2.3.0.0] [02-02-2006 13:35:45]
    C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10577: Expected type [DEVCHAN] but found [INTEGER]
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10512: Cannot convert type [INTEGER] to [DEVCHAN]
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10504: [<ref>] is not compatible with a [DEVCHAN] value
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10585: Dimension mismatch: [0] vs. [3802320]
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10533: Illegal assignment statement
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10512: Cannot convert type [INTEGER] to [DEVCHAN]
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10504: [<ref>] is not compatible with a [DEVCHAN] value
    ERROR: C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs(245): C10577: Expected type [DEVCHAN] but found [INTEGER]
    C:\Documents and Settings\Denis\Desktop\Babeu_AMX Program files\J.Babeu.axs - 8 error(s), 0 warning(s)
    NetLinx Compile Complete [02-02-2006 13:35:47]
  • jjamesjjames Posts: 2,908
    Can you post the block of your code where the compiler is pointing to with those erros?
  • DenisDenis Posts: 163
    JJames

    Since I'm working with feedback on serial control for the first time, is it possible to tell me if AMX system see carriage return even we don't see in the string? I'm just speaking with Vantage support and he confirm to me as Vantage controler send each time a carriage return character

    Since I don't know if AMX see it, I replaced $OD by LO

    DATA_EVENT[vdv_VANTAGE]
    {
    	STRING:
    	{
    		LOCAL_VAR CHAR Buffer[100]
    		STACK_VAR CHAR Reply[100]
    		LOCAL_VAR INTEGER nMASTER	// HOLDS MASTER
    		LOCAL_VAR INTEGER nMODULE	// HOLDS MODULE
    		LOCAL_VAR INTEGER nLOAD		// HOLDS LOAD
    		LOCAL_VAR INTEGER nPERCENT	// HOLDS PERCENT OF LOAD
    		LOCAL_VAR CHAR nLOAD_STAT	
    		
    		WHILE(FIND_STRING (DATA.TEXT,'LO',1))			// WHILE WE FIND A CARRIAGE RETURN
    		{
    			Reply = "Buffer, REMOVE_STRING(DATA.TEXT,'LO',1)"
    			SEND_COMMAND dvTP_LIGHT_PISCINE, "'@TXT',70,nmaster"
    			CLEAR_BUFFER Buffer
    			REMOVE_STRING(Reply,'LO ',1)				// REMOVE 'LO ' PART OF STRING
    			nMASTER = ATOI(REMOVE_STRING(Reply,'1',1))		// REMOVE AND PLACE AS MASTER
    			nMODULE = ATOI(REMOVE_STRING(Reply,'5',1))		// REMOVE AND PLACE AS MODULE
    			nLOAD   = ATOI(REMOVE_STRING(Reply,'7',1))		// REMOVE AND PLACE AS LOAD
    			nPERCENT= ATOI(Reply)					// PLACE AS PERCENT
    			nLOAD_STAT = [nMODULE][nLOAD] = nPERCENT		// ASSIGN PERCENT TO ARRAY
    		}
    		Buffer = "Buffer,DATA.TEXT"
    	}
    }
    
  • DenisDenis Posts: 163
    Sorry

    I forgot the first part of code you post .

    I place volatile var and delete line as I create, replace "$OD" instead 'LO'and do new test and now I get this

    Starting NetLinx Compile - Version[2.3.0.0] [02-02-2006 16:47:07]
    C:\Documents and Settings\Denis\Desktop\test.axs
    WARNING: C:\Documents and Settings\Denis\Desktop\test.axs(89): C10240: Ignoring unrecognized char [$ = ASCII(36)] in input
    ERROR: C:\Documents and Settings\Denis\Desktop\test.axs(89): C10233: Symbol [OD] not defined
    C:\Documents and Settings\Denis\Desktop\test.axs - 1 error(s), 1 warning(s)
    NetLinx Compile Complete [02-02-2006 16:47:09]
  • jjamesjjames Posts: 2,908
    My apologies; I shouldn't have gotten short.

    The nLOAD_STAT needs to be defined up under the DEFINE_VARIABLE section near the top. It needs to be a multidimensional array.
    nLOAD_STAT[3][8]
    
    The first number (3) will be the number of modules you're trying to read from. The 8 shouldn't change because you can only have 8 loads per module.
    WHILE(FIND_STRING (DATA.TEXT,'LO',1))	
    
    If you replaced the $0D with 'LO', you will only get the 'LO' and none of the valuable information we need.
    			nMASTER = ATOI(REMOVE_STRING(Reply,'1',1))		// REMOVE AND PLACE AS MASTER
    			nMODULE = ATOI(REMOVE_STRING(Reply,'5',1))		// REMOVE AND PLACE AS MODULE
    			nLOAD   = ATOI(REMOVE_STRING(Reply,'7',1))		// REMOVE AND PLACE AS LOAD
    			nPERCENT= ATOI(Reply)					// PLACE AS PERCENT
    
    The REMOVE_STRING will only remove up to whatever information IF it finds a '1' in the "Reply" string. Since we MIGHT have more than one master, we need to look for the first space, and remove up to and including it. So now, nMASTER = '1 ', but since we use ATOI, it removes the space, and nMASTER = 1. Reply now contains only the module, load and percent. This is repeated until we know there won't be anymore spaces and we just convert the remaining information in Reply to nPERCENT.
    nLOAD_STAT = [nMODULE][nLOAD] = nPERCENT
    
    nLOAD_STAT should be declared up in the DEFINE_VARIABLE section like I said earlier. Most (if not all) of your errors are coming from here. It should read:
    nLOAD_STAT[nMODULE][nLOAD] = nPERCENT
    

    Hopefully this mkaes more sense.
  • jjamesjjames Posts: 2,908
    Denis wrote:
    replace "$OD" instead 'LO'and do new test and now I get this

    Make sure it's a zero, and not an "Oh". Should be "Zero-Dee"
  • DenisDenis Posts: 163
    Yeah!

    Special tanks to JJames for his great help, now all works fine
Sign In or Register to comment.