Serial Monitor missing data on some Macintosh computers

PaulStoffregen

Well-known member
When Teensy sends data very rapidly with the lines/sec benchmark, on some Macs the serial monitor loses parts of the incoming data.

serial_monitor_issue_mac.png

But when I run it here on my Macbook Air, I see this:

screen.png

Why the data loss happens on some Macs but not others is a mystery. :(
 
Yes, here's a first guess to try... a copy of usb_serial.c without any transmit flushing. This will cause problems with other programs, so it's only meant for testing with this speed benchmark. Other programs which don't transmit tons of data continuously will withhold sending until you've printed a multiple of 64 bytes. The idea is to make sure we only send full 64 byte USB packets to your Mac, to see if that makes any difference.

To use this, control-click Arduino and select "Show Package Contents" from the context menu.

Then in the new window, navigate to Conents/Java/hardware/teensy/avr/cores/teensy3. Copy this usb_serial.c file into that folder, replacing the copy already there. You shouldn't need to restart Arduino. It is supposed to notice the file is new and automatically recompile it on your next Upload or Verify.
 

Attachments

  • usb_serial.c
    8.3 KB · Views: 178
Forget what I said on twitter, I found a 3.6!

Ok this first test is Arduino 1.8.8, macOS 10.13.6, Teensduino 1.45. I'll update to latest and try again in a bit.

Old usb_serial.c (included with package):
Screen Shot 2019-05-07 at 11.42.04 AM.jpg

New usb_serial.c (provided my Paul):
Screen Shot 2019-05-07 at 11.46.01 AM.jpg

Both just stop printing at the point where it cuts off (10001323 in the second one). I also get "An error occurred while uploading the sketch" but teensyduino shows the new sketch uploading. This is a common problem for me when using any Teensy board I've learned to ignore it but could be related (it has been brought up in previous forum discussions on this same topic).
 
Just as a reminder - the missed data and hanging only happens when USB Type is set to something including Serial. If it's set to Raw HID then the serial printout works perfectly (but only in Arduino Serial Monitor, of course. No other serial terminal sees it).
 
I'm on Mac OS 10.12.6 (Sierra) and there's no problem nor with Arduino 146 with Arduino serial monitor neither with custom build (core from github master) + (iTerm2 or xterm) with tycmd monitor
Tried Teensy on Mac usb Port, Teensy on Thunderbold Dock's USB, even on USB hub -> TB Dock : no loss, around 34900+ lines/second in all cases

The tests I did were -DUSB_MIDI_AUDIO_SERIAL

Is it a Mojave+ problem ? If not may be you setup a poll, with OS version and USB Mac's chipset type/manufacturer or whatever
 
It has existed since at least Sierra. High Sierra did some fixes to serial in the OS that we hoped would fix the problem but didn't seem to.
 
Ok, looks like the problem may be something on the Macintosh side.

Next thing to try is whether Coolterm can receive the data without dropouts.

To select the serial port, click Connection > Options, then click the "Re-Scan Serial Ports" button at the bottom if Teensy doesn't show in the Port drop-down. The other settings don't matter. Here's a screenshot of how I tested.

coolterm1.jpg

Then click the "Connect" button in the toolbar. Here's how it looks on my Macbook Air.

coolterm2.jpg

If Coolterm can receive the data without problems, then the bug is very likely in Teensyduino serial monitor code. Or maybe in the Arduino IDE itself?
 
Now using a Teensy LC (left the 3.6 at home, sorry for the change but the behaviour is the same).

First upload. Actually worked fine but Arduino Serial Monitor hung after a second or so.
Screen Shot 2019-05-08 at 1.50.36 PM.jpg

SIDENOTE: Just as a reminder, once in a while it works fine. AND that uploaded sketch continues to work. BUT if you re-upload the same sketch without changing anything, the missed characters bug shows up. It seems to me that it is usually the first upload that is more likely to work but I have never been able to consistently repeat it.

Next upload. Missed characters and Serial Monitor hang (i.e. serial data stops streaming).
Screen Shot 2019-05-08 at 1.50.54 PM.jpg

Same upload checked in CoolTerm. Many missed characters BUT does not hang (i.e. serial data continues to stream).
Screen Shot 2019-05-08 at 1.51.40 PM.jpg

These screenshots were all done with the 64-byte modified usb_serial.c. But I just switched back to the original file and ran it again and the behaviour is exactly the same.
 
Paul, let me know if you'd like me to test anything else.

The only hint I've got to think about is something to do with serial modems in the OS - sometimes in the network preferences teensy will keep creating new modem devices (USB Serial, USB Serial 1, USB Serial 2...). BUT this is also not consistently repeatable. Adafruit SAMD based boards will sometimes do this too, but they don't drop serial data...
 
I did some quick testing with T3.6 and adafruit M4 feather (SAMD51) using USB lines sketch to MAC OS 10.13.6, arduino serial monitor on macbook pro.

T3.6 no losses lines/sec=35401
ada M4 no losses lines/sec=12814

using 1.8.8 with 1.47-beta2
 
Last edited:
Just tested with a Feather M0 Bluefruit, and a Trinket M0. Both work as expected - not hanging and not dropping data - settling around 5500 lines/sec.

Tried multiple uploads and power cycles on each just to be sure.
 
p.s. FYI just did another test with Teensy to verify that it fails after Adafruit succeeds and it behaves just like before (i.e. it still drops data and hangs the serial monitor)

NOTE: I can stop the monitor from hanging on Teensy if I add a delay(1) to the end of your benchmark program (see below just to be clear). It still drops data just like the previously seen but doesn't hang anymore.

Code:
void setup() {
  Serial.begin(1000000); // edit for highest baud your board can use
  while (!Serial) ;
  count = 10000000;
  prior_count = count;
  count_per_second = 0;
  prior_msec = millis();
}

void loop() {
  Serial.print("count="); 
  Serial.print(count);
  Serial.print(", lines/sec=");
  Serial.println(count_per_second);
  count = count + 1;
  uint32_t msec = millis();
  if (msec - prior_msec > 1000) {
    // when 1 second as elapsed, update the lines/sec count
    prior_msec = prior_msec + 1000;
    count_per_second = count - prior_count;
    prior_count = count;
  }
  delay(1);
}
 
Back
Top