xxxajk
Well-known member
As title says... I'd like to know when the computer closes the Serial connection.
Teensy is self powered.
!Serial doesn't seem to provide a way to know this until it is being reconnected.
Looking at how USB is implemented, it appears that I would have to do some sort of timeout, which I would be totally fine with.
What (if any) method or function could be called to cause Serial interface on USB to become negated?
I know that libusb at least sends a packet when you close the pipe on all platforms, and I'll have to see if this is true using the kernel using my beagle.
Here is the simple sketch.
Teensy is self powered.
!Serial doesn't seem to provide a way to know this until it is being reconnected.
Looking at how USB is implemented, it appears that I would have to do some sort of timeout, which I would be totally fine with.
What (if any) method or function could be called to cause Serial interface on USB to become negated?
I know that libusb at least sends a packet when you close the pipe on all platforms, and I'll have to see if this is true using the kernel using my beagle.
Here is the simple sketch.
Code:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWriteFast(LED_BUILTIN, LOW);
}
void loop() {
int junk;
if(!Serial) {
digitalWriteFast(LED_BUILTIN, LOW); // visually show disconnected
delay(250); // so you can see the effect when app is reconnecting
} else {
digitalWriteFast(LED_BUILTIN, HIGH); // visually show app connected
// echo back anything entered
while(Serial.available()) {
junk = Serial.read();
Serial.write(junk);
}
}
}