GSAK (Geocaching Swiss Army Knife)
Contents - Index

Mtp (function)

Mtp(sAction,[sData1],[sData3],[sData3) : string
 
Macro function to communicate with MTP devices (Garmin Monterra, for example)

sAction is the required action to perform and may need up to 3 data parameters

GetDevices - Returns a CSV list of USB connected devices that support MTP commands. No data parameters are required. You can use the macro function Csv() to read this data and pull out individual entries.

For example here is a list of my attached devices which include a HTC phone (mtp device), Nexus 7 (mtp device), Garmin Oregon 650 (mass storage), SanDisk thumb drive (mass storage)



Macro code to produce this list:
 

$data = mtp("getdevices")
$Data =  "Friendly name,Description,Manufacturer,Drive,DeviceId" + $_Crlf + $data
$Data = replace(";","|",$data)
$data = replace(",",";",$data)
$html = sqltohtml($data,"Show connected devices via MTP","y")


Dir - Returns a csv List of files on the device (Currently just FileName,ObjectId,Type). sData1 must be the device ID to list and sData2 must be the folder to list. From what I can gather, on all MTP devices the root folder for internal memory is "S10001" and for any attached SD card it is "S20001", For example the code to list the contents of the root folder (Internal memory) of my HTC phone:
 

$data = mtp("getdevices")
$rows = Val(CsvGet($data,"rows"))
$x = 0
Repeat
$x = $x + 1
$name = CsvGet("*","$x,2")
if equal($name,"HTC One SV")
   $DevId = CsvGet("*","$x,5")
   BreakRepeat
endif
Until $x = $rows
$data = mtp("Dir",$devid,"s10001")
$rows = Val(CsvGet($data,"rows"))
$x = 0
$data = "Name;ObjectId;Type" + $_crlf
Repeat
$x = $x + 1
$data = $data + CsvGet("*","$x,1") + ";" + CsvGet("*","$x,2") + ";" + CsvGet("*","$x,3") + $_Crlf
Until $x = $rows
$html = sqltohtml($data,"Dir of HTC (Internal memory)","y")

 
Which produces this list:



FileExists - sData1 must be the device ID and sData2 must be the fully qualified path to the file (For example "s10001\Movies\Airplane.mp4"). The return value is "True" or "False"

FolderExists - sData1 must be the device ID and sData2 must be the fully qualified path to the folder, without the trailing backslash (For example"s10001\Movies"). The return value is "True" or "False"

DeleteFile - sData1 must be the device ID and sData2 must be the fully qualified path to the file (For example"s10001\Garmin\gpx\test.gpx"). 

GetFile - Fetch a file from the device. sData1 must be the device ID. sData2 must be the fully qualified path to the file (For example"s10001\Garmin\Geocache_Visits.txt").

PutFile - Save a file to the device. sData1 must be the device ID. sData2 must be the fully qualified path to the file (For example"c:\temp\test.gpx"). sData3 must be the fully qualified path where the file will be saved (example "s10001\Garmin\gpx\test.gpx")

CreateFolder - Create a folder on the device. sData1 must be the device ID. sData2 must be the fully qualified path to the folder (for example "s10001\NewFolder"

If there is an error performing the action then the first 7 characters of the return string will contain "*Error*"
Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact