I was playing with USBserial library and found something really annoying. The main loop woudn't be executed if USB isn't connected. So, while the usb is plugged, LED1 blinks, when unplugged, LED1 stops. Also, if connected for some time, it would stop anyway if hyperterminal or some other pc aplication isn't using that virtual port.
How to detect USB state? How to ignore USB not presented and execute the rest of the code anyway?
#include "mbed.h"
#include "USBSerial.h"
USBSerial pc;
DigitalOut myled1(LED1);
int main() {
while(1) {
myled1 = 1;
wait(0.2);
myled1 = 0;
pc.printf("I am a virtual serial port on LPC\r\n");
}
}
I was playing with USBserial library and found something really annoying. The main loop woudn't be executed if USB isn't connected. So, while the usb is plugged, LED1 blinks, when unplugged, LED1 stops. Also, if connected for some time, it would stop anyway if hyperterminal or some other pc aplication isn't using that virtual port.
How to detect USB state? How to ignore USB not presented and execute the rest of the code anyway?