is it possible to download images while a script is running? - page 6 - General Discussion and Assistance - CHDK Forum supplierdeeply

is it possible to download images while a script is running?

  • 63 Replies
  • 10823 Views
*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: is it possible to download images while a script is running?
« Reply #50 on: 05 / December / 2021, 15:00:14 »
Advertisements
Quote from: reyalp link=topic=14446.msg147432#msg147432
I'm not clear what approach you're pursing at this point, but I again, I highly recommend not connecting USB (or making the camera think it's connected with force_usb_active) when the camera is in rec.
i'm now trying to figure out what code i should add to my script, so i can connect the usb (maybe leave it connected) and keep it connected while the cam goes back and/or stays in record mode and resumes shooting.
if it stays connected i need some flag after each shot, so the pc can detect when it's safe to start downloading.
or opens to reconnect. this way i hope i can prevent possible data corruption or other trouble because the canon software is busy.
Quote
It's also likely you need some delay between force_usb_present and switch_mode_usb. On elph130, 100ms seems to be plenty going from play mode, while no delay failed to switch.
i'll try a delay
Quote
If you are allowing the camera to auto-switch to play due to sensing USB, that would need additional time.
if at all possible, i'd like to prevent it switching to play as much as possible.
that is the code i am looking for.
My first try went to play after each shot for 10 seconds and i think that is not a long term solution. i did that with usb_remote(121 0/1)
I see this as a fair chance the cam will fail quickly if it switches to play a 100 times a day.
« Last Edit: 05 / December / 2021, 15:14:04 by Mlapse »
frustration is a key ingredient in progress

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: is it possible to download images while a script is running?
« Reply #51 on: 05 / December / 2021, 15:23:46 »
my first thought is that i should create a window of a few hours a day in the cam script that will enable connection and download.
outside those hours this connection can be blocked. possibly making (re)connection of usb safe outside the download hours.
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14117
Re: is it possible to download images while a script is running?
« Reply #52 on: 05 / December / 2021, 15:35:13 »
i'm now trying to figure out what code i should add to my script, so i can connect the usb (maybe leave it connected) and keep it connected while the cam goes back and/or stays in record mode and resumes shooting.
if it stays connected i need some flag after each shot, so the pc can detect when it's safe to start downloading.
You could use the usb message interface for this. You'd probably want a handshake, like the PC sends something indicating "ready to start downloading" and waits for a reply indicating "ok to start now", which the camera sends after the shot is complete. The PC could also send a message indicating the download is done.

Note that messages from the camera are queued until a PTP client fetches them, so if you blindly use write_usb_msg when chdkptp isn't actively checking for messages, the queue would fill up (it has 15 slots) and then when chdkptp check for messages, it would get everything in the queue. Similarly, messages from the PC are queued in the PTP task until the script uses read_usb_msg()

Quote
Quote
If you are allowing the camera to auto-switch to play due to sensing USB, that would need additional time.
if at all possible, i'd like to prevent it switching to play as much as possible.
that is the code i am looking for.
Again, what I'm suggesting is avoiding the Canon firmware triggered auto-switch. If you want to have the camera essentially always in rec, you should use  force_usb_present  at startup, before switching to rec (edit: with switch_mode_usb). If your camera boots into rec, that's a bug in the port, but in that case, you'd want to wait for it to be fully booted to rec, switch to play, force_usb_present, and then switch back to rec. This only needs to be done once per boot.

Quote
I see this as a fair chance the cam will fail quickly if it switches to play a 100 times a day.
Yes, it seems preferable to avoid that.

my first thought is that i should create a window of a few hours a day in the cam script that will enable connection and download.
outside those hours this connection can be blocked. possibly making (re)connection of usb safe outside the download hours.
I not clear how you intend to combine blocking USB and using force_usb_active. I see these as mutually exclusive approaches:
1) The camera script blocks USB until it's ready to accept downloads, then switches to play, unblocks USB, waits for download to complete. The PC detects this because it sees the camera device show up.
2) The script makes the camera think USB is always present, allowing it to stay in rec mode when USB shows up for real.
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: is it possible to download images while a script is running?
« Reply #53 on: 05 / December / 2021, 15:50:42 »
I not clear how you intend to combine blocking USB and using force_usb_active. I see these as mutually exclusive approaches:
1) The camera script blocks USB until it's ready to accept downloads, then switches to play, unblocks USB, waits for download to complete. The PC detects this because it sees the camera device show up.
2) The script makes the camera think USB is always present, allowing it to stay in rec mode when USB shows up for real.
will try to implement what you wrote tomorrow.

as for mutually exclusive, timesharing does mean you do not use it at the same moment :)
with what you wrote, something in this line might do it i think:
1)The camera script blocks USB and moves or stays in record  until set time
2)At set time, the camera goes to play, unblocks, sets usb always present, moves back to record when pc is connected or when wait time is exceeded (no pc active)
3)the pc download should be always done before end of the window and triggers a reboot.
4)after the reboot/at set time the cam is or moves to play, usb is blocked again and goes back to record
5) the pc can now wait until the next day when the window opens again or be powered down or unplugged safely.

btw most computers have standard 5v always active. it can be disabled in bios if you do not want 5v when powered down.
« Last Edit: 05 / December / 2021, 16:58:25 by Mlapse »
frustration is a key ingredient in progress


*

Offline reyalp

  • ******
  • 14117
Re: is it possible to download images while a script is running?
« Reply #54 on: 05 / December / 2021, 17:35:08 »
as for mutually exclusive, timesharing does mean you do not use it at the same moment :)
with what you wrote, something in this line might do it i think:
1)The camera script blocks USB and moves or stays in record  until set time
2)At set time, the camera goes to play, unblocks, sets usb always present, moves back to record when pc is connected or when wait time is exceeded (no pc active)
I still don't understand why you'd implement #1 if you are also implementing #2. It just seems like an extra state to test and debug. In your scenario, #2 has to work whether the PC is actually active or not (otherwise you wouldn't need force_usb_present), so why not stay in that state all the time?
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: is it possible to download images while a script is running?
« Reply #55 on: 05 / December / 2021, 17:43:39 »
i am afraid that a disconnection of the 5v when in #2 would be a risk.... since you stated i should not plug in the usb when in record mode.
but your reaction gives away that i worry too much ;)
i will only build #2 in the script....saves on coding :)
« Last Edit: 05 / December / 2021, 17:47:03 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14117
Re: is it possible to download images while a script is running?
« Reply #56 on: 05 / December / 2021, 22:20:49 »
i am afraid that a disconnection of the 5v when in #2 would be a risk....
The whole point of #2 is that it makes the Canon firmware think +5v is there when it's not, so it doesn't notice what the actual +5v is doing. (note CHDK can still see the real state with get_usb_power)
Quote
since you stated i should not plug in the usb when in record mode.
Again, the reason I keep saying that is because of how the Canon firmware responds when it notices +5v suddenly appearing. If it thinks +5v never went away, then it won't notice it suddenly appearing.

Now it's quite possible some other problem will show up, but the only way to find out is to try to implement it.

FWIW, I used the attached script for some quick testing on elph130. Using it to call usb_force_active and switch to rec without a USB cable, then plugging in the cable and connecting with chdkptp seems to work fine.
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: is it possible to download images while a script is running?
« Reply #57 on: 06 / December / 2021, 03:22:49 »
FWIW, I used the attached script for some quick testing on elph130. Using it to call usb_force_active and switch to rec without a USB cable, then plugging in the cable and connecting with chdkptp seems to work fine.
i must have misunderstood you.
-tested the script and it works as long as the cam is in play without the lens extended.
-if the cam is in record, moves to play (at that point the lens is still extended) and then start the script, the cam stays in play and finishes the script.
so i should not forget the lens retract before triggering this loop....it seems this might be why my first attempts all led to failure (both S95 and S110 do this)
-when it is in record (i know shouldn't do that, but want to know anyway) it disables lcd, keeps backlight on and the battery has to be pulled.

i did not find set_lens_retract(0) or something to add when the lens is extended like activate_sensor(). is there a way to do either?
because this might pose a small problem, since i start the cam in record to position it before i start the shoot.
after reboot it starts in play, i guess the script start and puts the cam in shoot, so that might give enough time to make it work. if the lens extends before the script starts setting will fail.

setting lens retract in CF to 0 seconds so it moves the lens in when going to play results also in failure: this time the lens extends, so that part works coming from record. but it immediately retracts and the script finishes in play.
it appears i need the lens retract set at 1 minute to make it work, but the lens should be retracted before it can work.
« Last Edit: 06 / December / 2021, 11:47:24 by Mlapse »
frustration is a key ingredient in progress


*

Offline Mlapse

  • *****
  • 584
  • S95 S110
Re: is it possible to download images while a script is running?
« Reply #58 on: 06 / December / 2021, 11:47:56 »
new usbtest works, but doesn't in SUIx...first sleep there has to be ~70 seconds
« Last Edit: 06 / December / 2021, 11:53:29 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14117
Re: is it possible to download images while a script is running?
« Reply #59 on: 06 / December / 2021, 12:09:38 »
-tested the script and it works as long as the cam is in play without the lens extended.
-if the cam is in record, moves to play (at that point the lens is still extended) and then start the script, the cam stays in play and finishes the script.
I feel like we're talking past each other. Again, the whole point of using force_usb_active is to make the camera think there USB was always connected, so it never sees a new connection in rec. As I keep saying, if the camera detects a new USB connection (whether real or usb_force_active) while in rec, you get problems.

Boot the camera in play, call usb_force_active, then switch to rec, using switch_mode_usb. Any subsequent play/rec transitions should also use switch_mode_usb.

Quote
i did not find set_lens_retract(0) or something to add when the lens is extended like activate_sensor(). is there a way to do either?
There is nothing like this in CHDK. There has been some work on preventing lens retraction https://chdk.setepontos.com/index.php?topic=13737.0

(Edit: actually, I vaguely remember there being some eventprocs to retract the lens, search might turn something up)

That said, I don't think lens position should be an issue if you follow the advice above.

Quote
because this might pose a small problem, since i start the cam in record to position it before i start the shoot.
Again, if you are going to use the force_usb_active approach, you should not start the cam in rec. You should use something like the script I posted to switch to rec. If you need to do things manually on the camera, you can use a standalone script instead / in addition to integrating it in your main script.

Quote
new usbtest works, but doesn't in SUIx...first sleep there has to be ~70 seconds
What makes it need to be 70 seconds?
« Last Edit: 06 / December / 2021, 12:12:05 by reyalp »
Don't forget what the H stands for.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal