Page 1 of 1

Execute a focus assistant tool from script

Posted: Sat Dec 26, 2020 7:47 pm
by Droy
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.

Re: Execute a focus assistant tool from script

Posted: Mon Dec 28, 2020 5:23 pm
by admin
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

Re: Execute a focus assistant tool from script

Posted: Tue Dec 29, 2020 7:11 pm
by Droy
Thanks a lot for your answer!!!

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.

Re: Execute a focus assistant tool from script

Posted: Wed Dec 30, 2020 8:32 pm
by admin
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

Re: Execute a focus assistant tool from script

Posted: Thu Dec 31, 2020 11:23 am
by Droy
THANKS A LOT!!!

This will be great! I will be looking forward for the upgrade. I really appreciate your support and effort.

Re: Execute a focus assistant tool from script

Posted: Thu Dec 31, 2020 1:55 pm
by admin
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

Re: Execute a focus assistant tool from script

Posted: Thu Dec 31, 2020 3:05 pm
by admin
Hi,

this updated version is now available in the beta download page.

Cheers, Robin

Re: Execute a focus assistant tool from script

Posted: Wed Jan 06, 2021 12:10 am
by Droy
Thanks for the update!!

I have been testing this feature and it works very well. It is exactly what we needed.

Best regards