MTP_Teensy always enumerating as Disconnected

wygonski

Member
I have been working with MTP_Teensy implemented on a Teensy 4.1 with the intent of integrating it into a datalogger. I have been trying to solve the problem of programmatically resetting the session from Windows host so as to be able to view the newly-logged files in File Explorer-like view.

Following the recommendation at https://github.com/KurtE/MTP_Teensy, I can successfully accomplish the disk content refresh in Win10 DeviceManager--Disable device followed by Enable device shows the refreshed list of files in the File Explorer-like view.

So far so good, but I want to do the disable/enable from my Win10 C# application followed by a redisplay of the files list. The PnPUtil application found on every Win10 PC is designed to do this. First I can find the MTP_Teensy device and obtain its instance id:

Code:
C:\WINDOWS\system32>pnputil /enum-devices /instanceid "USB\VID_16C0&PID_04D1&MI_01\a&12108765&1&0001"
Microsoft PnP Utility

Instance ID:                USB\VID_16C0&PID_04D1&MI_01\a&12108765&1&0001
Device Description:         Teensy
Class Name:                 WPD
Class GUID:                 {eec5ad98-8080-425f-922a-dabf3de3f69a}
Manufacturer Name:          PJRC
Status:                     Disconnected
Driver Name:                wpdmtp.inf

Then I should be able to disable the device by instance id with PnPUtil, but the command fails, apparently because the device is not connected:
Code:
C:\WINDOWS\system32>pnputil /disable-device "USB\VID_16C0&PID_04D1&MI_01\a&12108765&1&0001"
Microsoft PnP Utility

Failed to disable device:  USB\VID_16C0&PID_04D1&MI_01\a&12108765&1&0001
The device is not connected.

Of course a search reveals that this PnPUtil enable/disable command always "just works" and I cannot find any help on the "device is not connected" error.

This Disconnected status persists even when I am interacting with the device in Win10, and also when my C# app has an active connection to it. In my C# app I am using the MediaDevices NuGet package which is able to connect and interact with the Teensy MTP device.

Is there something about the MTP_Teensy implementation that fails to report the status as Connected? Perhaps I am mis-understanding what's happening here, but it would be nice if I could refresh the MTP_Teensy files list programmatically. (I can workaround by rebooting the Teensy from my host app to refresh, but I would rather not do that.)

Thanks,
John
 
MTP can disabled/enabled using the device manager, so I expect it can be done with "pnputil" a tool I was not aware of when we worked on PC-side refresh of MTP and I suggested the powershell script
 
Thanks for the reply. Searching the forum I found this powershell script (attributed to you) which works as expected:

Code:
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
    exit;
}

$a = Get-WmiObject Win32_PNPEntity | where { $_.Name -eq 'Teensy'}

echo $a.Name
$a | Disable-PnpDevice -Confirm:$false;
$a | Enable-PnpDevice -Confirm:$false;

As you pointed out the disable/enable works in the powershell script and in Device Manager, so I will try to solve my problem with using PnPUtil for this purpose.

In any event, thank you for your tremendously useful MTP implementation!
 
A related question, I can also refresh the file list using your firmware method send_DeviceResetEvent(). Is there a way to know when this event has been handled in firmware, perhaps with another method call? The goal would be to invoke the device reset, and then refresh my host-side app internal file list to show newly-added files.
I tried checking the Win10 "Created" property of mtpindex.dat, but it was not so clear that this is a viable approach. Do you have a comment or recommendation on this point?
 
Back
Top