PTP and USB remote simultaneously with USB_force_active() - page 2 - Script Writing - CHDK Forum

PTP and USB remote simultaneously with USB_force_active()

  • 24 Replies
  • 13639 Views
Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #10 on: 22 / May / 2015, 08:27:42 »
Advertisements
Do we know they aren't connected to the +5 in any way? I know next to nothing about the USB at the electrical level.
I've looked into these circuiits quite a bit (for CHDK USB remote reasons, for USB battery charger design reasons, and at least one Arduino clone project) but am not an expert.  However, from what I have seen,  the data lines are not typically connected to +5V in any functional way.  Of course there is always an electrical path but it's high impedance and not necessary or used for USB functionality.

I once read about a USB configuration descriptor (bMaxPower --> Maximum Power Consumption in 2mA units). Could that infer the host controller monitors/limits the current supplied? (and if 0 power monitored, cause it to stop data supply)
USB ports on most PC computers can be configured in software to limit the amount of current they will source.  This allows them to meet the USB spec but also charge devices that need more current.   That's what the USB configuration descriptor you mentioned refers to.  I do not believe there is any minimum current draw specified so there is no official "disconnected" state based on current draw.  While it's technically possible for a USB port to be designed to monitor the +5V current draw and disconnect if it falls,  it just does not seem likely.

So I retested three of my cameras (a560, G10, a1200) using 1.4.0.   I have a toggle switch installed in the +5V line of the USB cable I use between my PC and cameras for CHDK development.   

The following sequence works correctly on all three cameras with no disconnections. 

Code: [Select]
$ run -i
___> c
connected: Canon PowerShot A1200, max packet size 512
con> =usb_force_active(1)          -- lock USB communications on (+5V line changes do not disconnect USB)
con 1> =set_config_value(121,1)    -- enable USB switch operations (switch & controller mode already setup)
con 2> =switch_mode_usb(1)         -- switch camera to shooting mode
con 3> =shoot()                    -- take a picture
con 4>
After the usb_force_active(1) is issued,  I can toggle the  +5V inline switch to my heart's content and the connection is not affected.  Once the set_config_value(121,1) is done,  toggling the +5V line causes the camera to take a picture (as expected).  The chdkptp shoot() command also causes a picture to be taken.

So unless Josh P has a unique PC that detects current changes on the +5V line,  it seems something else must be wrong. 
  • A bug in the A2500 port  ? Wrong USB bit used in mmio?  (this seems unlikely looking at the A2500 code ).
  • The A2500 USB hardware is different from all my cameras and it kills USB  communications on the camera side when the +5V goes away?
  • Josh P's USB cable configuration does not just open the +5V line? Or opens the wrong wire entirely ? 
  • Something else we are assuming but Josh P is not actually doing?

Given that things work properly on all of my cameras, I'm out of other ideas.

 
« Last Edit: 22 / May / 2015, 08:57:32 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #11 on: 22 / May / 2015, 15:06:31 »
Last night I tried it with version 1.4 and the behavior was the same.

The consensus seems to be that it is not a problem with the camera, and I agree with that. The camera seems to be acting exactly as it should. That leaves the cable and the computer.

When I turned off the switch in the 5V line the camera was connecting to and disconnecting from the computer repeatedly (about every 5 seconds). Each time I reconnected over PTP I had about enough time for a command or two and it would disconnect from the computer again. So the camera and computer are capable of communicating when the 5V line is out.

This code that Waterwingz posted:
Code: [Select]
$ run -i
___> c connected: Canon PowerShot A1200, max packet size 512
con> =usb_force_active(1)          -- lock USB communications on (+5V line changes do not disconnect USB)
con 1> =set_config_value(121,1)    -- enable USB switch operations (switch & controller mode already setup)
con 2> =switch_mode_usb(1)         -- switch camera to shooting mode
con 3> =shoot()                    -- take a picture
con 4>
is what I'm doing, except that I'm using the menu to activate the USB remote mode. I need to figure out the right config_value number for the USB remote in propset6.

The switch in the USB cable is in the red wire.

I though it might be possible that the connection in one of the data lines is intermittent. But then it would be very odd for them to be intermittent only when the 5V line is off and fine otherwise.

I like the idea of a powered hub, I'm going to order one of those and try that.

Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #12 on: 22 / May / 2015, 15:12:47 »
From this website
http://superuser.com/questions/701585/disconnecting-a-usb-device-without-unplugging-it

Someone says:
Quote
the USB upstream (host or hub) recognize a connected device by a pull-up resistor connected by the device to one of the data lines. The device recognizes an active upstream by the presence of the 5V supply.

*

Offline reyalp

  • ******
  • 14113
Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #13 on: 22 / May / 2015, 15:56:58 »
However, from what I have seen,  the data lines are not typically connected to +5V in any functional way.  Of course there is always an electrical path but it's high impedance and not necessary or used for USB functionality.
It also seems conceivable that the USB chip on the camera could do something on the other lines when the +5 goes away.

Quote
A bug in the A2500 port  ? Wrong USB bit used in mmio?  (this seems unlikely looking at the A2500 code ).
If this was the case, then it seems like USB remote shouldn't work at all. It's the same bit.

Quote
The A2500 USB hardware is different from all my cameras and it kills USB  communications on the camera side when the +5V goes away?
Conceivable, but seems unlikely considering the range of generations your cameras span, and the probable similarity of the A1200.

Quote
Josh P's USB cable configuration does not just open the +5V line? Or opens the wrong wire entirely ?
Definitely worth double checking. Could a noisy switch affect the other lines enough for the PC to think there's an error?

Out of curiosity, what OSes did you do your testing on?
Don't forget what the H stands for.


*

Offline reyalp

  • ******
  • 14113
Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #14 on: 22 / May / 2015, 15:59:00 »
is what I'm doing, except that I'm using the menu to activate the USB remote mode. I need to figure out the right config_value number for the USB remote in propset6.
Note config numbers are defined by CHDK for the CHDK config file, so they don't vary between propsets.
Don't forget what the H stands for.

Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #15 on: 22 / May / 2015, 18:33:46 »
Out of curiosity, what OSes did you do your testing on?
Both Linux and Win7.

I suppose I could load chdkptp on a couple different computers and try that too.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14113
Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #16 on: 22 / May / 2015, 22:16:07 »
I suppose I could load chdkptp on a couple different computers and try that too.
I guess it's possible different host adapters could behave differently, but it seems like a long shot. Probably not worth spending much time on.
Don't forget what the H stands for.

Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #17 on: 22 / May / 2015, 22:23:45 »
The switch in the USB cable is in the red wire.
One long shot is that the red wire in your cable is not actually the +5V wire.  Most cables are done that way but there is no spec that requires it and there are millions of those cables made every year.  It's quite possible one or more vender have a red/green color blind employee building cables. As long as they get the pin-to-pin connections right, the cable will work and nobody will be any wiser.

You would not be getting reliable communications at all when the switch is open if it's actually the D+ or D- wire that has the switch in it.   

But if it's the ground wire you are switching then the flaky communications like you are seeing when the switch is open are quite possible.

A little probing with a DVM will soon tell the story if there is a wire swap at work.
« Last Edit: 22 / May / 2015, 22:26:02 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16


Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #18 on: 23 / May / 2015, 13:54:05 »
I get 5V between the black and red wires. I also remember when I put the switch in that the red and black wire were connected to the outer contacts of the USB plug, which would be correct.

I was testing last night, and had no problems at all! I couldn't figure out what was different, but then I realized I was using the battery. All the problems were happening when I was using external power plugged into the wall. I'm not sure why tha would cause a problem.

I tested the contacts on the external power and got 4.42V. A new and fully charged battery was 4.16V.

Tonight I'm going to spend some time making sure that was the only difference.

Re: PTP and USB remote simultaneously with USB_force_active()
« Reply #19 on: 23 / May / 2015, 15:39:59 »
I get 5V between the black and red wires.
Just to be sure - is the red positive & the black negative?

Quote
All the problems were happening when I was using external power plugged into the wall. I'm not sure why that would cause a problem.
What kind of an "external power supply"?
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal