## Script / UI Sync Problems

Discussions on extending SharpCap using the built in Python scripting functionality
CarlH
Posts: 6
Joined: Tue Apr 03, 2018 11:16 pm

### Script / UI Sync Problems

This is my first attemp to create an atomated script that records R-G-B videos using a filter wheel in a loop until I stop the script. The first red filter recording works fine, but when starting with the green filter the script seems to start running wild: the current filter and the time left display in SharpCap user interface are not updated / displayed anymore, and the next recording does not stop after 30 seconds. Finally when I stop the script the recording continues until I manually press the stop record button in the SharpCap user interface.

Are there additional commands needed to get the script posted below to get running in a controlled manner and to get the user interface correctly displaying the current status?

I am running SharpCap 3.2.6292 and using a ZWO ASI 1600 Mono with an Atik EFW2 filterwheel.

import time
import clr
from System import TimeSpan
from SharpCap.UI import CaptureLimitType
SharpCap.TargetName='Mars'
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitType = CaptureLimitType.TimeLimited

while True:

# RED
SharpCap.SelectedCamera.Controls.Exposure.ExposureMs=10
SharpCap.SelectedCamera.Controls.Gain.Value=240
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitTime = TimeSpan.FromSeconds(30)
SharpCap.Wheels.SelectedWheel.Position = 2
SharpCap.SelectedCamera.PrepareToCapture()
SharpCap.SelectedCamera.RunCapture()
while True:
if not SharpCap.SelectedCamera.Capturing:
break
time.sleep(0.5)

# SAME CODE FOR GREEN AS FOR RED (only different exposure and filter pos)

# SAME CODE FOR BLUE AS FOR RED (only different exposure and filter pos)

Thanks, Carl

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

### Re: Script / UI Sync Problems

Hi,

I can't see anything obviously wrong. I'd advise that you update to the latest version of SharpCap as the one you are using is quite out of date now (there have been some scripting fixes, but nothing that would obviously tie in with what you are seeing).

If you still have problems with the latest version then please can you post the full script including indentation (use the code block button above the message post window – it looks like this </>).

Thanks, Robin

CarlH
Posts: 6
Joined: Tue Apr 03, 2018 11:16 pm

### Re: Script / UI Sync Problems

Hi Robin

thanks for the help. I've just installed the newest SharpCap version. The behaviour is the same:

1. Red filter is recorded fine, 30s, and Time Left is displayed on the status bar. Only the R filter box on the Camera Control Panel is not highlighted, it still shows L, even if R is beeing used for recording. After the 30s the SER-file is correctly stored, and it used the R filter as it should.

2. Green filter starts recording, but Time Left is not displayed in the status bar, and the recording continuous indefinitelly.

For reference, the scripting window shows this information:
IronPython 2.7.9 (2.7.9.0) on .NET 4.0.30319.42000 (32-bit)

Here is the complete code:

Code: Select all

import time
import clr
from System import TimeSpan
from SharpCap.UI import CaptureLimitType
SharpCap.TargetName='Mars'
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitType = CaptureLimitType.TimeLimited

while True:

# RED
SharpCap.SelectedCamera.Controls.Exposure.ExposureMs=10
SharpCap.SelectedCamera.Controls.Gain.Value=240
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitTime = TimeSpan.FromSeconds(30)
SharpCap.Wheels.SelectedWheel.Position = 2
SharpCap.SelectedCamera.PrepareToCapture()
SharpCap.SelectedCamera.RunCapture()
while True:
if not SharpCap.SelectedCamera.Capturing:
break
time.sleep(0.5)

# GREEN
SharpCap.SelectedCamera.Controls.Exposure.ExposureMs=12
SharpCap.SelectedCamera.Controls.Gain.Value=240
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitTime = TimeSpan.FromSeconds(30)
SharpCap.Wheels.SelectedWheel.Position = 3
SharpCap.SelectedCamera.PrepareToCapture()
SharpCap.SelectedCamera.RunCapture()
while True:
if not SharpCap.SelectedCamera.Capturing:
break
time.sleep(0.5)

# BLUE
SharpCap.SelectedCamera.Controls.Exposure.ExposureMs=15
SharpCap.SelectedCamera.Controls.Gain.Value=240
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitTime = TimeSpan.FromSeconds(30)
SharpCap.Wheels.SelectedWheel.Position = 4
SharpCap.SelectedCamera.PrepareToCapture()
SharpCap.SelectedCamera.RunCapture()
while True:
if not SharpCap.SelectedCamera.Capturing :
break
time.sleep(0.5)

Cheers

Carl

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

### Re: Script / UI Sync Problems

Hi Carl,

does it help if you put this line in each colour block rather than just having it at the start of the file?

Code: Select all

SharpCap.SelectedCamera.CaptureConfig.CaptureLimitType = CaptureLimitType.TimeLimited

I'm just wondering if that gets reset when the capture finishes?

Cheers, Robin

CarlH
Posts: 6
Joined: Tue Apr 03, 2018 11:16 pm

### Re: Script / UI Sync Problems

Hi Robin,

adding the CaptureLimitType line to each filter does not help. But adding a SharpCap.SelectedCamera.StopCapture() after every capture ended helps (even if it looks a little strange in the message bar). Maybe capture end and file save do not happen instantaneously, so that a timing problem occurs.

Now the only other real problem left is how to perform a StopCapture when the script is manually stopped. Is there a way to achieve this?

And is there a way to tell the filter bar control to be refreshed with the current filter?

Thanks

Carl

CarlH
Posts: 6
Joined: Tue Apr 03, 2018 11:16 pm

### Re: Script / UI Sync Problems

Hi Robin,

replacing

Code: Select all

SharpCap.Wheels.SelectedWheel.Position = 1
by

Code: Select all

SharpCap.SelectedCamera.Controls.FilterWheel.Value='R'
solves the problem with the filter control box display.

Cheers

Carl

CarlH
Posts: 6
Joined: Tue Apr 03, 2018 11:16 pm

### Re: Script / UI Sync Problems

Hi Robin,

I also managed to stop the last recording when the script is stopped:

Code: Select all

try:
# script code

finally:
if SharpCap.SelectedCamera.Capturing:
SharpCap.SelectedCamera.StopCapture()

Cheers

Carl

CarlH
Posts: 6
Joined: Tue Apr 03, 2018 11:16 pm

### Re: Script / UI Sync Problems

Here is the final code for reference, in case somebody is interested. The script stops fine in the middle of a recording, but not during a filter move - in this case an error appears and the recording continues, which can only be stopped by running and stopping the script again.

Code: Select all

import time
import clr
from System import TimeSpan
from SharpCap.UI import CaptureLimitType
SharpCap.TargetName='Mars'

def Rec(exposureInMs, gain, durationInSecs, filterName):
SharpCap.SelectedCamera.Controls.Exposure.ExposureMs=exposureInMs
SharpCap.SelectedCamera.Controls.Gain.Value=gain
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitType = CaptureLimitType.TimeLimited
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitTime = TimeSpan.FromSeconds(durationInSecs)
SharpCap.ShowNotification('Moving filter wheel to ' + filterName)
SharpCap.SelectedCamera.Controls.FilterWheel.Value=filterName
while SharpCap.SelectedCamera.Controls.FilterWheel.Moving:
time.sleep(0.1)
SharpCap.SelectedCamera.PrepareToCapture()
SharpCap.ShowNotification('Capturing with ' + filterName + ' filter', 0, False, 4)
SharpCap.SelectedCamera.RunCapture()
while SharpCap.SelectedCamera.Capturing:
time.sleep(0.1)
SharpCap.SelectedCamera.StopCapture()

try:
while True:
Rec(10, 240, 30, 'R')
Rec(12, 240, 30, 'G')
Rec(15, 240, 30, 'B')

finally:
if SharpCap.SelectedCamera.Capturing:
SharpCap.SelectedCamera.StopCapture()

Carl