-
Notifications
You must be signed in to change notification settings - Fork 94
Sketch freezes until MIDI port is opened by PC #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Tested on Mac OS X 10.10.5, Arduino 1.6.2. |
Hi @odbol , the code you are trying to use is outdated, since in the meantime we went through a very big effort to support modular USB Core and Pluggable libraries. |
@facchinm I think I fixed it now. BTW, thanks for the work on the PluggableUSB! Clever design, and such an improvement! |
So I added this issue as a comment to Arduino core, but putting here for visibility (and ultimately this is where we'd apply the fix).
The whole Arduino sketch will freeze if you try using it after the USB is connected, but before an app opens the MIDI port and starts listening to the MIDI sent from the Arduino.
Try with this test sketch: https://github.com/odbol/Arduino-MIDI-Test-Sketch
I've narrowed it down to this:
MidiUSB.sendMIDI()
, which freezes the whole sketch. (LED stops blinking)USBD_Send()
function blocks until there is a connection.USBD_Send()
stops blocking).SerialUSB.write()
function does not block if there is nothing connected. See theif (_usbLineInfo.lineState > 0)
line in CDC.cpp for how they do this.USBD_Send()
will block (i.e. the MIDI port is not yet opened on the other end), and avoid calling it if it will block (just drop the messages if there's nothing listening).I've attempted to duplicate the
_usbLineInfo.lineState
technique in CDC.cpp, but couldn't get it to work:https://github.com/odbol/Arduino/tree/midi-fixserial
Any advice or help would be much appreciated!
The text was updated successfully, but these errors were encountered: