Options

# CheckSum8 Modulo 256

AVprogramer
Posts:

**8**Hi,

I need advice on how to implement CheckSum8 Modulo 256 in Netlinx Studio.

In past, I used that function to calculate checksum:

DEFINE_FUNCTION CHAR BXORcheckSum(CHAR sBytes[])

{

stack_var char this_sum

STACK_VAR INTEGER nX

this_sum = $00

FOR(nX=2;nX<=5;nX++)

{

this_sum = this_sum BXOR sBytes[nX]

SEND_STRING 0, ("'Checksum PRocess Result: ',this_sum")

}

RETURN this_sum

}

That function worked correctly, but now I control different TVs, and now works only with checksum calculation using CheckSum8 Modulo 256

https://www.scadacore.com/tools/programming-calculators/online-checksum-calculator/

0

## Comments

816It's pretty simple... create sum of all bytes the checksum has to be calculated over, and then do a MOD 256 to that sum, to get just the lower 8bits of the sum

8Hi,

Thanks for the advice, but unfortunately this code doesn't work entirely correctly.

I want to send a string to increase and decrease the volume like that: $AA$12$01$01$0F$(CRC)

Where I have to calculate CRC every time that's why I need this function.

And now when I put this string into the CRC calculator from this website:

https://www.scadacore.com/tools/programming-calculators/online-checksum-calculator/

in this form: 1201010F, I get CRC = 23 and this is how it should be(result in attachment).

Whereas with your code I get 12

816hm, I added a little code around, the function is unchanged, working as expected...

rename the txt file to axs.

The only difference I see just now is that in the first code I had a comma in the FOR() parameters instead of a semicolon. But this gives a syntax error when compiling, so should not have an effect to the result.

389I couldn't see what would be wrong with the code either, so I ran it and it produces the right checksum. when I put in:

`"$12,$01,$01,$0F"`

23 comes out as the checksum, as expected. So don't know what is different on your side

8Hi.

Yes, the function works correctly, it's my fault in implementing it in my code.

Thanks, Marc Scheibein for help.