Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to specify which teensy is programmed via its serial number? #56

Open
hmaarrfk opened this issue Jul 17, 2020 · 7 comments

Comments

@hmaarrfk
Copy link
Contributor

For use cases where we have multiple teensies connected, is it possible to specify which one we program via their serial number? usb port?

@takurx
Copy link

takurx commented Feb 11, 2021

Hi @hmaarrfk,
I also want to write to multiple teensy (same version, 3 teensy 4.1s).
When it open Teensy, it specify vid and pid.
https://github.com/PaulStoffregen/teensy_loader_cli/blob/master/teensy_loader_cli.c#L669
Teensy have same vid and pid.
I think that new function option need to specify usb port.

@hmaarrfk
Copy link
Contributor Author

You can try

#57

Only works on linux.

I did the bad thing on releasing the feature on conda forge as well

@takurx
Copy link

takurx commented Feb 12, 2021

Thank you. That's helpful for me!! I will try it.

@FiratSusan
Copy link

Greetings,
I was playing around with your changes so I can use this serial-number functionality with PlatformIO to flash my two teensy via USB only and I noticed a strange thing.

This is the output from usb-devices for my teensy:

T:  Bus=03 Lev=02 Prnt=05 Port=00 Cnt=01 Dev#=  7 Spd=480 MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=16c0 ProdID=0486 Rev=02.79
S:  Manufacturer=Teensyduino
S:  Product=Teensyduino RawHID
S:  SerialNumber=7365140
C:  #Ifs= 2 Cfg#= 1 Atr=c0 MxPwr=100mA
I:  If#= 0 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=(none)
I:  If#= 1 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid

As you see, my serial-number is 7365140.

I had issues flashing my teensy and noticed that the serial-number which gets parsed out of your code is not matching to my serial-number.

I added some prints to your code:

...
if (dev->descriptor.iSerialNumber) {
	// langid 0x0409 is English US
	r = usb_get_string(h, dev->descriptor.iSerialNumber, 0x0409, buf, 128);
	if (r < 0) {
		usb_close(h);
		continue;
	}

	// Seemsl like 16 bit wide chars are being sent
	for (i=0; i < r/2; i++){
		buf[i] = buf[i * 2];
	}
	printf("%s\n", buf);
	// The first char seems to be of value 16
	// meaning DATA LINK ESCAPE. Who knows what that means???
	read_serial_number = &buf[1];
	printf("%s\n", read_serial_number);
} else {
...

Here is the output of PlatformIO using your changes + outputs from me:

...
Configuring upload protocol...
AVAILABLE: custom, jlink, teensy-gui
CURRENT: upload_protocol = custom
Uploading .pio/build/teensy_rear/firmware.hex
Teensy Loader, Command Line, Version 2.2
Read ".pio/build/teensy_rear/firmware.hex": 16180 bytes, 0.8% usage
73651405
73651405
Sending reboot command to 7365140
...

Any idea why this happens?
Either usb-devices is not displaying the serial numbers correctly or the conversion from 16bit values to 8bit is not working right.

@hmaarrfk
Copy link
Contributor Author

do you have two teensies connected?

@FiratSusan
Copy link

FiratSusan commented May 31, 2021

In the run shown above, no.

@hmaarrfk
Copy link
Contributor Author

are you using a standard intel based computer? I've been using this for quite some time and it seems to be "working" but maybe there is a bug....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants