TinyUSB WebUSB and serial functions

Hi

I am trying to get my RP2040 based board to send data to a web page through TinyUSB/WebUSB (Adafruit_USBD_WebUSB).
I manage to write data from the MCU to the web page, however, as soon as my data exceeds 64 bytes, the data is lost.

The problem is that I can't manage to divide my data into smaller chunks.
I tried to use the web_usb.flush() function, but it doesn't have any effect.
When I look at the Adafruit_USBD_WebUSB.cpp, I see

void Adafruit_USBD_WebUSB::flush(void) {}

so the flush function seems to be empty.
How can I force my Serial buffer to be sent ?

Why not? Show us what you tried, and describe what happened.

Here is my code to test WebUSB (this is part of a larger program)

Adafruit_USBD_WebUSB usb_web;

void  send_params(byte _key, byte layout_number, byte _num, byte _cc, byte _ch, byte _type) {
  byte buf[6] = {_key, layout_number,  _num,  _cc,  _ch, _type};
    usb_web.write(buf, 6);
}

void  test() {
  for (byte i = 0; i < 12; i ++) {
    byte layout_number = 0;
    byte _num = i;
    byte _key = 10;
    byte _cc = b[0].short_control[layout_number];
    byte _ch = b[0].short_ch[layout_number];
    byte _type = b[0].short_type[layout_number];
    send_params(_key, layout_number, _num, _cc, _ch, _type);
  }  
}

void line_state_callback(bool connected)
{
  if ( connected ) {
    //   usb_web.println("Connected" );
    test() ;
  }
}

// the setup function runs once when you press reset or power the board
void setup_webusb()
{
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
  // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
  TinyUSB_Device_Init(0);
#endif

  usb_web.setLineStateCallback(line_state_callback);
  usb_web.begin();

  // wait until device mounted
  while ( !TinyUSBDevice.mounted() ) delay(1);
}


void usbweb_loop()
{
}

the send_params function sends arrays of length 6, but on the web page I receive a big array of 6 x the size of the "for" loop in test().
if this size is <12, the buffer is < 64 bytes and the message is sent, if it bigger than 64 bytes, nothing is sent.

That result strongly suggests that you are not terminating transmissions properly.

I imagine that study of the library documentation or examples would be useful.

Thanks for your answer.
I have studied the library as much as I could (FYI, it's here ), but I came here because my understanding has reached its limits.

Basically, webusb opens a serial port. In the example provided, there's nothing fancy about the write() function.
I don't get how I can force it to get sent on purpose, or to overcome the 64 bytes limit.

Your snippet looks nothing like the example, which assumes ASCII data transmission, naturally terminated by CRLF. For binary data transmission, the receiving end has to know what to expect.

For informed help, please read and follow the instructions in the "How to get the best out of the forum" post, linked at the head of every forum category. Post ALL the code, using code tags, and explain what the program is supposed to do.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.