Home AMX User Forum NetLinx Studio

Buffer, Length_string question

All,

I need to flip the state of the nDIM_FLAG variable based on if the buffer is filled or not. I am clearing it out after each message fills, and the length is constantly shifting from 0 to 13, which is what I want. However, my length_string code is not working to flip the variable. Any help is appreciated!
DATA_EVENT[dvLights]
{
    ONLINE:
    {
    }
    STRING:
    {
	LOCAL_VAR sINTEGER Zone1
	LOCAL_VAR sINTEGER Zone2
	LOCAL_VAR sINTEGER Zone3
	LOCAL_VAR sINTEGER Zone4
	
	SEND_STRING 0, "'FROM LIGHTS: ',DATA.TEXT"
	
	Lights_Buffer = DATA.TEXT
	
	IF(FIND_STRING(DATA.TEXT, "'DL,'", 1))
	{

	    SELECT
	    {
		ACTIVE(FIND_STRING(DATA.TEXT, "'DL,[1:1],'", 1)):
		{
		    REMOVE_STRING(DATA.TEXT, "'DL,[1:1],'", 1)
		    Zone1 = ATOL(DATA.TEXT)
		    SEND_LEVEL dvTP_Lights, 10, (Zone1*2.55)
		}
		ACTIVE(FIND_STRING(DATA.TEXT, "'DL,[1:2],'", 1)):
		{
		    REMOVE_STRING(DATA.TEXT, "'DL,[1:2],'", 1)
		    Zone2 = ATOL(DATA.TEXT)
		    SEND_LEVEL dvTP_Lights, 11, (Zone2*2.55)
		}
		ACTIVE(FIND_STRING(DATA.TEXT, "'DL,[1:3],'", 1)):
		{
		    REMOVE_STRING(DATA.TEXT, "'DL,[1:3],'", 1)
		    Zone3 = ATOL(DATA.TEXT)
		    SEND_LEVEL dvTP_Lights, 12, (Zone3*2.55)
		}
		ACTIVE(FIND_STRING(DATA.TEXT, "'DL,[1:4],'", 1)):
		{
		    REMOVE_STRING(DATA.TEXT, "'DL,[1:4],'", 1)
		    Zone4 = ATOL(DATA.TEXT)
		    SEND_LEVEL dvTP_Lights, 13, (Zone4*2.55)
		}
	    }
	    CLEAR_BUFFER Lights_Buffer
	    
	    IF(LENGTH_STRING(Lights_Buffer) > 0)
	    {
		nDIM_FLAG = 1
	    }
	    ELSE
	    {
		nDIM_FLAG = 0
	    }
	}

    }
    ONERROR:
    {
	SEND_STRING 0, "'FROM LIGHTS: ',DATA.NUMBER"
    }
    OFFLINE:
    {
	IP_CLIENT_OPEN(5, '192.168.1.119', 24, IP_TCP)
    }
}

Comments

  • I believe your "Lights_buffer" is not a buffer but a variable.
    Try setting the variable to an empty string instead of CLEAR_BUFFER:
    Lights_buffer = "''" (that is a set of single parentheses inside a set of double parentheses)
    That should do the trick.
    ...Jim...
  • I believe your "Lights_buffer" is not a buffer but a variable.
    Try setting the variable to an empty string instead of CLEAR_BUFFER:
    Lights_buffer = "''" (that is a set of single parentheses inside a set of double parentheses)
    That should do the trick.
    ...Jim...

    It is a buffer, I didn't include that part of the code but it is defined as a buffer...
  • JasonSJasonS Posts: 229
    This code will never set "nDim_Flag" because the "Clear_Buffer" statement previous to your IF sets the length of the buffer to 0. This code will also not work reliably with partial messages or multiple messages in the buffer. Does this protocol use a delimiter?
  • DHawthorneDHawthorne Posts: 4,584
    You are testing your string length immediately after a CLEAR_BUFFER statement, and withing the same conditional that fires it. At that point, it will *always* return zero, since you just cleared it. I think if you put your test outside the conditional that runs the CLEAR_BUFFER, you will get the results your are expecting.
  • JasonS wrote: »
    This code will never set "nDim_Flag" because the "Clear_Buffer" statement previous to your IF sets the length of the buffer to 0. This code will also not work reliably with partial messages or multiple messages in the buffer. Does this protocol use a delimiter?

    Thank you. I've tried placing it outside of the conditional and it hasn't worked yet. I need to be able to set buttons to flash while receiving a response from the device, and latch on when the scene has recalled. Any help would be appreciated.

    Thanks
  • CLEAR_BUFFER Lights_Buffer
    IF(LENGTH_STRING(Lights_Buffer) > 0)
    {
    	nDIM_FLAG = 1
    }
    ELSE
    {
    	nDIM_FLAG = 0
    }
    
    This code will always set nDIM_FLAG to 0. Additionally, you aren't doing anything with Lights_Buffer in this string event besides copying data.text into it and as written it will never contain any data outside of this string event.

    I'm not sure from your posts and the code you've posted what exactly you are trying to do with either Lights_Buffer or nDIM_FLAG so I'm not really sure how to suggest fixing it.
  • rfletcher wrote: »
    CLEAR_BUFFER Lights_Buffer
    IF(LENGTH_STRING(Lights_Buffer) > 0)
    {
    	nDIM_FLAG = 1
    }
    ELSE
    {
    	nDIM_FLAG = 0
    }
    
    This code will always set nDIM_FLAG to 0. Additionally, you aren't doing anything with Lights_Buffer in this string event besides copying data.text into it and as written it will never contain any data outside of this string event.

    I'm not sure from your posts and the code you've posted what exactly you are trying to do with either Lights_Buffer or nDIM_FLAG so I'm not really sure how to suggest fixing it.

    When I send a command to this device, it returns a string which never changes after it's finished processing. Basically, I was thinking if I placed the message in a buffer, I could use that to trigger a variable used to flash a button while the device is processing a message. When it's no longer processing the message, I'd like to flip the variable to off so I can make my button latch on. Seems easy, but I can't figure it out to save my life.

    Any help would be appreciated.

    Thanks,
    Matt
  • dchristodchristo Posts: 177
    mjones2620 wrote: »
    However, my length_string code is not working to flip the variable.
    	    CLEAR_BUFFER Lights_Buffer
    	    
    	    IF(LENGTH_STRING(Lights_Buffer) > 0)
    	    {
    		nDIM_FLAG = 1
    	    }
    	    ELSE
    	    {
    		nDIM_FLAG = 0
    	    }
    	}
    

    You're clearing the buffer just before you check the length, so the length will always be zero at that point.

    --D
  • RaphayoRaphayo Posts: 111
    Look like a part of the programmer 2 exam :)

    Raphaël Thiffault
Sign In or Register to comment.