From: Paulo Teotonio Sobrinho <teotonio@fm...> - 2005-12-05 18:36:15
I also got the same kind of problem reported on this list when trying to
use ptpcam (it comes with libptp) and iRiver T10. It was clear that ptpcam
was not doing all we need, so I decided to write my on version of ptpcam
in order to learn about libptp. I'm not comfortable with C (or any other
language as a matter of fact) but I know a little bit of Python, so I used
Swig to get some of the functions and structures defined in ptp.h and
ptpcam.h wrapped into a python module.
I have libptp2 1.1.0, libusb 0.1.0, Python 2.4.1, swig 1.3 and
After playing with my little module inside a python shell, I came to some
conclusions about the problem with libptp and found a simple workaround.
1)There has to be a call to function ptp_opensession (libptp) as one of
the steps to iniciate communication. After we finish whatever we want to
do with the device, we have to call ptp_closesession. One problem with
ptpcam is that ptp_closesessio my not be called (for example if one kills
the program before it ends)
2)Suppose that in a previous session, there was no call to
ptp_closesession. Then when we iniciate a communication, ptp_opensession
sends an open session request (using myusb_bulk_write in myusb.c). The
function myusb_bulk_read is supposed to get an answer form the device but
gives it up after USB_TIMEOUT=4 seconds. Then ptp_opensession returns an
This is an expected behavior, I think. However:
3)the same problem described in 2) also happens if in a previous session
one deletes or uploads a file or simple creates a new directory in the
device's memory. In this case, it is not enough to nicely close the
session with ptp_closesession. All other actions in the previous session,
like listing files, device properties, etc, seem to cause no problem.
4) In my python session, if ptp_opensession returns PTP_ERROR_IO, I just
call ptp_opensession again and again till it returns PTP_RC_OK or
PTP_RC_SessionAlreadyOpened. In my experience, I did not have to call
ptp_opensession more than 3 times. After this point, all operations work
5) Suppose that my previous session involved some file upload or that I
forgot to call ptp_closesession. Disconnecting the usb cable and
reconnecting it also helps.
The functions I have defined using my python module are enough to list,
delete and upload files. Before that, I was not able to use my T10 except
as a FM radio. It was very frustrating. I'll never buy any iRiver product
At this point my code has many problems (badly documented, obscure
variable names, some comments are in Portuguese, small changes to ptp.c
that I don't remember, and much more) and my not be useful for others. I'm
not sure exactly how I used swig and got the python module. It was a
painful try and error processes (remember: I'm not comfortable with C).
I'd like to clean up the mess at least a little before sharing the code
but have no time at the moment. However, if any of you would like to try
it, let me now.
Conclusion: It is possible to use libptp to interface with T10 (probable
T30 also), but we still have to find out what causes the usb timeout.