Switch Class
Master Interfaces Reference
These green boxes in each interface member each have a link to the corresponding member definition in Master ISwitchV3 Interface (external). The information in this Alpyca document is provided for your convenience. If there is any question, the info in ASCOM Master Interface Definitions (external) is the official specification.
- class alpaca.switch.Switch(address: str, device_number: int, protocol: str = 'http')
Bases:
DeviceASCOM Standard ISwitch V2 Interface
Initialize the Switch device.
- Parameters:
address (
str) – IP address and port of the device (x.x.x.x:pppp)device_number (
int) – The index of the device (usually 0)protocol (
str, optional) – Only if device needs https. Defaults to “http”.
- Action(ActionName: str, *Parameters) str
Invoke the specified device-specific custom action
Common to all devices
- Parameters:
ActionName – A name from
SupportedActionsthat represents the action to be carried out.*Parameters – List of required parameters or [] if none are required.
- Returns:
String result of the action.
- Raises:
NotImplementedException – If no actions at all are supported
ActionNotImplementedException – If the driver does not support the
requested – ActionName. The supported action names are listed in
SupportedActions.NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
This method, combined with
SupportedActions, is the supported mechanic for adding non-standard functionality.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
Action(), find this specific device’s specification, and seeAction()there.
- CanAsync(Id: int) bool
The specified switch can operate asynchronously. See
SetAsync()andSetAsyncValue().- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.Examples of switches that cannot be written to include a limit switch or a sensor.
Master Interfaces Reference
Switch.CanAsync() (external)
- CanWrite(Id: int) bool
The specified switch can be written to.
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.Examples of witches that cannot be written to include a limit switch or a sensor.
Master Interfaces Reference
Switch.CanWrite() (external)
- CancelAsync(Id: int) None
Cancels an in-progress asynchronous state change operation. See
SetAsync()andSetAsyncValue()for details of asynchronous switch operations.- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
On return, the next call to
StateChangeComplete()for this switch will raise anOperationCancelledException; thereafter calls toStateChangeComplete()for the switch will returnFalse.Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.CancelAsync() (external)
- CommandBlind(Command: str, Raw: bool) None
Transmit an arbitrary string to the device and does not wait for a response.
Common to all devices
- Parameters:
Command – The literal command string to be transmitted.
Raw – If true, command is transmitted ‘as-is’. If false, then protocol framing characters may be added prior to transmission.
- Raises:
NotImplementedException – If no actions at all are supported
NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Attention
Deprecated, will most likely result in
NotImplementedExceptionMaster Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
CommandBlind(), find this specific device’s specification, and seeCommandBlind()there.
- CommandBool(Command: str, Raw: bool) bool
Transmit an arbitrary string to the device and wait for a boolean response.
Common to all devices
- Returns:
The True/False response from the command
- Parameters:
Command – The literal command string to be transmitted.
Raw – If true, command is transmitted ‘as-is’. If false, then protocol framing characters may be added prior to transmission.
- Raises:
NotImplementedException – If no actions at all are supported
NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Attention
Deprecated, will most likely result in
NotImplementedExceptionMaster Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
CommandBlind(), find this specific device’s specification, and seeCommandBlind()there.
- CommandString(Command: str, Raw: bool) str
Transmit an arbitrary string to the device and wait for a string response.
Common to all devices
- Returns:
The string response from the command
- Parameters:
Command – The literal command string to be transmitted.
Raw – If true, command is transmitted ‘as-is’. If false, then protocol framing characters may be added prior to transmission.
- Raises:
NotImplementedException – If no actions at all are supported
NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Attention
Deprecated, will most likely result in
NotImplementedExceptionMaster Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
CommandString(), find this specific device’s specification, and seeCommandString()there.
- Connect() None
Connect to the device asynchronously.
Common to all devices
- Returns:
Nothing
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Non-Blocking Use
Connectingto indicate completion.Natively present only in Platform 7 (2024) devices, but this library emulates Connect()/Disconnect()/Connecting mechanic for older devices.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
Connect(), find this specific device’s specification, and seeConnect()there.
- Disconnect() None
Disconnect from the device asynchronously.
Common to all devices
- Returns:
Nothing
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Non-Blocking Use
Connectingto indicate completion.Natively present only in Platform 7 (2024) devices, but this library emulates Connect()/Disconnect()/Connecting mechanic for older devices.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
Disconnect(), find this specific device’s specification, and seeDisconnect()there.
- GetSwitch(Id: int) bool
The state of the specified switch.
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.On is True, Off is False.
Master Interfaces Reference
Switch.GetSwitch() (external)
- GetSwitchDescription(Id: int) str
The textual description of the specified switch.
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.GetSwitchDescription() (external)
- GetSwitchName(Id: int) str
The textual name of the specified switch.
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.GetSwitchName() (external)
- GetSwitchValue(Id: int) float
The value of the specified switch as a float.
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.GetSwitchValue() (external)
- MaxSwitchValue(Id: int) float
The maximum value of the specified switch as a double.
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.MaxSwitchValue() (external)
- MinSwitchValue(Id: int) float
The minimum value of the specified switch as a double.
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.MinSwitchValue() (external)
- SetAsync(Id: int, State: bool) None
Asynchronouly Set a switch to the specified boolean on/off state.
- Parameters:
Id – the specified switch number (see Notes)
State – The required control state
- Raises:
NotImplementedException – If
CanAsync()= Falsefor switchIdInvalidValueException – The
Idis out of range (seeMaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Asynchronous (non-blocking): The method returns as soon as the state change operation has been successfully started, with
StateChangeComplete()for switchId = False. After the state change has completedStateChangeComplete()becomes True.Switches are numbered from 0 to
MaxSwitch- 1.On is True, Off is False.
Master Interfaces Reference
Switch.SetAsync() (external)
- SetAsyncValue(Id: int, Value: float) None
Asynchronouly Set a switch to the specified value
- Parameters:
Id – the specified switch number (see Notes)
Value – The value to be set, between
MinSwitchValue`()andMaxSwitchValue()for switchId
- Raises:
NotImplementedException – If
CanAsync()= Falsefor switchIdInvalidValueException – The Id is out of range (see
MaxSwitch), or if the given value is not betweenMinSwitchValue()andMaxSwitchValue()for the given switchId.NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Asynchronous (non-blocking): The method returns as soon as the state change operation has been successfully started, with
StateChangeComplete()for switchId = False. After the state change has completedStateChangeComplete()becomes True.Switches are numbered from 0 to
MaxSwitch- 1.On is True, Off is False.
Master Interfaces Reference
Switch.SetAsyncValue() (external)
- SetSwitch(Id: int, State: bool) None
Set a switch to the specified state
- Parameters:
Id – the specified switch number (see Notes)
State – The required control state
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.On is True, Off is False.
Master Interfaces Reference
Switch.SetSwitch() (external)
- SetSwitchName(Id: int, Name: str) None
Set a switch name to the specified value.
- Parameters:
Id – the specified switch number (see Notes)
Name – The desired (new) name for the switch
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.On is True, Off is False.
Master Interfaces Reference
Switch.SetSwitchName() (external)
- SetSwitchValue(Id: int, Value: float) None
Set a switch value to the specified value.
- Parameters:
Id – the specified switch number (see Notes)
Value – Value to be set, between
MinSwitchValueandMinSwitchValue.
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch), or the Value is out of range, not betweenMinSwitchValueandMinSwitchValue.NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.On is True, Off is False.
Master Interfaces Reference
Switch.SetSwitchValue() (external)
- StateChangeComplete(Id: int) bool
True if the last
SetAsync()orSetAsyncValue()has completed and the switch is in the requested state.- Parameters:
Id – the specified switch number (see Notes)
- Raises:
NotImplementedException – If
CanAsync()isFalsefor switchIdOperationCancelledException – If an in-progress state change is cancelled by a call to
CancelAsync()call for switchIdInvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.StateChangeComplete() (external)
- SwitchStep(Id: int) float
The step size of the specified switch (see Notes).
- Parameters:
Id – the specified switch number (see Notes)
- Raises:
InvalidValueException – The Id is out of range (see
MaxSwitch)NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Step size is the difference between successive values of the device.
Switches are numbered from 0 to
MaxSwitch- 1.
Master Interfaces Reference
Switch.SwitchStep() (external)
- property Connected: bool
(Read/Write) Retrieve or set the connected state of the device.
Common to all devices
Set True to connect to the device hardware. Set False to disconnect from the device hardware. You can also read the property to check whether it is connected. This reports the current hardware state. See Notes below.
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
The
Connectedproperty sets and reports the state of connection to the device hardware. For a hub this means thatConnectedwill beTruewhen the first driver connects and will only be set to False when all drivers have disconnected. A second driver may find thatConnectedis alreadyTrueand settingConnectedto False does not reportConnectedas False. This is not an error because the physical state is that the hardware connection is stillTrue.Multiple calls setting
ConnectedtoTrueor false will not cause an error.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
Connected, find this specific device’s specification, and seeConnectedthere.
- property Connecting: bool
Returns
Truewhile the device is undertaking an asynchronousConnect()orDisconnect()operation.Common to all devices
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Use this property to determine when an (async)
Connect()orDisconnect()has completed, at which time it will transition fromTruetoFalse.Natively present only in Platform 7 (2024) devices, but this library emulates Connect()/Disconnect()/Connecting mechanic for older devices.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
Connecting, find this specific device’s specification, and seeConnectingthere.
- property Description: str
Description of the device such as manufacturer and model number.
Common to all devices
- Raises:
NotConnectedException – If the device status is unavailable
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
This describes the device, not the driver. See the
DriverInfoproperty for information on the ASCOM driver.The description length will be a maximum of 64 characters so that it can be used in FITS image headers, which are limited to 80 characters including the header name.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
Description, find this specific device’s specification, and seeDescriptionthere.
- property DeviceState: List[dict]
List of key-value pairs representing the operational properties of the device
Common to all devices
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
DeviceState, find this specific device’s specification, and seeDeviceStatethere.
- property DriverInfo: List[str]
Descriptive and version information about the ASCOM driver
Common to all devices
- Returns:
Python list of strings (see Notes)
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
This describes the driver not the device. See the
Descriptionproperty for information on the device itselfThe return is a Python list of strings, the total length of which may be hundreds to thousands of characters long. It is intended to display detailed information on the ASCOM (COM or Alpaca) driver, including version and copyright data. . To get the driver version in a parse-able string, use the
DriverVersionproperty.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
DriverInfo, find this specific device’s specification, and seeDriverInfothere.
- property DriverVersion: str
String containing only the major and minor version of the driver.
Common to all devices
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
This must be in the form “n.n”. It should not to be confused with the
InterfaceVersionproperty, which is the version of this specification supported by the driver. Note: on systems with a comma as the decimal point you may need to make accommodations to parse the value.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
DriverVersion, find this specific device’s specification, and seeDriverVersionthere.
- property InterfaceVersion: int
ASCOM Device interface definition version that this device supports.
Common to all devices
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
This is a single integer indicating the version of this specific ASCOM universal interface definition. For example, for ICameraV3, this will be 3. It should not to be confused with the
DriverVersionproperty, which is the major.minor version of the driver for this device.This value is cached internally after first retrieval since it is repeatedly used if emulating Connect/Disconnect semantics on older (pre - Platform 7) devioces.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
InterfaceVersion, find this specific device’s specification, and seeInterfaceVersionthere.
- property MaxSwitch: int
Count of switches managed by this device.
- Raises:
NotConnectedException – If the device is not connected
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
Number of switches managed by this device. Switches are numbered from 0 to MaxSwitch - 1.
Master Interfaces Reference
Switch.MaxSwitch (external)
- property Name: str
The short name of the driver, for display purposes.
Common to all devices
- Raises:
DriverException – If the driver cannot successfully complete the request. This exception may be encountered on any call to the device.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
Name, find this specific device’s specification, and seeNamethere.
- property SupportedActions: List[str]
The list of custom action names supported by this driver
Common to all devices
- Returns:
Python list of strings (see Notes)
- Raises:
DriverException – An error occurred that is not described by one of the more specific ASCOM exceptions. The device did not successfully complete the request.
Note
This method, combined with
Action(), is the supported mechanic for adding non-standard functionality.SupportedActions is a “discovery” mechanism that enables clients to know which Actions a device supports without having to exercise the Actions themselves. This mechanism is necessary because there could be people / equipment safety issues if actions are called unexpectedly or out of a defined process sequence. It follows from this that SupportedActions must return names that match the spelling of
Action()names exactly, without additional descriptive text. However, returned names may use any casing because the ActionName parameter ofAction()is case insensitive.
Master Interfaces Reference
Alpyca uses a common Device class but this is not available in the ASCOM Master Interface Definitions (external). To see the reference info for
SupportedActions, find this specific device’s specification, and seeSupportedActionsthere.