Execute a focus assistant tool from script

Discussions on extending SharpCap using the built in Python scripting functionality
Droy
Posts: 10
Joined: Sat Dec 26, 2020 7:11 pm

Execute a focus assistant tool from script

I'm writing a script to automate an observation session with an ASCOM mount and focuser. I would like to execute from script a focus assistant, like "FWHM Measurement". When I execute:

SharpCap.Focusers.SelectedFocuser.Connected = True
SharpCap.Transforms.SelectTransform("FWHM Measurement")

The assistant window opens but I must click manually in the "In" or "Out" buttom to start the secuence of auto focus.

Is there any way I can execute this automatically? Besides, How can I select from script a custom image area before start the auto focus secuence?

Any help will be very welcomed.
Posts: 6667
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Execute a focus assistant tool from script

Hi,

Selecting the rectangle is supported :

Code: Select all

clr.AddReference("System.Drawing")
from System.Drawing import Rectangle
SharpCap.Transforms.SelectionRect = Rectangle(10,20,30,40)

Note - don't try SharpCap.Transforms.SelectionRect.Top = 100 - it doesn't work.

Access to the scan in/out functionality via scripting is not possible, but in SharpCap 3.3 beta you can invoke the autofocus sequencer action from scripting

Code: Select all

SharpCap.Sequencer.RunSequence("AUTOFOCUS OFFSET -100 TO 100 STEP COUNT 20")

This will select multistar FWHM (sorry, only option right now), then scan from current position -100 to current position +100 in 20 steps and then return to the best found focus point.

cheers,

Robin
Droy
Posts: 10
Joined: Sat Dec 26, 2020 7:11 pm

Re: Execute a focus assistant tool from script

The secuencer it is really great!!! I find this feature extremely useful.

Now I'm testing my script with version 3.3 and it is very promising, now I have more questions related with that, I hope you don't mind me to ask you more questions.

Is there any way to know if the focus process ended successfuly? I have tried and the script-command apparently ends without error, although the secuencer window could show a problem:

19:46:28 Error : 'SharpCap did not find a best focus position in the range 24900 to 25100' while running step Autofocus from offset -100 to 100 with 20 steps
19:46:28 End : Sequence halted due to error.

I would like to know from the script what happened in order to try again with a wider range or inform about the problem to the requester (in my case a remote program I'm writing) so any way to know about the process will be very useful.

Besides, the progress bar in the secuencer remains incomplete and the window open, I know it is not a big issue but Is there any way to close the secuencer window from the script? And the focus window?

Thanks a lot for your help!

P.S: FYI We are writing an script to execute in 3 separates PCs with 3 SharpCaps to receive commands from a command center in order to syncronize the capture of images, but we need to know, before sending the capture command, if the focus process was sucessful or not in the three telescopes. The script to receive JSON commands http way is already done and is working, but we need to finish the focus secuence.
Posts: 6667
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Execute a focus assistant tool from script

Hi,

I'm afraid there's no obvious way to shut down the sequence progress window from the scripting, and right now I can't see a clean way to add one.

However, it is easy to add a status property to the sequencer object, which can report back where the sequence completed successfully or with an error after the sequence has finished running – I will put that in the next update to SharpCap 3.3.

Sounds like a fun project that you are building

Cheers, Robin
Droy
Posts: 10
Joined: Sat Dec 26, 2020 7:11 pm

Re: Execute a focus assistant tool from script

THANKS A LOT!!!

This will be great! I will be looking forward for the upgrade. I really appreciate your support and effort.
Posts: 6667
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Execute a focus assistant tool from script

You will be able to query

Code: Select all

SharpCap.Sequencer.Status

This will give back an enumeration of type SharpCap.Sequencer.SequencerStatus, which can be one of

Code: Select all

        Unknown,
Running,
Completed,
Error,
Cancelled,

cheers,

Robin
Posts: 6667
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Hi,