CNMAT / OSC

OSC: Arduino and Teensy implementation of OSC encoding
cnmat.berkeley.edu/oscuino
Other
727 stars 135 forks source link

Problem sending bundles in quick succession from Max #118

Closed natcl closed 1 month ago

natcl commented 3 years ago

I have this strange issue when trying to read bundles on Teensy/Arduino Uno where I will get an INVALID_OSC error if I try to send 2 or more bundles in quick succession from Max/MSP.

The patch is very simple:

image

The test code (included below) is pretty straightforward too.

I tried also sending the OSC data from Max to Node-RED and compared the bytes received there with the bytes received by the Arduino and it's exactly the same.

Here are the byte that are sent:

[35,98,117,110,100,108,101,0,0,0,0,0,0,0,0,1,0,0,0,16,47,116,101,115,116,0,0,0,44,105,0,0,0,0,0,255]
[35,98,117,110,100,108,101,0,0,0,0,0,0,0,0,1,0,0,0,16,47,116,101,115,116,0,0,0,44,105,0,0,0,0,0,255]
#include <OSCBundle.h>
#include <OSCBoards.h>

#ifdef BOARD_HAS_USB_SERIAL
#include <SLIPEncodedUSBSerial.h>
SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
#else
#include <SLIPEncodedSerial.h>
 SLIPEncodedSerial SLIPSerial(Serial);
#endif

void setup() {
  SLIPSerial.begin(115200);
}

void test(OSCMessage &msg) {
  if (msg.isInt(0)) {
    Serial.println(msg.getInt(0));
  }
}

void loop() {
  OSCBundle bundleIN;
  int size;

  while(!SLIPSerial.endofPacket()) {
    if( (size = SLIPSerial.available()) > 0) {
       while(size--) {
         bundleIN.fill(SLIPSerial.read());
       }  
     }
  }
  if(!bundleIN.hasError()) {
    bundleIN.dispatch("/test", test);

  } else {
    Serial.print("Error: ");
    Serial.println(bundleIN.getError());
  }
  bundleIN.empty();
}

oscBug.zip

adrianfreed commented 1 month ago

I pushed a potential fix for this kind of thing