How to add Roland Checksum for a sendSysEx [Solved]

Hi,

how to calculate a Roland checksum in lua? Imagine the command looks like :

midi.sendSysex (devPort, commandArray, payLoadArray,checkSum)

and I need to calculate the checkSum based on the payLoadArray.
What’s a good way to do that?

1 Like

I assume the checksum is calculated using data in the payLoadArray. If I were you, I would:

  1. create function to calculate the checksum, eg. checksumByte = calculateChecksum(payLoadArray)
  2. concatenate commandArray, payLoadArray, and checksumByte to form byteArray
  3. send byteArray with midi.sendSysex(devPort, byteArray)
1 Like

To actually calculate it, the standard is something like sum all the bytes in the array and truncate to 7 bits, or sum all the bytes and subtract from 256, or …

The Roland manuals are usually pretty good about telling you somewhere how it’s done.

Alternatively, if you have an editor like HexEdit, you can take a dump with a checksum and calculate various ways across the data bytes until you match what is there

1 Like

It works!
Here’s the function (payLoad = a table)

function calcChecksum(payLoad)
  local result = 0
  for i= 1, #payLoad do
    result = result+payLoad[i]
  end
  result = (128-result)%128
  return result
end
3 Likes