Jump to content

My first Script


 Share

Recommended Posts

Hi. The following is my first script. It took a couple of hours digging in the help files to find the right functions to use. I had my fill of basic back in the 70's so it was fun to get back into some simple programming to do stuff we could only dream of. What have I done? - I have successfully written the core of a camera automation program.

It activates a picture capture program, waits while the data is downloaded to the controlling PC then turns the camera off until the next activation. Simple, but very cool.

There may be some redundancy in some of the lines but it works and I can trim fat out later.

The help files and forum are a great asset. Thanks, Alex 1759

Run("C:\Program Files\Canon\CameraWindow\RemoteCaptureDC\RemoteCaptureDC.exe")

WinWaitActive("RemoteCapture DC")

WinActive("RemoteCapture DC")

ControlEnable("RemoteCapture DC", "", "[iD: 1011]")

ControlClick("RemoteCapture DC", "", "[iD: 1011]")

ProcessWait("RemoteCapture DC", 10)

WinClose("RemoteCapture DC")

Link to comment
Share on other sites

Hi. The following is my first script. It took a couple of hours digging in the help files to find the right functions to use. I had my fill of basic back in the 70's so it was fun to get back into some simple programming to do stuff we could only dream of. What have I done? - I have successfully written the core of a camera automation program.

It activates a picture capture program, waits while the data is downloaded to the controlling PC then turns the camera off until the next activation. Simple, but very cool.

There may be some redundancy in some of the lines but it works and I can trim fat out later.

The help files and forum are a great asset. Thanks, Alex 1759

Run("C:\Program Files\Canon\CameraWindow\RemoteCaptureDC\RemoteCaptureDC.exe")

WinWaitActive("RemoteCapture DC")

WinActive("RemoteCapture DC")

ControlEnable("RemoteCapture DC", "", "[iD: 1011]")

ControlClick("RemoteCapture DC", "", "[iD: 1011]")

ProcessWait("RemoteCapture DC", 10)

WinClose("RemoteCapture DC")

Welcome to the forum.

You might want to change ControlEnable to ControlFocus. Using ControlEnable can cause problems if the program was not ready for that control to be enabled. Also, your ProcessWait line seems odd, but if it works...... :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

The suggestions are great, thanks Plato. I will follow up on them and see if I can work out some of the whys. I am sure there are many "odd" things to sort out, all part of the learning curve and coming to grips with a new set of syntax and function. So much power and no real sence of what it could do, yet. :)

Link to comment
Share on other sites

Hi Plato

I commented out each line in turn until the process failed, the following lines seem to be needed. My approach to something not working, when trying to follow the rules, is to add lines that might help from what I can find in the in examples and then trim out what might be redundant until I have a functioning program. Pretty can come later as long as I have not made spaghetti. I had added the WinActive and ControlEnable as I did not know where the process was failing (because I have not yet worked out how to capture the "Return Value" yet). It seems the key was adding the ProcessWait. It works without WinActive and ControlEnable but not without ProcessWait. Your comment about ProcessWait is interesting and I may have to look into it more deeply. Thanks again Alex.Posted Image

"ProcessWait" version:

Run("C:\Program Files\Canon\CameraWindow\RemoteCaptureDC\RemoteCaptureDC.exe") ; opens RC and actives camera lens

WinWaitActive("RemoteCapture DC") ; waits till RC is active

ControlClick("RemoteCapture DC", "", "[iD: 1011]") ; operates "Release Button"

ProcessWait("RemoteCapture DC", 10) ; waits ten seconds while photo is down loaded to hard drive

WinClose("RemoteCapture DC") ; closes RC, closes camera lens

Link to comment
Share on other sites

Your ProcessWait line is probably just timing out... so it is nothing more than a 10 second sleep:

Sleep(10000)

Normally, the paramater fed to a ProcessWait line of code would the process name.

From the help file under ProcessWait:

Remarks

Process names are executables without the full path, e.g., "notepad.exe" or "winword.exe"

Your ProcessWait line looks odd because there is no ".exe" extension.

Also from the help file under ProcessWait:

Pauses script execution until a given process exists.

The info above is what ProcesWait does

Your comment info from your code...

; waits ten seconds while photo is down loaded to hard drive

...seems to indicate that you think that ProcessWait waits for some process to complete.

> ...because I have not yet worked out how to capture the "Return Value" yet...

$ReturnValue = ProcessWait("RemoteCapture DC", 10)

MsgBox(0, '"$ReturnValue equals...", $ReturnValue)

It is best not to reply on Sleep lines of code. A fluctuation in CPU loading might cause your script to fail. It is better to look for some word(s) that are unique to the window shown once the photo has completed downloading to the HDD.

Use the AutoIt Window Info tool to see what text in the window of interest AutoIt should be able to detect.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Hi Plato

The following puts the message box on the screen before the photo is taken supporting your argument my "ProcessWait" was just timing out and not causing a "wait" to occur. I had deduced I needed to slow the AutoIt process down to let the camera do its thing before it got shut down by the "WinClose" instruction. This supports my hunch, but I was getting a facsimile of the right answer for all the wrong reasons when I used - ProcessWait("RemoteCapture DC",10) without the .exe .

Run("C:\Program Files\Canon\CameraWindow\RemoteCaptureDC\RemoteCaptureDC.exe")

WinWaitActive("RemoteCapture DC", "")

ControlClick("RemoteCapture DC", "", "[iD: 1011]")

msgBox(0,"Close RC DC when download is complete", "")

WinClose("RemoteCapture DC")

Where as:

Run("C:\Program Files\Canon\CameraWindow\RemoteCaptureDC\RemoteCaptureDC.exe")

WinWaitActive("RemoteCapture DC", "")

ControlClick("RemoteCapture DC", "", "[iD: 1011]")

ProcessWait("RemoteCapture DC.exe",15)

WinClose("RemoteCapture DC")

takes the shot and shuts down at whatever time has been set in ProcessWait line timed from the moment the script is started. It seems there is no feedback between RC DC and AutoIt because I have not created any. I presume it works because the process time of RC DC is shorter than the run time of my AutoIt script with the wait instruction written correctly.

$ReturnValue = ProcessWait("RemoteCapture DC.exe", 15)

MsgBox(0, "$ReturnValue equals...", $ReturnValue)

placed after the "ProcessWait" instruction produced a message box with a "0" OK, but seemed to mess-up the timing by introducing another 15 second wait I was not expecting.

A good lesson in demonstrating and understanding what is actually going on, next lesson might be figuring out a feedback loop to test then data has down loaded OK, some time if it becomes a problem, Thanks, Alex.Posted Image

Link to comment
Share on other sites

To use ProcessWait, you need the exact name of the process, not the window title + .exe

You have a space between "RemoteCapture" and "DC"

Judging from the Run function in your code, I would say that the space is not supposed to be there.

However, once you get the ProcessWait line correct, you will find it to be useless for your script.

Instead of the ProcessWait line, you might want a WinWait line that uses some window text unique to the completed process window. In other words, if you as a human can see something like "complete" or "done" in the application's final window - then maybe AutoIt can see that too. Use the AutoIt Window Info tool to see what text AutoIt should be able to detect.

Run("C:\Program Files\Canon\CameraWindow\RemoteCaptureDC\RemoteCaptureDC.exe")

WinWaitActive("RemoteCapture DC", "")

ControlClick("RemoteCapture DC", "", "[iD: 1011]")

WinWait("RemoteCapture DC", "Done")

WinClose("RemoteCapture DC", "Done")

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • 1 month later...

I sorted out the space issue - there was a space in the window tile so it needed the space in the command.

I evaded the timing issues by using XP task schedule so my AutoIt script remains at just four lines.

I have run several remote capture sessions and am now working getting the power supplies sorted so I can go independent of the grid.

Thanks again for the most useful help.Posted Image

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...