Go Down

Topic: SisEx max receivable size <64 bytes. More does not receive. (Read 291 times) previous topic - next topic

Razoumihine

Hello,

I'm using an arduino MEGA 2560, with MIDI library 4.3.1.

After some time I finally found that I cannot receive SysEx messages longer than 63bytes. The bellow instructions work fine until 63 bytes. FOr example, if I set the SysExMaxSize=  16, then I receive SysEx up to 16bytes, not longer. Code works as per settings.

How to use custom settings

But if I set a custom value above 63 bytes, which I need for my code, then it only receives SysEx messages with length <64 bytes.

Is there a hard limitation on that board? Or maybe another custom setting in the library?

Lionel

In case, here bellow is the code:

Code: [Select]
//With MIDI OUT plug to MIDI IN, this code sends to MIDI OUT a SisEx message
//with increasing size at each time a button is pressed. The code receives this
//Sysex message to the MIDI IN prints it to serial monitor. 


/////////////////////////MAIN SETTINGS////////////////////////////
#include <MIDI.h>
#include <Keypad.h>

struct MySettings : public midi::DefaultSettings
{
    static const unsigned SysExMaxSize = 128 ;
    // Accept SysEx messages up to xxx bytes long.
//but works only bellow 64 bytes
};

// Create a 'MIDI' object using MySettings bound to Serial1.
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, MySettings);

//////////////////////////////KEYPAD//////////////////////////////////
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'a','b','c','d'},
  {'e','f','g','h'},
  {'i','j','k','l'},
  {'m','n','o','p'}
};
byte rowPins[ROWS] = {41, 39, 37, 35}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {27, 29, 31, 33}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int i = 60; // first SysEx syze setting
void setup()
{
  Serial.begin(9600);
  MIDI.begin();
 MIDI.turnThruOff();
}

void loop()
{
byte Message[i];     
//*************************SEND******************************************   
  char key = keypad.getKey();
 
  //Si une touche du clavier est enfoncée
  if (key != NO_KEY)
  {
     
       for (int j = 0; j<i; j++)
           {
            Message[j]=0;
           }
       
    MIDI.sendSysEx(i, Message, false); // envoie le message sysex
    Serial.print("SysEx  sent: ");
     //Boucle pour écrire dans le moniteur série le message SysEx envoyé
     for (int j = 0; j<i; j++)
      {
      Serial.print(Message[j],HEX);
      Serial.print(" ");
       }
    Serial.println("");
    i++;
   }
   

   
   
 
//*************************RECEIVE******************************************       
   //si un message midi est reçu
    if (MIDI.read()==1)
   {
         int a = MIDI.getSysExArrayLength (); // récupère la longueur du message SysEx
         
         const byte *  MyArray; // Déclare la structure qui va recevoir le message SysEx
         MyArray = MIDI.getSysExArray(); // Récupère le message SysEx

             
                 Serial.print("Received ");
                 Serial.print(a);
                 Serial.print(" bytes: ");
                 for (int i = 0; i<a; i++)
                      {
                      Serial.print(MyArray[i], HEX);
                      Serial.print(" ");
                      }
                 Serial.println();
               
                     
     }

}


el_supremo

The size of the SYSEX buffer is defined in MIDI.h
Code: [Select]
#define MIDI_SYSEX_ARRAY_SIZE 255 // Maximum size is 65535 bytes.
I have mine set to 255 (as above) but the default is 64.
However, the comment at the end is a lie because there's a bug in MIDI.cpp which restricts the buffer size to 255.
Code: [Select]
for (byte i=0;i<MIDI_SYSEX_ARRAY_SIZE;i++) {
The index 'i' is declared to be a byte but to handle 65535 bytes it must be int.
Code: [Select]
for (int i=0;i<MIDI_SYSEX_ARRAY_SIZE;i++) {

Pete
Don't send me technical questions via Private Message.

Razoumihine

Hi Pete,
The MIDI.h file does not have this line or equivalent:
Code: [Select]
#define MIDI_SYSEX_ARRAY_SIZE 255 // Maximum size is 65535 bytes.



As well as i don't find the following in the MIDI.cpp line, or equivalent:
Code: [Select]
for (byte i=0;i<MIDI_SYSEX_ARRAY_SIZE;i++)

Maybe you refer to another library?






el_supremo

OK, I was using the default arduino library.
Now I understand your problem. You are overriding the default sysex size in the way that is described in a comment in midi_Settings.h and also in how to use custom settings and it still doesn't work.
At the moment, I can't see any reason for the library to restrict a sysex to 63 bytes.
I would try changing the sysex size directly in midi_Settings.h just to see if it has any effect.

Pete
Don't send me technical questions via Private Message.

Razoumihine

Well it is the same if I change directly the value in the library. I'll try with the default library.  :smiley-confuse:

Grumpy_Mike

That limit is being imposed by the default size of the input serial buffer. Nothing to do with the library.

Razoumihine

That limit is being imposed by the default size of the input serial buffer. Nothing to do with the library.
Yes for the default size of the input buffer, but that library recombines the input buffer in order to receive longer SysEx messages.

But anyway, I finally solved that. The problem was not on the input length, but on the output length.
It's no interest here to detail step by step everything on why I thought it was an input issue.

The point is that the library setting works fine, and I was limited only with the sending length.
You may see additional details here:
https://github.com/FortySevenEffects/arduino_midi_library/issues/77

Lionel


Go Up