Check if Wheel is Connected

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
User avatar
1CM69
Posts: 62
Joined: Tue Nov 14, 2017 9:49 pm

Check if Wheel is Connected

Post by 1CM69 » Thu Aug 30, 2018 8:22 am

Hi,

just trying out a simple piece of script to check if a Filter Wheel is connected but hit a small bump in the road.

Code: Select all

import clr
clr.AddReference("SharpCap")

if SharpCap.Wheels.SelectedWheel.Connected != False:
	SharpCap.ShowNotification('HAVE WHEEL')
else:
	SharpCap.ShowNotification('NO WHEEL')
the above works perfectly fine when ticking or unticking the 'Connected' checkbox but for belt & braces I would like to check just incase the USB cable has been removed/knocked out after ticking the 'Connected' checkbox because at the moment, if 'Connected' is checked & the USB cable is removed, SharpCap still assumes the device is connected & returns True.

Also found that the same happens when checking for camera connected:

Code: Select all

if SharpCap.SelectedCamera != None:
	SharpCap.ShowNotification('HAVE CAMERA')
else:
	SharpCap.ShowNotification('NO CAMERA')
You can connect to your camera as normal from the menu but then pull the USB cable out & SharpCap still thinks the camera is connected.

I realise that I can go down the 'Try/Except' route but before doing that, I thought that I may be missing a property somewhere.

regards..,

Kirk

User avatar
1CM69
Posts: 62
Joined: Tue Nov 14, 2017 9:49 pm

Re: Check if Wheel is Connected

Post by 1CM69 » Thu Aug 30, 2018 10:26 am

small update.

Here I am checking to see if either the Camera or Wheel or both are not connected:

Code: Select all

if all([SharpCap.Wheels.SelectedWheel.Connected, SharpCap.SelectedCamera]):
	SharpCap.ShowNotification('BOTH CONNECTED')
else:
	SharpCap.ShowNotification('ONE or BOTH DEVICES NOT CONNECTED')
same applies about the removal of USB cable once connected though.

Just thought I'd share this simpler method of checking multiple items for TRUE at the same time.

Regards..,

Kirk

User avatar
admin
Site Admin
Posts: 3094
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Check if Wheel is Connected

Post by admin » Thu Aug 30, 2018 3:24 pm

Hi,

A filter wheel, mount or focuser that has been unplugged (or just randomly dropped out) after connection will typically not report an error until asked to do something (like move to a new position). There is no way to add 'device lost' notifications in SharpCap as the underlying ASCOM drivers do not support this sort of notification (and even if the ASCOM standard contained such a notification you could bet good money that at least half the drivers would not implement it properly...)

Cameras will typically close at some point after USB connection is lost, but this depends on the camera driver developers - the good ones spot that the device has vanished and return an error from their API calls (sometimes even with a 'device lost' error code). Other device drivers sadly just freeze if the device is lost - SharpCap asks for a new frame or to adjust the exposure and the driver just sits there for ever waiting for a reply from a device that is no longer connected.

The upshot of this is that 'all bets are off' if you start pulling out USB cables for connected devices. I have done my best - where possible - to show a useful error message and close the camera (or other device) down gracefully, but that's an aspiration not a promise!

cheers,

Robin

User avatar
1CM69
Posts: 62
Joined: Tue Nov 14, 2017 9:49 pm

Re: Check if Wheel is Connected

Post by 1CM69 » Thu Aug 30, 2018 4:34 pm

OK, thanks for replying Robin, much appreciated.

Regards..,

Kirk

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest