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

MTP (Media Transfer Protocol) #12

Open
caver456 opened this issue Apr 19, 2021 · 9 comments
Open

MTP (Media Transfer Protocol) #12

caver456 opened this issue Apr 19, 2021 · 9 comments

Comments

@caver456
Copy link
Contributor

This was discovered as part of #10.

Several models are now MTP and more will be MTP in the future. So: let's get it going!

Googling and searching on stackoverflow hasn't turned up any brilliant leads yet as far as making MPT part of a turnkey installable solution. There is a tool for sale that mounts up MTP with drive letters in Windows: mtpdrive.com so maybe that's a lead, but the free version looks pretty limiting and is probably not turn-key installable as part of GPSIO anyway.

The closest seems to be: https://drautb.github.io/2015/07/27/the-perfect-exchange-mtp-with-python/ but it looks like this will require some work on PyMTP - looks like it's python 2, and it's not clear if libmtp is included or not.

@caver456
Copy link
Contributor Author

mtpmount works well as a standalone executable, with some caveats.
https://github.com/hst125fan/mtpmount

dokan must be installed as prerequisite.
https://github.com/dokan-dev/dokany

Fortunately, dokan has .msi installers for both 32bit and 64bit (32bit installer cannot be used on 64bit system), and mtpmount has standalone executables (no install needed) for both 32bit and 64bit.

Just run the dokan .msi, then download the mtpmount executable, and use it as in the mtpmount readme except that the pound sign must (apparently) be double-quoted in powershell:

PS C:\Users\caver\Downloads> .\mtpmount-x64.exe list available
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.

Available Connections and Storage Media:
Connection Elements: Contains 1 storages that can be mounted
 |-- Storage E: [ID #0]
Connection My Passport: Contains 1 storages that can be mounted
 |-- Storage F: [ID #1]
Connection Alpha 200i: Contains 2 storages that can be mounted
 |-- Storage Internal Storage [ID #3]
 |-- Storage Memory Card [ID #4]
Use mount command to make one of them a windows removable drive
PS C:\Users\caver\Downloads> .\mtpmount-x64.exe mount "#3" h:
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.

Drive H:\ is now Alpha 200i\Internal Storage. Don't forget to unmount the drive (using unmount command) before disconnecting your device
PS C:\Users\caver\Downloads>

After it's mounted as a drive letter that wrapper.py will be searching for, GPSIO works normally.

After that, dismounting from the command line is interesting:

PS C:\Users\caver\Downloads> .\mtpmount-x64.exe unmount "#3"
This is mtpmount, version 19.8.0 from commit 43033d6
This program comes with NO WARRANTY. Usage only at your own risk.

Alpha 200i\Internal Storage has been unmounted successfully.
Syncing Alpha 200i. DO NOT UNPLUG THIS DEVICE YET!

the terminal pauses for about 5 seconds here

Cache OK
All content synced to Alpha 200i. You may now unplug this device.
PS C:\Users\caver\Downloads>

So if this is the correct route to pursue, here are some key considerations:

  1. find out about installing both dokan and mptdrive easily
  2. find out if 'unmount' is necessary
  3. find out if the pause during unmount is necessary

@caver456
Copy link
Contributor Author

If a stale device number is in the table returned by 'list available', then a subsequent mount command on that id will return something like this:

Cannot establish connection to device. Is 5 really connected (and spelled correctly)?

@caver456
Copy link
Contributor Author

If an MTP device is already mounted (such as on subsequent call to the mount command), the 'list available' table will return something this:

|-- Storage Internal Storage [ID #3] (is mounted)

So, don't try to mount it again.

@caver456
Copy link
Contributor Author

caver456 commented Apr 28, 2021

Tried a hot-unplug; the device seems fine (at first glance) but Windows file navigator still has an entry for that drive letter - trying to eject it raises an error, but, the file system appears to still be there, fully cached? You can browse the j: drive in the file navigator and even edit a file (though I didn't try to save it).

Then, I ran 'mtpmount unmount j:' - subsequent attempts to explore the folder in the windows file navigator show this popup:

image

The next time you plug in a MTP device, the drive list is refreshed i.e. j: is removed from the list. Would be interesting to see if also gets refreshed after plugging in a Mass Storage device.

@caver456
Copy link
Contributor Author

Ok - so the mounting seems to go well (not sure if the above issues will be a real problem - it may be just as well to do the unmount command before returning from wrapper.py).

BUT - viewing one of the gpx files on the mounted drive letter - it is all just binary goop - not xml. Looks like there might be an issue with the mount encoding or something like that...

@caver456
Copy link
Contributor Author

The binary goop issue was resolved by a restart. wrapper.py was able to proceed, and viewing a gpx file from the mounted drive, it was xml as expected.

We could just call this a fluke, but, during research I saw a note somewhere that it's probably a good idea to restart after installing anything that futzes with the file system.

So,

  1. probably best to require a restart after the install of dokany, and
  2. need to decide how to deal with this problem.

For the immediate term, you get the Unexpected disconnect error in the browser, which means the operator should do file browser transfer anyway, but, something more useful might be helpful (like a message that says 'the drive mounting process did not work - try restarting your system' or such. If it happens repeatedly, well, that's another issue...

@caver456
Copy link
Contributor Author

Probably a bug in dokany or mtpmount:

  1. mount the drive
  2. observe that in this case there were 5 gpx files in Garmin/GPX (plus Current.gpx in Garmin/GPX/Current)
  3. delete the five files
  4. unmount
  5. unplug
  6. start the gps, observe that in fact all the waypoints and routes are gone
  7. plug it back in
  8. mtpmount
  9. guess what: the files that were previously deleted still show up in the mounted drive's Garmin/GPX directory! And apparently GPSIO tries to read them and dies because they have binary goop. Huh.

@caver456
Copy link
Contributor Author

the same ghost files appear even if you mount it as a different drive letter. The ghost files have a file size (2kb or so) but when you edit them in vi they are empty. So it seems like a decent workaround may be to just check every file to make sure it starts with and ends with otherwise move on, BUT, the files that do appear when navigating to the MTP drive in Windows file browser, do NOT appear (or are empty) on the mounted drive. That's a problem.

@caver456
Copy link
Contributor Author

Not sure if this stackoverflow question has been linked to this issue yet:

https://stackoverflow.com/questions/64910317

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

No branches or pull requests

1 participant