PDA

View Full Version : Serial Port Emulation via USB



jerenrich
01-02-2013, 10:44 PM
My Teensy 3.0 mistakenly thinks the serial monitor is open 2500ms before it is actually ready. I'm not sure what happened, but after a computer restart, under "Tools", the serial port has started to show up as a grey-ed out, "Serial Port: (emulated)". I suspect a behind the scenes driver update, but I now need to insert a "delay(2500)" after "while (! Serial) {}" in order to see serial output from my setup routine.

What has changed? Is there anyway to avoid such a long wait? Thanks


void setup() {
Serial.begin(57600);
while (! Serial) {}
delay(2500); //Previously, I just had to wait 100ms
Serial.println("Setup");
}


void loop() {
delay(500);
Serial.println("Loop");
}

PaulStoffregen
01-03-2013, 12:51 AM
Windows, Mac, or Linux... and which version? And is this beta 9 or 10? These details matter!

jerenrich
01-03-2013, 12:59 AM
Windows Version 7. And with both Teensy Beta 9 & 10. Perhaps coincidentally, this happened after I installed Beta 10, which also coincided with a system reboot.

jerenrich
01-03-2013, 01:15 AM
I now suspect that "While (! Serial) {}" is not working with this new USB driver, and my long sleep was just giving me enough time to manually open the console. Based on a few more tests, it appears that the serial port consistently takes 357ms to open, regardless of whether a console is open on the other side to receive (I used the code below, starting up the serial monitor before / after hitting "reset").


unsigned long startupTime, serialReadyTime;
unsigned long i = 0;

void setup() {
Serial.begin(57600);

startupTime = micros();
while (! Serial) {
i++;
}
serialReadyTime = micros();

Serial.println("Setup");
}


void loop() {
delay(500);
Serial.print(i);
Serial.print("\t");
Serial.println((serialReadyTime - startupTime) / 1000);
}

jerenrich
01-03-2013, 01:19 AM
This shows how the new USB driver appears

114

PaulStoffregen
01-03-2013, 01:22 AM
Did you also happen to change the Tools > USB Type setting?

There's a known problem where Windows 7 takes a long time (several seconds) to recognize a new Keyboard+Mouse+Joystick device. I did some initial investigation and found Teensy 3.0 reboots quickly, Windows begins the USB enumeration process, but waits several seconds between receiving the initial device response and asking for more info on each interface. It appears like Teensy answers each control transfer very quickly. Investigating more throughly is on my to-do list....

It's hard to know if that's related. Maybe you could try this on both "Serial" and "Keyboard+Mouse+Joystick", and perhaps also "MIDI".

Also, please be aware the known issue is related to which device type Teensy was previously programmed, not the current setting. So when you change Tools > USB Type, the first Upload will be the same as before the change.

It's entirely possible this is some other issue? Very hard to know from so little info.

jerenrich
01-03-2013, 01:27 AM
Okay, this issue appears to have been entirely related to mistakenly changing the "Tools>Usb Type" to MIDI. I guess I had a stray mouse click somehow that accidentally did this. Sorry...and thanks!