Home AMX User Forum NetLinx Studio

ATOI from an array

Can someone please tell me why this doesn't work so that I can get on with life?
BUTTON_EVENT [TP,1]
{
    PUSH:
	{
	STACK_VAR CHAR sChan[4]
	sChan = '1556'
	SEND_COMMAND dvSat, "'SP',ATOI(sChan[1])"
	SEND_COMMAND dvSat, "'SP',ATOI(sChan[2])"
	SEND_COMMAND dvSat, "'SP',ATOI(sChan[3])"
	SEND_COMMAND dvSat, "'SP',ATOI(sChan[4])"
	}
}


I'm trying to get around old firmware in an NXI that doesn't support 4-digit XCH commands. This is a distillation of what I've been trying to do. When I look at notifications all I get is SP$00 every time. I've tried assigning the four characters in sChan to 4 separate single CHAR variables, then doing ATOI, then sending it out, but it still doesn't work. I also tried with an NI-2100. Any ideas? At this point I don't even care if the answer makes me look dumb :)

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    Netlinx doesn’t handle single character arrays very well. You need to force its hand by using double quotes for ATOI like this:
    SEND_COMMAND dvSat, "'SP',ATOI("sChan[1]")"
    SEND_COMMAND dvSat, "'SP',ATOI("sChan[2]")"
    SEND_COMMAND dvSat, "'SP',ATOI("sChan[3]")"
    SEND_COMMAND dvSat, "'SP',ATOI("sChan[4]")"
    
  • viningvining Posts: 4,368
    Can someone please tell me why this doesn't work so that I can get on with life?
    BUTTON_EVENT [TP,1]
    {
        PUSH:
    	{
    	STACK_VAR CHAR sChan[4]
    	sChan = '1556'
    	SEND_COMMAND dvSat, "'SP',ATOI(sChan[1])"
    	SEND_COMMAND dvSat, "'SP',ATOI(sChan[2])"
    	SEND_COMMAND dvSat, "'SP',ATOI(sChan[3])"
    	SEND_COMMAND dvSat, "'SP',ATOI(sChan[4])"
    	}
    }
    
    

    I'm trying to get around old firmware in an NXI that doesn't support 4-digit XCH commands. This is a distillation of what I've been trying to do. When I look at notifications all I get is SP$00 every time. I've tried assigning the four characters in sChan to 4 separate single CHAR variables, then doing ATOI, then sending it out, but it still doesn't work. I also tried with an NI-2100. Any ideas? At this point I don't even care if the answer makes me look dumb :)
    Are you actually storing your digits in slots 0-9 or in the AMX standard 10-19? If it's a standard IR file then you need to add 10 to each number being sent since numeral 1 is in slot 11 not 1.
  • Thanks guys, I'll try the double quotes and see what happens. In the actual code I'm using I made sure to hit the right IR channel numbers. If it doesn't work I'll be back....
  • jweatherjweather Posts: 320
    Joe Hebert wrote: »
    Netlinx doesn’t handle single character arrays very well. You need to force its hand by using double quotes for ATOI like this:

    Nothing wrong with pulling a single character out of an array, but it's a character (= a single ASCII value) at that point, not a string or char[] like atoi() wants as input. If you were trying to put it in a string, you'd be all set:

    sChan = 'test'
    SEND_STRING 0, "'character 3 = ', sChan[3]" // outputs "character 3 = s"

    But since SP is one of the weird "literal integer" functions, you can use atoi(sChan[1]) or sChan[1]-'0' to get the integer from the ASCII value.
  • Tangent regarding 'SP' and similar send_command types
    jweather wrote: »
    But since SP is one of the weird "literal integer" functions, you can use atoi(sChan[1]) or sChan[1]-'0' to get the integer from the ASCII value.

    Those "weird" functions that have a single byte integer value for data exist because of the days of AXlink. The fewer characters transmitted, the faster the whole system could run.
Sign In or Register to comment.