Class RelayDevice
Abstract class representing a relay device. It provides methods to check the device status, get and set the status of individual relays, and control the power state of the relays. The class also includes an event to notify when the status of a relay changes. The implementation of the methods is left to the derived classes, which will provide specific functionality based on the type of relay device being used.
public abstract class RelayDevice
- Inheritance
-
RelayDevice
- Derived
- Inherited Members
- Extension Methods
Constructors
RelayDevice(Relay, RelaySettings)
Constructor for the RelayDevice class. It initializes the Relay and RelaySettings properties, and sets up the timer for checking the status of the relays if a refresh time is specified in the relay settings.
protected RelayDevice(Relay relay, RelaySettings relaySettings)
Parameters
relayRelayThe Relay object representing the relay device.
relaySettingsRelaySettingsThe RelaySettings object containing the configuration settings for the relay device.
Fields
Relay
The Relay object representing the relay device. This object contains information about the relay, such as its name, type, and other relevant details.
public readonly Relay Relay
Field Value
RelaySettings
The RelaySettings object containing the configuration settings for the relay device. This includes parameters such as the refresh time for checking the status of the relays, and any other settings that may be relevant for the operation of the relay device.
public readonly RelaySettings RelaySettings
Field Value
Methods
CheckDevice()
Checks the status of the relay device. This method is abstract and must be implemented by derived classes to provide specific functionality for checking the status of the relay device.
public abstract bool CheckDevice()
Returns
CheckStatus()
Checks the status of the relays. This method is abstract and must be implemented by derived classes to provide specific functionality for checking the status of the relays.
public abstract void CheckStatus()
GetStatusRelay()
Gets the status of the relay device. This method is abstract and must be implemented by derived classes to provide specific functionality for retrieving the status of the relay device.
public abstract bool GetStatusRelay()
Returns
GetStatusRelay(int)
Gets the status of a specific relay outlet. This method retrieves the status of the relay outlet with the specified outlet ID from the _relaysStatus dictionary.
public virtual RelayEnum.Status GetStatusRelay(int outletId)
Parameters
outletIdintThe ID of the relay outlet.
Returns
GetStatusRelayAsync()
Gets the status of the relays. This method is abstract and must be implemented by derived classes to provide specific functionality for retrieving the status of the relays.
public abstract Task<bool> GetStatusRelayAsync()
Returns
PowerOffAll()
Powers off all relay outlets. This method is abstract and must be implemented by derived classes to provide specific functionality for powering off all relay outlets.
public abstract void PowerOffAll()
PowerOffRelay(int)
Powers off a specific relay outlet. This method is abstract and must be implemented by derived classes to provide specific functionality for powering off a relay outlet with the specified outlet ID.
public abstract void PowerOffRelay(int outletId)
Parameters
outletIdintThe ID of the relay outlet to power off.
PowerOnAll()
Powers on all relay outlets. This method is abstract and must be implemented by derived classes to provide specific functionality for powering on all relay outlets.
public abstract void PowerOnAll()
PowerOnOffRelay(int, int)
Powers on or off a specific relay outlet for a specified duration. This method first powers off the relay outlet with the specified outlet ID, then waits for the specified number of milliseconds, and finally powers on the relay outlet again. The method runs asynchronously to avoid blocking the main thread while waiting for the specified duration.
public virtual void PowerOnOffRelay(int outletId, int milliseconds)
Parameters
outletIdintThe ID of the relay outlet.
millisecondsintThe duration in milliseconds for which the relay outlet should be powered off.
PowerOnRelay(int)
Powers on a specific relay outlet. This method is abstract and must be implemented by derived classes to provide specific functionality for powering on a relay outlet with the specified outlet ID.
public abstract void PowerOnRelay(int outletId)
Parameters
outletIdintThe ID of the relay outlet to power on.
Reboot()
Reboots all relay outlets. This method is abstract and must be implemented by derived classes to provide specific functionality for rebooting all relay outlets.
public abstract void Reboot()
RebootOutlet(int)
Reboots a specific relay outlet. This method is abstract and must be implemented by derived classes to provide specific functionality for rebooting a relay outlet with the specified outlet ID.
public abstract void RebootOutlet(int outletId)
Parameters
outletIdint
Refresh()
Refreshes the status of the relay device. This method is virtual and can be overridden by derived classes to provide specific functionality for refreshing the status of the relay device.
public virtual void Refresh()
SetStatusRelay(int, Status)
Sets the status of a specific relay outlet. This method updates the status of the relay outlet with the specified outlet ID in the _relaysStatus dictionary.
public virtual void SetStatusRelay(int outletId, RelayEnum.Status status)
Parameters
outletIdintThe ID of the relay outlet.
statusRelayEnum.StatusThe new status of the relay outlet.
Events
RelayStatusChanged
Event that is triggered when the status of a relay changes. The event handler receives the instance of the RelayDevice and the outlet ID of the relay that changed its status.
public event EventHandler<int>? RelayStatusChanged