Teensy 4.0 Detect USB presence?

Status
Not open for further replies.

donperryjm

Well-known member
I have a section of code that outputs data to the USB serial, but this runs in the loop.
I want to optimize the code to prevent it from trying to spit that out to USB isn't connected.
All that concatenation forming work could be avoided in my loop.

IS there a flag to check if USB serial is connected?
 
You can easily ignore lack of USB connection
Yes, it fills-up a buffer, but when this buffer is full all further data are dropped.
You can see that by writing data to USB, disconnecting USB from PC and after some time reconnecting.
At that point you see that first the last data before disconnecting are arriving followed by new data

One possibility would be to using Serial.availableForWrite() and stop using it when it returns zero
 
Status
Not open for further replies.
Back
Top