Sequencer "Target" steps - what do they do?
-
lowenthalm
- Posts: 224
- Joined: Mon May 07, 2018 12:27 am
Sequencer "Target" steps - what do they do?
The "TARGET" steps available in the sequencer:
1 PROMPT FOR TARGET
2 MOUNT SET TARGET TO ""
3 SELECT AND GOTO TARGET
4 MOUNT GOTOTARGET
5 MOUNT CURRENT TO TARGET
6 MOUNT SYNC TO TARGET
So...I wanted to just command SharpCap to use its object catalog to go to whatever is in the current target name field. It seemed like there might be some way of doing it, given all of the above steps available.
The first two, are pretty straight foward ways of setting the current target name.
The the 3rd pops open the target catalog dialog, and works as expected.
So, what are the last 3 for? I thought MOUNT GOTOTARGET might use the current target name to grab coordinates from the target catalog and go to it. So I made a sequence that just had MOUNT GOTOTARGET as its single line and ran it. The mount slewed to the last object for which I had previously done a SAVE PLATE SOLVE COORDINATES in a script I had run earlier and looped as if it was waiting to settle. It never did, so I stopped the sequenece. Then I tried running it again, and this time the sequencer editor ended up in a state where I could pause and resume the current sequence, but could not stop it (the stop button was disabled). The close box for SharpCap didn't work either. I was able to hit the close box for the app via start menu bar, and SharpCap popped up its dialog "do you want to quite SharpCap", and Yes closed the dialog and the sequencer popped a message in its sequener run window saying it got a cancellation request. SharpCap didn't quit, so I had to kill the process to get control back.
Given this result, I am afraid to try sequence steps 4, 5 and 6 above to see what they do. The current SharpCap docs do not describe any of the steps after the first 2. Could you describe how how these sequencer steps are used? Is there a way of doing what I originally was interested in doing?
1 PROMPT FOR TARGET
2 MOUNT SET TARGET TO ""
3 SELECT AND GOTO TARGET
4 MOUNT GOTOTARGET
5 MOUNT CURRENT TO TARGET
6 MOUNT SYNC TO TARGET
So...I wanted to just command SharpCap to use its object catalog to go to whatever is in the current target name field. It seemed like there might be some way of doing it, given all of the above steps available.
The first two, are pretty straight foward ways of setting the current target name.
The the 3rd pops open the target catalog dialog, and works as expected.
So, what are the last 3 for? I thought MOUNT GOTOTARGET might use the current target name to grab coordinates from the target catalog and go to it. So I made a sequence that just had MOUNT GOTOTARGET as its single line and ran it. The mount slewed to the last object for which I had previously done a SAVE PLATE SOLVE COORDINATES in a script I had run earlier and looped as if it was waiting to settle. It never did, so I stopped the sequenece. Then I tried running it again, and this time the sequencer editor ended up in a state where I could pause and resume the current sequence, but could not stop it (the stop button was disabled). The close box for SharpCap didn't work either. I was able to hit the close box for the app via start menu bar, and SharpCap popped up its dialog "do you want to quite SharpCap", and Yes closed the dialog and the sequencer popped a message in its sequener run window saying it got a cancellation request. SharpCap didn't quit, so I had to kill the process to get control back.
Given this result, I am afraid to try sequence steps 4, 5 and 6 above to see what they do. The current SharpCap docs do not describe any of the steps after the first 2. Could you describe how how these sequencer steps are used? Is there a way of doing what I originally was interested in doing?
- admin
- Site Admin
- Posts: 17586
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Sequencer "Target" steps - what do they do?
Hi,
the last 3 steps are basic support for the ASCOM concept of 'Target Co-ordinates' in the sequencer. Mount ASCOM drivers have a current pointing co-ordinate and also a 'Target' co-ordinate. Applications can set and read the target co-ordinates to/from the ASCOM driver, and if everything is working as it should, one application (say a planetarium app) can set the target and another (SharpCap) can read those co-ordinates.
So, you have the option to GOTO the current target co-ordinates of the ASCOM mount, set the target co-ordinates to the current co-ordinates and to sync the mount to the target co-ordinates.
SharpCap also gives you some UI interaction with the ASCOM target co-ordinates at the bottom of the mount control area:
The target co-ordinates are shown (here they are actually unset, which is possible) and the three buttons to the right, in order,
* Set the target to the current co-ordinates
* Goto the target co-ordinates
* Sync to the target co-ordinates
You will also find that certain things (like picking a catalog target and going to it in SharpCap) automatically set the target co-ordinates.
What I don't understand is how the sequencer got itself into a state trying to use those steps. If you can share the log from that run then I will have a dig and see if I can see what was going on.
cheers,
Robin
the last 3 steps are basic support for the ASCOM concept of 'Target Co-ordinates' in the sequencer. Mount ASCOM drivers have a current pointing co-ordinate and also a 'Target' co-ordinate. Applications can set and read the target co-ordinates to/from the ASCOM driver, and if everything is working as it should, one application (say a planetarium app) can set the target and another (SharpCap) can read those co-ordinates.
So, you have the option to GOTO the current target co-ordinates of the ASCOM mount, set the target co-ordinates to the current co-ordinates and to sync the mount to the target co-ordinates.
SharpCap also gives you some UI interaction with the ASCOM target co-ordinates at the bottom of the mount control area:
The target co-ordinates are shown (here they are actually unset, which is possible) and the three buttons to the right, in order,
* Set the target to the current co-ordinates
* Goto the target co-ordinates
* Sync to the target co-ordinates
You will also find that certain things (like picking a catalog target and going to it in SharpCap) automatically set the target co-ordinates.
What I don't understand is how the sequencer got itself into a state trying to use those steps. If you can share the log from that run then I will have a dig and see if I can see what was going on.
cheers,
Robin
-
lowenthalm
- Posts: 224
- Joined: Mon May 07, 2018 12:27 am
Re: Sequencer "Target" steps - what do they do?
Here is the SharpCap log and the CPWI ASCOM driver log. After reading your description, it dawned on me that a bit later after trying to use CPWI, it was also in a strange state where it couldn't be closed and I had to kill the process. I was so befuddled at that point that I didn't really think through what had just occurred. I just wanted to get the mount homed and finish up for the night after the dense marine layer clouds came in and ruined yet another night.
I had previously used NGC6823 as a test target for a capture script I was testing. I used CPWI to go to the target, and then plate solved and synced in SharpCap. Then I ran the capture script, which immediately uses SAVE PLATE SOLVE COORDINATES to save the target coordinates for use after a meridian flip. After all this, I had homed the mount and then ran the sequence containing MOUNT GOTOTARGET to see what it would do - and the results can be seen at timestamp 22:06:19.631366 in the log. It slewed back to NGC6823, but then got stuck in a loop. This is where I think CPWI got into a very bad state that forced me to later kill its process tree.
I did not notice whether CPWI implements the ASCOM target mechanism you describe and I don't see any evidence of this in the CPWI ASCOM log. Next time I will check to see if the last target name I slewed to in CPWI shows up in the telescope hardware control panel. Nevertheless, somehow either CPWI provided the target coordinates or SAVE PLATE SOLVE COORDINATES sets the target coordinates, as MOUNT GOTOTARGET did make the mount slew from the mount home position back to the last target to which I had slewed, NGC6823.
Its probably probably worth check the SharpCap log to see what was going on, but not delving in too deeply unless something pops out at you. It appears to be just a case of CPWI glitching. The SharpCap log is pretty verbose, and I don't see any log entries about getting target coordinates and target name from the ASCOM driver. The CPWI log does show an exception occurred in the slew task (bold, below), and that I fussed around with SharpCap (after killing it and restarting it) for another 40 minutes before noticing CPWI's bad state and restarting CPWI too.
CPWI log fragment:
2025-09-10 22:06:04.836 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis0 set-rate 7.29211589881283E-05
2025-09-10 22:06:04.870 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis1 set-rate 7.29211589881283E-05
2025-09-10 22:06:15.187 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis0 set-rate 7.29211589881283E-05
2025-09-10 22:06:15.220 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis1 set-rate 7.29211589881283E-05
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) slew mount requested. raHours:rads decDegrees:rads 19.7319722222222:5.16581824784759 23.3694444444444:0.407873749917452
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) J2000 coordinates[rads]. ra dec 5.16097400097867 0.406759754700183
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) Create Slewing task
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) Create DEFAULT Slewing task
2025-09-10 22:06:19.700 -07:00 [Mount_Service_Executor 21#21] (MountService) GotoCoarse (adjusted) 324675, 7274952
2025-09-10 22:06:24.978 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount service executor reports exception in task: Loop Task for Mount Service
2025-09-10 22:06:24.999 -07:00 [Mount_Service_Executor 21#21] (Connection) Communication issue reported by Mount
2025-09-10 22:06:24.999 -07:00 [Connection_Tasks1#6] (Connection) Attempting to reconnect Mount
2025-09-10 22:07:40.182 -07:00 [#84] (MountService) recieved stop request from ASCOM driver.
2025-09-10 22:10:14.004 -07:00 [#137] (MountService) recieved stop request from ASCOM driver.
2025-09-10 22:46:06.636 -07:00 [#1] (MountService) Mount-axis-stop-and-reset 0
2025-09-10 22:46:06.636 -07:00 [#1] (MountService) Mount-axis-stop 0
2025-09-10 22:46:52.802 -07:00 [#1] (MainForm) Main form attempting to close
2025-09-10 22:46:55.130 -07:00 [#1] (Connection) Connection shutdown scheduled
2025-09-10 22:47:42.597 -07:00 [#1] (MainForm) Main form attempting to close
2025-09-10 22:47:47.821 -07:00 [#1] (Connection) Connection shutdown scheduled
2025-09-10 22:51:05.160 -07:00 [#1] (LogUtil)
log begins... \\Mac\Home\Documents\Celestron\CPWI\Logs\CPWI_log_2025_09_10.txt 0
2025-09-10 22:51:05.175 -07:00 [#1] (LogUtil) CPWI version: 2.5.2.99
2025-09-10 22:51:05.300 -07:00 [#1] (Cpwi) Starting CPWI...
I had previously used NGC6823 as a test target for a capture script I was testing. I used CPWI to go to the target, and then plate solved and synced in SharpCap. Then I ran the capture script, which immediately uses SAVE PLATE SOLVE COORDINATES to save the target coordinates for use after a meridian flip. After all this, I had homed the mount and then ran the sequence containing MOUNT GOTOTARGET to see what it would do - and the results can be seen at timestamp 22:06:19.631366 in the log. It slewed back to NGC6823, but then got stuck in a loop. This is where I think CPWI got into a very bad state that forced me to later kill its process tree.
I did not notice whether CPWI implements the ASCOM target mechanism you describe and I don't see any evidence of this in the CPWI ASCOM log. Next time I will check to see if the last target name I slewed to in CPWI shows up in the telescope hardware control panel. Nevertheless, somehow either CPWI provided the target coordinates or SAVE PLATE SOLVE COORDINATES sets the target coordinates, as MOUNT GOTOTARGET did make the mount slew from the mount home position back to the last target to which I had slewed, NGC6823.
Its probably probably worth check the SharpCap log to see what was going on, but not delving in too deeply unless something pops out at you. It appears to be just a case of CPWI glitching. The SharpCap log is pretty verbose, and I don't see any log entries about getting target coordinates and target name from the ASCOM driver. The CPWI log does show an exception occurred in the slew task (bold, below), and that I fussed around with SharpCap (after killing it and restarting it) for another 40 minutes before noticing CPWI's bad state and restarting CPWI too.
CPWI log fragment:
2025-09-10 22:06:04.836 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis0 set-rate 7.29211589881283E-05
2025-09-10 22:06:04.870 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis1 set-rate 7.29211589881283E-05
2025-09-10 22:06:15.187 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis0 set-rate 7.29211589881283E-05
2025-09-10 22:06:15.220 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount-axis1 set-rate 7.29211589881283E-05
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) slew mount requested. raHours:rads decDegrees:rads 19.7319722222222:5.16581824784759 23.3694444444444:0.407873749917452
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) J2000 coordinates[rads]. ra dec 5.16097400097867 0.406759754700183
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) Create Slewing task
2025-09-10 22:06:19.700 -07:00 [#10] (MountService) Create DEFAULT Slewing task
2025-09-10 22:06:19.700 -07:00 [Mount_Service_Executor 21#21] (MountService) GotoCoarse (adjusted) 324675, 7274952
2025-09-10 22:06:24.978 -07:00 [Mount_Service_Executor 21#21] (MountService) Mount service executor reports exception in task: Loop Task for Mount Service
2025-09-10 22:06:24.999 -07:00 [Mount_Service_Executor 21#21] (Connection) Communication issue reported by Mount
2025-09-10 22:06:24.999 -07:00 [Connection_Tasks1#6] (Connection) Attempting to reconnect Mount
2025-09-10 22:07:40.182 -07:00 [#84] (MountService) recieved stop request from ASCOM driver.
2025-09-10 22:10:14.004 -07:00 [#137] (MountService) recieved stop request from ASCOM driver.
2025-09-10 22:46:06.636 -07:00 [#1] (MountService) Mount-axis-stop-and-reset 0
2025-09-10 22:46:06.636 -07:00 [#1] (MountService) Mount-axis-stop 0
2025-09-10 22:46:52.802 -07:00 [#1] (MainForm) Main form attempting to close
2025-09-10 22:46:55.130 -07:00 [#1] (Connection) Connection shutdown scheduled
2025-09-10 22:47:42.597 -07:00 [#1] (MainForm) Main form attempting to close
2025-09-10 22:47:47.821 -07:00 [#1] (Connection) Connection shutdown scheduled
2025-09-10 22:51:05.160 -07:00 [#1] (LogUtil)
log begins... \\Mac\Home\Documents\Celestron\CPWI\Logs\CPWI_log_2025_09_10.txt 0
2025-09-10 22:51:05.175 -07:00 [#1] (LogUtil) CPWI version: 2.5.2.99
2025-09-10 22:51:05.300 -07:00 [#1] (Cpwi) Starting CPWI...
- Attachments
-
- ASCOM_Telescope_log_SharpCap_2025_09_10_1- slimmed down.txt.zip
- (628.31 KiB) Downloaded 28 times
-
- Log_2025-09-10T19_43_18-8616.log.zip
- (243.57 KiB) Downloaded 30 times
- admin
- Site Admin
- Posts: 17586
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Sequencer "Target" steps - what do they do?
Hi,
thanks for sharing the logs and also doing some analysis. I think you are right that the first issue was caused by CPWI glitching - SharpCap instructs the move to the target co-ordinates, and for a few seconds the mount is moving as expected with the distance to target going down, then it stops reporting any new movement at 22:06:24.928416 - that ties in exactly with your CPWI error in the CPWI log.
On to what happens next... SharpCap sits waiting in the hope that the mount will eventually get to the target co-ordinates. There is a timeout on this (2 minutes), but it looks like you manually cancelled before the timeout expired. From the log, it seems that the sequencer cancellation/stop all went through as planned.
Next, it looks like a custom python script takes over and stuff happens probably under the control of the script. A dark and flat get selected, then the camera is switched from still mode to live mode - all seems OK still.
At about 22:07:48, the application stops responding (we get a report that it hasn't been responding for 10s at 22:07:58). The log then contains a dump of what all the different threads in the application were doing at that point, but the key one is thread #1, which is responsible for keeping the UI responsive. We can see from the log that that thread is inside PythonTime.sleep(), so some python code in that thread is running 'sleep'. Looking further down we come across a mention of CustomButton. So, we know that the thread is sleeping in script in a custom button handler and that is the cause of the hang of SharpCap.
Normal scripts in SharpCap can use 'sleep' because they run from a background thread of their own and that doesn't cause any issues, but code that is run from a custom button should avoid using sleep and should do what it needs to do and return quickly to avoid hanging SharpCap. Do you want to share your custom script with me so that I can give more detailed advice on how to handle the situation?
cheers,
Robin
thanks for sharing the logs and also doing some analysis. I think you are right that the first issue was caused by CPWI glitching - SharpCap instructs the move to the target co-ordinates, and for a few seconds the mount is moving as expected with the distance to target going down, then it stops reporting any new movement at 22:06:24.928416 - that ties in exactly with your CPWI error in the CPWI log.
On to what happens next... SharpCap sits waiting in the hope that the mount will eventually get to the target co-ordinates. There is a timeout on this (2 minutes), but it looks like you manually cancelled before the timeout expired. From the log, it seems that the sequencer cancellation/stop all went through as planned.
Next, it looks like a custom python script takes over and stuff happens probably under the control of the script. A dark and flat get selected, then the camera is switched from still mode to live mode - all seems OK still.
At about 22:07:48, the application stops responding (we get a report that it hasn't been responding for 10s at 22:07:58). The log then contains a dump of what all the different threads in the application were doing at that point, but the key one is thread #1, which is responsible for keeping the UI responsive. We can see from the log that that thread is inside PythonTime.sleep(), so some python code in that thread is running 'sleep'. Looking further down we come across a mention of CustomButton. So, we know that the thread is sleeping in script in a custom button handler and that is the cause of the hang of SharpCap.
Normal scripts in SharpCap can use 'sleep' because they run from a background thread of their own and that doesn't cause any issues, but code that is run from a custom button should avoid using sleep and should do what it needs to do and return quickly to avoid hanging SharpCap. Do you want to share your custom script with me so that I can give more detailed advice on how to handle the situation?
cheers,
Robin
-
lowenthalm
- Posts: 224
- Joined: Mon May 07, 2018 12:27 am
Re: Sequencer "Target" steps - what do they do?
Firstly, I have several buttons that call sequences. For example, one custom button auto-sets the focuser to an estimate of best focus (all in Python code) and then the Python code runs a sequencer file that does an auto focus scan. Definitely doesn't return quickly! Is it ok to call sequences from a custom button? These seem to work fine, as far as I can tell, not freezing the interface. You can see an example in the code below that is walled off a function, ExceInSequencerOnly(), that the Python code no longer calls.
I think the custom button you are seeing that uses a sleep is a custom button that calls a python function called MDLCustomButtonDarkAndFlatAction. This has been on my fix list for ages. It sleeps for about 6 seconds waiting for the next frame before completing its operations. I use the button a few times when I first start up for the night to quickly set up the camera, exposure, gain, flat, dark and display stretch in preparation for syncing my mount on a star when I first turn the mount on for the night. I know it freezes the interface for that the 6 second wait, but since I only use it once or twice at the beginning of the night, I kept putting off fixing it.
This particular custom button used to call a sequence, but I turned off that bit of code in favor of doing it all in Python. However, I was stuck with the sleep() call because I couldn't figure out how to do the equivalent of the sequencer statement "WAIT FOR FRAME" in SharpCap Python. All the methods for waiting for a frame in the camera object seem to save captures to disk, which isn't what I wanted.
Here is the code, with the problem bit at # HOW DO I ... Thanks for taking a look at it for me!
I think the custom button you are seeing that uses a sleep is a custom button that calls a python function called MDLCustomButtonDarkAndFlatAction. This has been on my fix list for ages. It sleeps for about 6 seconds waiting for the next frame before completing its operations. I use the button a few times when I first start up for the night to quickly set up the camera, exposure, gain, flat, dark and display stretch in preparation for syncing my mount on a star when I first turn the mount on for the night. I know it freezes the interface for that the 6 second wait, but since I only use it once or twice at the beginning of the night, I kept putting off fixing it.
This particular custom button used to call a sequence, but I turned off that bit of code in favor of doing it all in Python. However, I was stuck with the sleep() call because I couldn't figure out how to do the equivalent of the sequencer statement "WAIT FOR FRAME" in SharpCap Python. All the methods for waiting for a frame in the camera object seem to save captures to disk, which isn't what I wanted.
Here is the code, with the problem bit at # HOW DO I ... Thanks for taking a look at it for me!
Code: Select all
def MDLCustomButtonDarkAndFlatAction():
def PerformAutoStretch():
from time import sleep
# This isn't needed since changing ExposureGainShift triggers a preview restart
# SharpCap.SelectedCamera.RestartPreview()
exposure = SharpCap.SelectedCamera.Controls.Exposure.Value
# This locks the interface. Not nice. Need to figure out how make this work better
# changed to all Python code so that it doesn't zap the sequence currently loaded into the sequence editor...
# HOW DO I do the equivalent of a sequencer "WAIT FOR FRAME" here.
sleep( exposure + 1.0 )
SharpCap.SelectedCamera.Controls.DisplayStretchEnable.Value = True
SharpCap.DisplayStretch.CalcAutoStretch()
def PerformFastAutoStretch():
from math import log2
# rescale gain/exposure to 5 seconds to quickly get an image that can be
# used to calculate the auto stretch for a much longer exposure
target_fast_exposure = 5
SharpCap.SelectedCamera.LiveView = True
SharpCap.SelectedCamera.Controls.ExposureGainShift.Value = 0
fast_exposure_log = log2( target_fast_exposure )
exposure_log = log2( SharpCap.SelectedCamera.Controls.Exposure.Value )
#print( exposure_log, fast_exposure_log, fast_exposure_log - exposure_log )
SharpCap.SelectedCamera.Controls.ExposureGainShift.Value = fast_exposure_log - exposure_log
PerformAutoStretch()
SharpCap.SelectedCamera.Controls.ExposureGainShift.Value = 0
def ExecInPythonOnly():
# new code seems to work better, wihtout locking the interface
MDLAutoDarkFlat.AutosetDarkAndFlat( wait = 0 )
PerformFastAutoStretch()
def ExceInSequencerOnly():
SharpCap.Sequencer.RunSequenceFile(
"\\\\Mac\\Home\\Desktop\\SharpCap Captures\\__Sharpcap Sequences\\Set Dark and Flat for Current Exposure (Best Gain).scs"
)
#ExceInSequencerOnly()
ExecInPythonOnly()
-
lowenthalm
- Posts: 224
- Joined: Mon May 07, 2018 12:27 am
Re: Sequencer "Target" steps - what do they do?
For sequencer script calls, I presume the following would be preferred in custom button code implementations that run sequencer scripts:
to get it to immediately return from the custom button once the sequencer ball is rolling down the hill.
When I started writing Python code for SharpCap, I really didn't pay attention to thread safe implementations. I was just trying to figure out the language! I'm paying attention now and promise I will do better.
# I am replacing the current code that uses sleep() to the following code so I don't run into further problems this weekend. Once I get feedback from you as to how to do this in Python, use the technique you recommend.
Code: Select all
def MDLSafeRunSequencerFileAsync( script_path : str ):
SharpCap.Sequencer.LoadScriptFile( script_path )
task = SharpCap.Sequencer.RunAsync()
When I started writing Python code for SharpCap, I really didn't pay attention to thread safe implementations. I was just trying to figure out the language! I'm paying attention now and promise I will do better.
# I am replacing the current code that uses sleep() to the following code so I don't run into further problems this weekend. Once I get feedback from you as to how to do this in Python, use the technique you recommend.
Code: Select all
def MDLSafeWaitForNextFrame( ):
if SharpCap.SequencerIsRunning:
print( "MDLSafeWaitForNextFrame: Sequencer is running - don't run any sequence scripts" )
else:
script = "LIVE MODE\nWAIT FOR FRAME"
SharpCap.Sequencer.LoadScript( script )
task = SharpCap.Sequencer.RunAsync()
# wait for task to return before returning...
SharpCap.SafeWaitForAsync( task )
-
lowenthalm
- Posts: 224
- Joined: Mon May 07, 2018 12:27 am
Re: Sequencer "Target" steps - what do they do?
I went back and double checked my auto focus Python code to make sure no sleeps() were being triggered. I had implemented using SharpCap.Focusers.SelectedFocuser.StartMoveAsync so I would no longer need to perform a sleep. However, the
When this returns, it double checks to make sure the focuser is still moving and if it is, it is forced to sleep a bit until its finished:
When I checked the console, SharpCap.Focusers.SelectedFocuser.IsMoving was still returning True, so it fell into the emergency fallback code that sleeps some extra time.
So apparently, I should take the SharpCap function name at face value: it starts, but doesn't wait. How do I make it wait after I start the focus move in a thread-safe way?
P.S. I played around with "await asyncio.sleep( 5 )", but it looks like Iron Python doesn't implement await it, or doesn't implement the same way started Python does or maybe await appears in a later version of Python than IronPython supports. So at this point, I am not even sure what documentation to look at to learn how Iron Python threading works.
Code: Select all
def do_the_move_async( new_pos ):
# 2025-08-03 Changed to Async so interface wouldn't freeze
from System.Threading import CancellationToken
task = SharpCap.Focusers.SelectedFocuser.StartMoveAsync( new_pos, CancellationToken() )
SharpCap.SafeWaitForAsync( task )
Code: Select all
self.do_the_move_async( new_pos ):
if SharpCap.Focusers.SelectedFocuser.IsMoving:
print( e, "Waiting for focuser to finish, despite using async focus move!" )
time.sleep(5)
print( "...focuser still moving? ", SharpCap.Focusers.SelectedFocuser.IsMoving )
So apparently, I should take the SharpCap function name at face value: it starts, but doesn't wait. How do I make it wait after I start the focus move in a thread-safe way?
P.S. I played around with "await asyncio.sleep( 5 )", but it looks like Iron Python doesn't implement await it, or doesn't implement the same way started Python does or maybe await appears in a later version of Python than IronPython supports. So at this point, I am not even sure what documentation to look at to learn how Iron Python threading works.
- admin
- Site Admin
- Posts: 17586
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Sequencer "Target" steps - what do they do?
Hi,
ah, OK, that's an interesting case. The StartMoveAsync really does just start the move - the async part of it is handling the case where the hardware is misbehaving and not responding promptly (or similar), avoiding the application becoming unresponsive while waiting for the hardware to respond.
As a quick work around, try replacing the sleep() with something like
You can probably do that in a loop while the moving flag is set without the application becoming unresponsive, as the Task.Delay() call will cause the application to process windows messages while waiting (which sleep doesn't do).
Let me know if that works - it might be a good idea to add a scripting helper function to wait safely on a condition lambda returning true.
cheers,
Robin
ah, OK, that's an interesting case. The StartMoveAsync really does just start the move - the async part of it is handling the case where the hardware is misbehaving and not responding promptly (or similar), avoiding the application becoming unresponsive while waiting for the hardware to respond.
As a quick work around, try replacing the sleep() with something like
Code: Select all
SharpCap.SafeWaitForAsync(Task.Delay(1000)) # import Task from System.Threading.TasksLet me know if that works - it might be a good idea to add a scripting helper function to wait safely on a condition lambda returning true.
cheers,
Robin
-
lowenthalm
- Posts: 224
- Joined: Mon May 07, 2018 12:27 am
Re: Sequencer "Target" steps - what do they do?
So here is what I implemented to wait for a short (5 second or less exposure) in Python. The interface does not freeze.
Is there a better way to do a wait for next frame in Python?
And here is what I implemented to wait for the focuser motion to complete moving. As with waiting for the next frame above, the wait time is expected to be short, no more than about 3 seconds, unless something goes seriously wrong.
I have been trying to get at the docs for Task so I can better understand how to use it, but hit brick wall in the Iron Python help system:
Despite Task being completely opaque, if I excute "from System.Threading.Tasks import Task" and Task.Delay(1000), it works as you described.
...and I just tried importing from System.Threading.Tasks import Task into the global name space at the Python console prompt, and help( Task ) still shows the same as it did in the above code listing fragment. HOWEVER, typing Task. pops up the function browser and shows Delay, etc, etc. None of the listed methods in Task seem at all related to the Python Docs on line for the Task class. Every time I think I am getting the hang of Python I run into bizarre things like this. I am so confused...
Task is not a namespace I can iterate through either, and the output of print( Task ) is "Microsoft.Scripting.Actions.TypeGroup:Task(Task, Task`1)". Is this something in .NET that is being implemented in Iron Python instead of the Python standard Task class?
Code: Select all
def MDLWaitForNextExposure( additional_wait_in_sec = 1 ):
from System.Threading.Tasks import Task
exposure_wait_time = SharpCap.SelectedCamera.LatestStatus.FrameProgress.ExposureTimeSeconds - \
SharpCap.SelectedCamera.LatestStatus.FrameProgress.ExposureElapsedSeconds \
+ additional_wait_in_sec
# convert to integer ms (Delay wants a TimeSpan, and only an int will directly convert
wait_time_in_ms = int(exposure_wait_time * 1000 + .5)
SharpCap.SafeWaitForAsync(Task.Delay(wait_time_in_ms))
And here is what I implemented to wait for the focuser motion to complete moving. As with waiting for the next frame above, the wait time is expected to be short, no more than about 3 seconds, unless something goes seriously wrong.
Code: Select all
# returns True focuser finished moving before the timeout, otherwise returns False
def MDLFocuserToFinishMoving( timeout_in_sec = 8, poll_frequence_in_sec = 0.5 ) -> bool :
from System.Threading.Tasks import Task
debug_count_down = 0 # set to non zero positive loop count to debug without focuser available
def IsFocuserMoving( debug ):
if debug > 0:
return debug - 1
else:
print( "Debug mode off: actually checking focuser for movement" )
return SharpCap.Focusers.SelectedFocuser.IsMoving
wait_time_in_ms = int(poll_frequence_in_sec * 1000)
loops = int( timeout_in_sec / poll_frequence_in_sec + .99 )
print( f"Waiting with timeout {timeout_in_sec}, polling every {wait_time_in_ms} milliseconds, max {loops} loops until timeout." )
for t in range( 0, loops):
print( f"Waiting...{t}" )
is_moving = IsFocuserMoving( debug_count_down )
if not is_moving:
return True
debug_count_down = is_moving
SharpCap.SafeWaitForAsync(Task.Delay(wait_time_in_ms))
print( "Timeout occurred!" )
return False
Code: Select all
def TestFunc():
from System.Threading.Tasks import Task
help( Task )
TestFunc()
returns...
Help on type-collision object:
class type-collision(type-collision)
| Method resolution order:
| type-collision
| type-collision
| MemberTracker
| object
|
| Methods defined here:
|
| GetBoundValue(...)
| GetBoundValue(self: MemberTracker, resolverFactory: OverloadResolverFactory, binder: ActionBinder, instanceType: Type, instance: DynamicMetaObject) -> DynamicMetaObject
|
| SetBoundValue(...)
| SetBoundValue(self: MemberTracker, resolverFactory: OverloadResolverFactory, binder: ActionBinder, instanceType: Type, value: DynamicMetaObject, instance: DynamicMetaObject) -> DynamicMetaObject
| SetBoundValue(self: MemberTracker, resolverFactory: OverloadResolverFactory, binder: ActionBinder, instanceType: Type, value: DynamicMetaObject, instance: DynamicMetaObject, errorSuggestion: DynamicMetaObject) -> DynamicMetaObject
|
.....
lots more stuff that clearly has nothing to do with Task
.....
...and I just tried importing from System.Threading.Tasks import Task into the global name space at the Python console prompt, and help( Task ) still shows the same as it did in the above code listing fragment. HOWEVER, typing Task. pops up the function browser and shows Delay, etc, etc. None of the listed methods in Task seem at all related to the Python Docs on line for the Task class. Every time I think I am getting the hang of Python I run into bizarre things like this. I am so confused...
Task is not a namespace I can iterate through either, and the output of print( Task ) is "Microsoft.Scripting.Actions.TypeGroup:Task(Task, Task`1)". Is this something in .NET that is being implemented in Iron Python instead of the Python standard Task class?
- admin
- Site Admin
- Posts: 17586
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Sequencer "Target" steps - what do they do?
Hi,
good to hear that you have made progress with solutions for the hanging, although I still have a note to try to make this sort of thing easier for scripting users.
The thing to remember with IronPython is that you can either talk to python library types or to .NET Framework types. In the case of the Task class we are using here, it's a .NET Framework type (see https://learn.microsoft.com/en-us/dotne ... ew=net-9.0).
I'm afraid I don't quite understand why you get the weird output from 'help(Task)' - I presume there must be some other 'Task' that is also available in the global scope, but I am not sure why. Things like 'help(Task.Delay)' seem to work fine.
cheers,
Robin
good to hear that you have made progress with solutions for the hanging, although I still have a note to try to make this sort of thing easier for scripting users.
The thing to remember with IronPython is that you can either talk to python library types or to .NET Framework types. In the case of the Task class we are using here, it's a .NET Framework type (see https://learn.microsoft.com/en-us/dotne ... ew=net-9.0).
I'm afraid I don't quite understand why you get the weird output from 'help(Task)' - I presume there must be some other 'Task' that is also available in the global scope, but I am not sure why. Things like 'help(Task.Delay)' seem to work fine.
cheers,
Robin