How does the Arduino IDE detect on which serial Port the Teensy is attached

Status
Not open for further replies.

Olovskos

Member
Hi @ all,

when I connect my Teensy 3.1 in serial Mode to the PC, the Arduino IDE show under "Port" -> "COM7 (Teensy). How is the Arduino IDE capable of detecting the correct Port?

I want to write my own Windows exe that behaves like a terminal program for example like putty but I want to detect automatically which Port Number the Teensy was asigned to.

Thanks in Advance
 
In case you are using c# for your windows application you can use TeensySharp https://github.com/luni64/TeensySharp for finding out the port numbers of all connected Teensies.

Here a snippet from the examples

Code:
var Watcher = new TeensyWatcher();

Console.WriteLine("Currently the following Teensies are connected:");
foreach (var Teensy in Watcher.ConnectedDevices)
{
  if (Teensy.Type == USB_Device.type.UsbSerial)
  {
      Console.WriteLine("USBSerial: Serialnumber {0}, on {1}", Teensy.Serialnumber, Teensy.Port);
  }
  else 
  {
      Console.WriteLine("HalfKay: Serialnumber {0}", Teensy.Serialnumber);
  }
}

You can also watch the bus in the background and get a notification if Teensies are connected / disconnected.
 
Thank you for your answers, I will dig into the code later, I think the C# code will be pretty straight forward but I think I will convert it to Java because Java it is Platform Independent :)

I just glanced through the code and it seems like the program is just looking for the correct PID/VID. The resulting keyword "Teensy" in "COM7 (Teensy)" is determined intern by the Arduino IDE by the PID/VID or is it the string descriptor of the USB config of the Teensy?
 
No matter which language you use, for Windows it always involves Microsoft's oh-so-painful setup API, sometimes even with a bit of configuration manager thrown in. Best if you can reuse code someone else already suffered that setup API pain.
 
I just glanced through the code and it seems like the program is just looking for the correct PID/VID. The resulting keyword "Teensy" in "COM7 (Teensy)" is determined intern by the Arduino IDE by the PID/VID or is it the string descriptor of the USB config of the Teensy?

Yes, Arduino's serial discovery manager is just looking at the VID/PID numbers. For the text, it's matching them against these lines from boards.txt:

Code:
teensy31.vid.0=0x16C0
teensy31.vid.1=0x16C0
teensy31.vid.2=0x16C0
teensy31.vid.3=0x16C0
teensy31.vid.4=0x16C0
teensy31.pid.0=0x0483
teensy31.pid.1=0x0487
teensy31.pid.2=0x0489
teensy31.pid.3=0x048A
teensy31.pid.4=0x0476

To actually trace this connectivity you'd probably spend days unraveling the complex Arduino prefs system and the numerous (and perhaps extraneous) classes the Arduino devs have built in the last few years. I don't recommend putting your time into that, unless you're really seriously wanting to become a regular Arduino contributor!

These's also a small (and perhaps ugly) hack Teensyduino patches into the IDE code for SerialBoardsLister.

https://github.com/PaulStoffregen/A...8cb#diff-27be716b7072079ddd6568079daa9b36R155

Which is the reason you see "(Teensy)" in the menu, rather than "(Teensy 3.2)". I'm definitely not above dirty little hacks if they improve end user experience...
 
I don't have the details handy, but the Python serial library (serialport?) also gives you access to this information and is cross platform.
 
Status
Not open for further replies.
Back
Top