Home AMX User Forum AMXForums Archive Threads Tips and Tricks

Need some input

Okay, so I'm programming to parse a response from a LiteTouch Standard CCU. I'm looking for LED status changes. Here's what it's supposed to spit at me:
"'09 XX YYYYYYYYY',13"
Where XX is the controls station (00-FF) and each Y corresponds to an LED (1-9) on the control station. If Y = 0 LED is off, else it's on.

So here's how I want to parse it:
STRING:
{
	LOCAL_VAR CHAR REPLY [100]
	LOCAL_VAR CHAR BUFFER[100]
	LOCAL_VAR INTEGER STATION
	LOCAL_VAR CHAR LED_NUM[9]
	
	
	WHILE(FIND_STRING(DATA.TEXT,"$0D",1))
	{
		Reply = "Buffer, REMOVE_STRING (DATA.TEXT,"$0D",1)"
		
		IF(LEFT_STRING(REPLY,2) = '09')
		{
			SET_LENGTH_STRING(REPLY,LENGTH_STRING(REPLY)-1)
			REMOVE_STRING(REPLY,'09 ',1)
			STATION = HEXTOI(REMOVE_STRING(REPLY,' ',1))
			FOR(nLOOP_COUNT = 1;nLOOP_COUNT<=9;nLOOP_COUNT++)
				n_LITE_STATUS[STATION][nLOOP_COUNT] = ATOI(REPLY[nLOOP_COUNT])
		}
		Buffer = "Buffer,DATA.TEXT"
	}
        Buffer = ''
        Replay = ''
}


But it's not working. It seems that the ATOI isn't working. However, if I change the code in the FOR loop to...
FOR(nLOOP_COUNT = 1;nLOOP_COUNT<=9;nLOOP_COUNT++)
	n_LITE_STATUS[STATION][nLOOP_COUNT] = REPLY[nLOOP_COUNT]-48
... it works just fine, and I get my 0s and 1s I need for button feedback on my panel.

Any idea why it won't parse the way I want it to using the ATOI statement?

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    Jerermiah,

    Change:

    ATOI(REPLY[nLOOP_COUNT])

    To:
    ATOI(?REPLY[nLOOP_COUNT]?)


    Technically, you shouldn?t need the double quotes, however, I was told a while back by an old time AMXer that ATOI doesn?t always work correctly if you don?t include them. So by default I include the double quotes whenever I use ATOI. I had the same problem before with ATOI when I was picking off an element in an array as your example shows and adding the quotes resolved the issue.

    Does that do the trick for you?
  • jjamesjjames Posts: 2,908
    Great!

    Worked like a charm. That definately needs to go into the Tips & Tricks section. Thanks for the help!
  • Joe HebertJoe Hebert Posts: 2,159
    Anytime. You're right, this is a good tip to post.
  • Joe HebertJoe Hebert Posts: 2,159
    jjames wrote:
    That definately needs to go into the Tips & Tricks section.
    We can always count on Suzanne listening in. We've been moved. Thanks, Suzanne. :)
  • Why ATOI didn't work as expected

    The ATOI function requires a string parameter. Anything other than a string will cause ATOI to return a 0 (zero).

    In your program:

    ATOI(REPLY[nLOOP_COUNT])

    the parameter for the ATOI function is a character, not a string. (Okay, we could start the whole argument that a single character is a string, but according to the Axcess and NetLinx compilers it isn't.) By providing the array index nLOOP_COUNT to the character array (string array) NetLinx provided a single character from that array at that index. To make it a proper string parameter, placing the double quotes around the parameter satisfies the requirement of the ATOI function.

    (from a long time AMXer....)
  • (from a long time AMXer....)

    Funny... Never heard of the guy. :)

    - Chip
Sign In or Register to comment.