Home AMX User Forum NetLinx Studio

XOR Comparison binary Checksum

Hey,

Controlling a Beyerdynamic MIX 10 NG2 and it wants a checksum on the end... yay.

From the manual:
"The check sum results from a vertical XOR comparison of the individual command bytes in the binary system."

There's an example and I understand how I manually calculate it... but how would I do this in NetLinx? Theres no hex to binary command? The other option is to calculate all the checksums manually for all the different codes I am going to need... which I would prefer to avoid.

User Manual: http://asia-pacific-india.beyerdynamic.com/shop/media//usermanual/MIX10NG2_BA_E_A5.pdf

Comments

  • PhreaKPhreaK Posts: 966
    '^' or 'BXOR' are what you are after. Check out 'Bitwise Operators' in the NS help file for more info.
  • Like PhreaKsaid correctly, it is the BXOR.

    CHAR cChk
    cChk = cBYTE1 BXOR cBYTE2 BXOR....BXOR BYTEn
    ...
    SEND_STRING dvSerial,"cBYYTE1, cBYTE2, ..., cBYTEn, cChk"

    a function to calculate the checksum may be
    DEFINE_FUNCTION CHAR BXORcheckSum(CHAR sBytes[])
    {
    STACK_VAR CHAR cChk
    STACK_VAR INTEGER nX
    FOR(nX=1;nX<=LENGTH_STRING(sBytes);nX++)
    {
    cChk = cChk BXOR sBytes[nX]
    }
    RETURN cChk
    }
    
    ...
    DEFINE_VARIABLE
    CHAR sMyString[] = { $01,$02,$FF }
    CHAR cMyChkSum
    ...
    cMyChkSum = BXORcheckSum(sMyString)
    SEND_STRING svSerial,"sMyString,sMyChkSum"
    
Sign In or Register to comment.