supplierdeeply

PC injected scripts

  • 11 Replies
  • 2369 Views
PC injected scripts
« on: 14 / November / 2013, 10:29:28 »
Advertisements
Being a newbie I'd first like to thank everybody here having done such an impressing piece of work. I've been following a lot of discussions here on the forum but not found any hints concerning the following idea. Maybe some more experienced users could evaluate the following approach

I am aware of the CHDK ptp extension. But it has several drawbacks in requiring the LibUSB driver, in de/installation and multi device programming to name just some issues ... 

My aim
Inject scripts over USB using the WPD interface, which is also in use by Windows Explorer.

Approach
WPD does not see any files in the CHDK folder, but it can read/write from/into the DCIM folder. So we could deposit a script (most easily by copying it there with the Windows Explorer per drag & drop) and have a Lua script periodically polling said DCIM-Folder, transferring any finds into the SCRIPTS Folder and starting them from there.
Scripts would have to comply with some requirements to keep the mechanism alive, but that seems not a critical point to me ...

Any suggestions and objections welcome!

Best PeterT

Re: PC injected scripts
« Reply #1 on: 14 / November / 2013, 11:16:05 »
I've been following a lot of discussions here on the forum but not found any hints concerning the following idea.

Hello and welcome !

Quote
Inject scripts over USB using the WPD interface, which is also in use by Windows Explorer.
How is that done, does Windows Explorer respond to the USB 'device connected' event ?

If you are connected to multiple cameras, can it distinguish each one ?

Quote
WPD does not see any files in the CHDK folder  but it can read/write from/into the DCIM folder.
How do the Powershots respond to WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES ?
Do they support plain text files ?

Quote
So we could deposit a script (most easily by copying it there with the Windows Explorer per drag & drop)

Are you saying that can be done right now without requiring any software ?

Quote
Scripts would have to comply with some requirements to keep the mechanism alive

Such as ?


Quote
Any suggestions and objections welcome!

Well, a friend has been working on this recently.
I will ask him if he has made any progress.


David

*

Offline reyalp

  • ******
  • 11084
Re: PC injected scripts
« Reply #2 on: 14 / November / 2013, 17:15:02 »
So we could deposit a script (most easily by copying it there with the Windows Explorer per drag & drop) and
Have you verified that your camera will actually do this?

On my a540, I can only upload a file if it has a camera recognized extension. foo.lua is rejected. foo.jpg gets uploaded and gets stored as IMG_nnnn.JPG. The camera shows "corrupted image" for the file. Presumably some other recognized file types / extensions would also work. I haven't checked what more modern cameras do.

What is the goal of this project, just uploading scripts, or doing something more complicated? If you want to control the camera while it is connected to PTP, letting it talk to regular windows PTP will probably prevent you from using record mode until you reboot. See discussion around http://chdk.setepontos.com/index.php?topic=6231.msg100661#msg100661

It's also worth noting that the cameras do have some upload support for other files, a long time ago there was a canon uploader for firmware updates that would let you upload arbitrary files by editing an INI file.

If there is a way to talk to vendor specific PTP / MTP extensions though windows API without providing your own driver, that could provide a much more flexible alternative.
Don't forget what the H stands for.

Re: PC injected scripts
« Reply #3 on: 15 / November / 2013, 22:38:04 »
Thanks for your fast reponses. My lengthy response on that got lost due to a forum timeout  >:(
So this one I'll keep short.

Quote
How is that done, does Windows Explorer respond to the USB 'device connected' event ?
If you are connected to multiple cameras, can it distinguish each one ?
Certainly, it does. Gives you a symbol for each cam, which you can open to view and copy contents. It also gives you the vendor guid in the property windows.

Quote
How do the Powershots respond to WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES ?
Please have a look at the attached screenshot. It should answer most of your (even unposed) questions. 
Since the WPD COM-objects functionality is mostly undocumented, especially when approached with managed code (C#), I currently have some problems on uploading content, while downloads with jpgs and movs (haven't testet other content types right now) work perfectly.

Quote
Have you verified that your camera will actually do this?
Gosh. You are right, my Windows 8 Explorer reports an error, when I try to do it with my A2400IS. But I remember having done it with a Windows 7 machine on some powershot type.
But does't your a540 provide enough evidence that file injection can be done in principle? I'am not so experienced with Lua right now. But if Lua can access all the storage on the device it should be able to read it bytewise and copy some "special" content into script files or interpret it some how.

What is my project?
Currently I'm running a large cam array using a uBasic script and periodically collect the data over USB via WIA. Since WIA doesn't read videos (since Vista) I'm currently reknitting my code and solution to use WPD. New possibilities give new ideas...

What is my goal?
I want to be able to update automatically either a script or at least inject parameter files, or some other interpretable stuff without the need of SD card removal or proprietary drivers.

Best PeterT


*

Offline reyalp

  • ******
  • 11084
Re: PC injected scripts
« Reply #4 on: 16 / November / 2013, 00:58:57 »
Gosh. You are right, my Windows 8 Explorer reports an error, when I try to do it with my A2400IS. But I remember having done it with a Windows 7 machine on some powershot type.
FWIW I was testing on win7.

Quote
But does't your a540 provide enough evidence that file injection can be done in principle?
On that particular camera / OS combo, it appears to work.

Having the name converted to the camera naming convention complicates things, but it's possible that you could find a pattern that gives a name which won't be confused with images or mess up the camera file listing.  This post http://chdk.setepontos.com/index.php?topic=2045.msg18862#msg18862 has some notes on how the camera treats different extensions and names, but again only for a540, modern cameras will likely behave somewhat differently.

I just did some testing with my D10, and did not find any combination of name/extension to upload by drag/dropping in explorer. Even a jpeg from the camera was not accepted.
Quote
I'am not so experienced with Lua right now. But if Lua can access all the storage on the device it should be able to read it bytewise and copy some "special" content into script files or interpret it some how.
Sure. In chdk you can list directories with the non-standard function os.listdir http://chdk.wikia.com/wiki/Lua#Differences_from_standard_lua_oslib and read and write files using the standard lua IO libraries http://www.lua.org/manual/5.1/manual.html#5.7

If the file is lua code, you can use loadfile() or dofile() directly http://www.lua.org/manual/5.1/manual.html#5.1
Don't forget what the H stands for.

Re: PC injected scripts
« Reply #5 on: 18 / November / 2013, 19:42:55 »
@reyalp: Thanks for your feedback.

Meanwhile I've verified that my code uploads to other devices like SD-Cards in USB-Adapters. But any attempts with the A2400IS produce a HRESULT: 0x80070005 (E_ACCESSDENIED)). Unless I'll find a way to unlock the folder for write access I'm stuck at this point - at least with this Cam.

Re: PC injected scripts
« Reply #6 on: 18 / November / 2013, 19:53:15 »
So why would Canon support WPD_CONTENT_TYPE_DOCUMENT if you cannot upload text files to the DCIM folder ?

Re: PC injected scripts
« Reply #7 on: 19 / November / 2013, 12:18:04 »
Quote
So why would Canon support WPD_CONTENT_TYPE_DOCUMENT if you cannot upload text files to the DCIM folder ?

It's not the question of a specific content type or CHDK running or not, it seems that this cam for some reason prohibits any file upload of any content type. Strangely enough videos recorded by this cam show up with WPD_CONTENT_TYPE_UNSPECIFIED while pictures have WPD_CONTENT_TYPE_IMAGE as expected.

It seems to me that the device is pretending to support more WPD functionality (interfaces) as it actually does.
Would it otherwise report to support WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_AND_DATA ?

My program shows that other devices reporting this command also allow for uploads.


Re: PC injected scripts
« Reply #8 on: 19 / November / 2013, 13:02:32 »
Presumably there are also undocumented Canon-specific WPD commands (that may deal with uploading files) ?

*

Offline reyalp

  • ******
  • 11084
Re: PC injected scripts
« Reply #9 on: 19 / November / 2013, 17:03:30 »
From http://msdn.microsoft.com/en-us/library/windows/desktop/hh155286%28v=vs.85%29.aspx it looks like you should be able to call MTP commands including extension commands. It's possible this would allow you to call the CHDK PTP commands directly, without using a dedicated driver. It might also be usable to call Canon extensions.

edit:
See also http://msdn.microsoft.com/en-us/library/windows/desktop/ff384848%28v=vs.85%29.aspx
Don't forget what the H stands for.

 

Related Topics