Home AMX User Forum AMX Technical Discussion

more string hiccups

Trying to pad a string with spaces and put a CR on the end
DATA_EVENT[vdvBleh]
{
    COMMAND:
    {
	STACK_VAR CHAR c_tmp[9]
	STACK_VAR INTEGER i3
	
	c_tmp = DATA.TEXT
		
	WHILE(LENGTH_STRING(c_tmp) < 8){
	    c_tmp = "c_tmp,' '"
	}
	c_tmp = "c_tmp, $0d"
	

    }
}

I get all the spaces I need, but the carriage return won't go; or at least it doesn't show up in the variable debug.

edit: just made c_tmp a local_var instead of stack and it's working now. no idea.

Comments

  • viningvining Posts: 4,368
    Are you receiving a single CHAR at a time or a string that ideally contains 7 CHARS ?

    Edit:
    Forget the above I see what you're doing now.

    The code looks like it should work fine but you shouldn't be able to see the var in debug unless you're stepping through it using break points. Otherwise to view while developing you'll need to change it to a local as I see you did in your edit and change it back to a stack when it's working properly.

    Either stack or local should work the same unless the data coming in is broken up and not in one chunk. Since this is a command handler that's not usually the case though.
  • travistravis Posts: 180
    I was stepping through it with breakpoints. The front of the string comes in all at once. I changed it back to stack and it doesn't show up.
  • DHawthorneDHawthorne Posts: 4,584
    I don't think debugging is entirely reliable with stack variables. It doesn't mean it's not working as expected, just not debugging as expected. I find it helpful in such cases to send the variable to the terminal screen (send_string 0) and use a simple routine to convert non-printable characters to the decimal representation:
    DEFINE_CONSTANTS
    
    MAX_STRING_SIZE = 5096 
    
    (***********************************************************)
    (* FUNCTION:     sCleanAscii                               *)
    (* RETURN:       CHAR[]                                    *)
    (* PARAMETERS:   sString - SOURCE STRING                   *)
    (*    Replaces high and low order ASCII characters with    *)
    (*        <ASCII #>                                        *)
    (***********************************************************)
    DEFINE_FUNCTION CHAR[MAX_STRING_SIZE] sCleanAscii (CHAR sString[])
    {
        STACK_VAR CHAR sTemp[MAX_STRING_SIZE] ;
        STACK_VAR INTEGER nCount ;
    
        FOR(nCount = 1; nCount <= LENGTH_STRING(sString); nCount ++)
        {
    	SELECT
    	{
    	    ACTIVE(sString[nCount] < 32) : // low order ASCII
    	    {
    		sTemp = "sTemp, '<', ITOA(sString[nCount]), '>'"
    	    }
    	    ACTIVE(sString[nCount] > 126) : // high order ASCII
    	    {
    		sTemp = "sTemp, '<', ITOA(sString[nCount]), '>'"
    	    }
    	    ACTIVE(TRUE) : sTemp = "sTemp, sString[nCount]" ;
    	}
        }
    
        RETURN sTemp ;
    }
    
    
  • travistravis Posts: 180
    That's actually pretty helpful. I had that function in the Strings library I got from this forum, but had never used it.

    And now I notice that the terminal actually shows a $0D when I send the string directly to it:
    Line     21 (12:21:57)::  string to device: RSPW1   $0D
    
Sign In or Register to comment.