Home AMX User Forum NetLinx Studio

Do I need a bitwise calculation?

NEC M300X Projector lamp runtime query says to concatenate a string in Windows Calc in Hex mode, switch to decimal mode and divide by 3600 to get lamp run time. Oh yeah, it's code for an Axcent3. Am I missing something? Any help would be appreciated.
DEFINE_VARIABLE
INTEGER LAMP_STRING[256]
PROJ_HOURS

(* IN THE FIND STRING CODE *)

LAMP_STRING= "$00,$00,$46,$50"
LAMP_HOURS = LAMP_STRING/$E10

Comments

  • PhreaKPhreaK Posts: 966
    To concatenate the returned value you will need to iterate over the characters and add them along with a bit shift. If it's always going to be four bytes this should do the trick:
    /**
     * Load 4 bytes of big endian data contained in a character array into a long.
     *
     * @param	x		a 4 byte character array containg the data to load
     * @return			a long filled with the passed data
     */
    define_function long raw_be_to_long(char x[4])
    {
        return x[1] << 24 + x[2] << 16 + x[3] << 8 + x[4]
    }
    

    Otherwise if it's an unknown length you will need to set up a basic iteration.

    Once you've got that it sounds like the device is just spitting back the lamp time in seconds, the divide by 3600 then just converts it to hours.
  • rdriederrdrieder Posts: 25
    Great idea!

    Unfortunately, I'm dealing with an Axcent3. I'm pretty sure Axcess code doesn't have the shift capability.
  • PhreaKPhreaK Posts: 966
    Ah to easy. Replace the left shift's with some multiplication:
    return x[1] * $1000000 + x[2] * $10000 + x[3] * $100 + x[4]
    
    And change it to a define call.
  • PhreaKPhreaK Posts: 966
    Or as a loop for an unknown length something like this should do the trick:
    integer i
    integer j
    long multiplier
    long ret
    for (i = length_string(x); i; i--) {
    	if (i > 1) {
    		multiplier = $100
    		for (j = i - 2; j; j--) {
    			multiplier = multiplier * $100
    		}
    	} else {
    		multiplier = 1
    	}
    	ret = ret + x[i] * multiplier
    }
    
    *untested
  • rdriederrdrieder Posts: 25
    Thanks-got it working

    This works:
    ((x[1] * (256*256*256)) + (x[2] * (256*256)) + (x[3] * 256) + x[4]) /3600
    

    This does not:
    x[1] * $1000000 + x[2] * $10000 + x[3] * $100 + x[4] / 3600
    

    Nor does this:
    ((x[1] * $1000000) + (x[2] * $10000) + (x[3] * $100) + x[4]) /3600
    

    Interesting...

    Appreciate your help!
Sign In or Register to comment.