Auto find Teensy from COM port list

Status
Not open for further replies.

Chevelle

Active member
I am using these danged things as fast as I can come up with ideas, and that is pretty fast. I love 'em. In almost all of my projects, the Teensy is the microcontroller mounted on a custom PCB that has all the rest of the functional hardware I need. (It is so much faster than mucking about trying to get a STI (or whatever) device on there and then programming it with some other editor. I use VisualStudio for both the Teensy code and the higher level code.)

So I almost always have to have the higher level code find the port that the Teensy is on. The easiest way is to look at the long description that is part of each com port until it finds the one with the string "Teensy" in it. Works great except that not all computers provide that in the name. My development computer does, i.e. "Teensy USB Serial (COM9)" but my laptop does not. "Universal Serial Port (COM5)" They are both running Windows 10.

That means that I can't rely on this method. The next best option that I have used is to create a "WhosThere" function in the Teensy. When it gets a "WhosThere" request on the serial port, it response with some secret identity string that is used for just this application. (That way, I can have multiple Teensy-driven boards in the same system.)

In some of my applications I have used a prefix and suffix for each serial transmission from the Teensy, such as "ABC>" and "<XYZ". The higher level code tests each incoming string for the prefix and suffix. This guarantees that the code has receive the entire string. (This hasn't generally been necessary. Sort of a belts and suspenders thing.

Just asking if any of you might have a nicer way to do this.

Thanks.
 
This of course depends on the language you are using on the PC.

In case of c#, you can have a look at TeensySharp https://github.com/luni64/TeensySharp. It finds the ComPorts and serial numbers of the Teensies on the USB bus. It also notifies you if a new one is attached or removed. Additionally, you can use it to download firmware from your user applications.

If you are using c/c++ the TyCommander code from Koromix is a good starting point https://github.com/Koromix/tytools.
 
I'll look into those options but I wondering how they would work if Windows doesn't even list the Teensies in the com port list. I'll check it out. Thanks.
 
TeensySharp queries the WMI database (see https://en.wikipedia.org/wiki/Windows_Management_Instrumentation) to get the relevant information. Programming is done through the HID interface.
TyCommander is directly using USB low level access to find out about the connected boards.

At the end of the day all the relevant information is available through the USB descriptors, depends on the programming language how to access it.
 
Status
Not open for further replies.
Back
Top