Home AMX User Forum NetLinx Studio

Smart-E Matrix Checksum

Hello all,

I've been trying to control a Smart-E 8x8 matrix, the protocol is pretty straightforward, but it requires an XOR checksum on all the previous bytes appended to the end of the string. I could calculate the checksum manually, but that means a huge library of statements to cater for all the different permetations of the matrix.

The code i'm trying to use is
DEFINE_FUNCTION sendswitcherstring(CHAR cmd[50])
{
switcherstring="$BE,$EF,cmd"
checksum=left_string(switcherstring,1)
for(x=2;x<=length_string(switcherstring);x++)
    {
    tempstring=mid_string(switcherstring,x,1)
    checksum=checksum BXOR tempstring
    }    

send_string dvSwitcher,"switcherstring,checksum"
}

It works in my head, but it's obviously not working in practice as it never gets the right result.

Any ideas?

Comments

  • AMXJeffAMXJeff Posts: 450
    mshunt wrote: »
    Any ideas?

    This seems to work...
    DEFINE_FUNCTION CHAR Calc_Checksum(CHAR cData[])
    {
    	STACK_VAR CHAR CS;
    	STACK_VAR BYTE;
    	
    	FOR (BYTE = 1; BYTE <= LENGTH_ARRAY(cData); BYTE++)
    	{
    		CS = CS BXOR cData[byte];
    	}
    	
    	RETURN CS;
    }
    
    DEFINE_PROGRAM
    
    WAIT 100 
    {
    	LOCAL_VAR CHAR cData[100];
    	
    	cData = "$BE,$EF,$00,$00,$00,$00,$00"
    	
    	SEND_STRING dvDevice,"cData, Calc_Checksum(cData)";
    }
    
    
  • mshuntmshunt Posts: 23
    I got it working, I was trying to use a CHAR as the checksum variable, and it just wasn't working. When I set checksum as an Integer it worked, Netlinx compiler did the rest. I've had to use the same method for PTZ camera control and I got that working today.

    I'm still getting my head around different variable types.
Sign In or Register to comment.