Class KmTronicRelay
Class for controlling a KMTronic relay device.
public class KmTronicRelay : RelayDevice
- Inheritance
-
KmTronicRelay
- Inherited Members
- Extension Methods
Constructors
KmTronicRelay(Relay, RelaySettings)
Class for controlling a KMTronic relay device.
public KmTronicRelay(Relay relay, RelaySettings relaySettings)
Parameters
relayRelayThe Relay object representing the relay device.
relaySettingsRelaySettingsThe RelaySettings object containing the configuration settings for the relay device.
Properties
DeviceStatus
Indicates the current status of the KMTronic relay device. It is updated by the CheckStatus method and can be used to determine if the device is online or offline.
public bool DeviceStatus { get; set; }
Property Value
Methods
CheckDevice()
Checks the connectivity and status of the KMTronic relay device by sending a command to retrieve the status of the first outlet. It updates the DeviceStatus property based on the response received from the device. If the response indicates that the status is unknown, it returns false, indicating that the device is not reachable or not responding correctly. Otherwise, it returns true, indicating that the device is online and responsive.
public override bool CheckDevice()
Returns
- bool
True if the device is online and responsive, false otherwise.
CheckStatus()
Checks the status of the KMTronic relay device by calling the GetStatusRelay method and updating the DeviceStatus property accordingly.
public override void CheckStatus()
CloseRelay(int)
Closes a specific outlet on the KMTronic relay device by sending a command to either open or close the relay, depending on the configured mode. This method is used to power on the outlet by allowing the current to flow through it.
public void CloseRelay(int outletId)
Parameters
outletIdintThe ID of the outlet to close.
Connect()
Asynchronously retrieves the status of a specific outlet on the KMTronic relay device. This method is not implemented in this class, and it throws a NotImplementedException when called.
protected virtual void Connect()
GetStatusRelay()
Retrieves the status of the KMTronic relay device by sending a command to get the status of all outlets. It checks if the response is not null or empty, which indicates that the device is online and responsive. If the response is null or empty, it indicates that the device is not reachable or not responding correctly, and it returns false. Otherwise, it returns true, indicating that the device is online and responsive.
public override bool GetStatusRelay()
Returns
- bool
True if the device is online and responsive, false otherwise.
GetStatusRelay(int)
Retrieves the status of a specific outlet on the KMTronic relay device by sending a command to get the status of all outlets. It checks if the response is not null or empty, and if it contains the expected format for the outlet status.
public override RelayEnum.Status GetStatusRelay(int outletId)
Parameters
outletIdintThe ID of the outlet to retrieve the status for.
Returns
GetStatusRelayAsync()
Asynchronously retrieves the status of the KMTronic relay device. This method is not implemented in this class, and it throws a NotImplementedException when called.
public override Task<bool> GetStatusRelayAsync()
Returns
Exceptions
OpenRelay(int)
Powers on a specific outlet on the KMTronic relay device by sending a command to either open or close the relay, depending on the configured mode.
public void OpenRelay(int outletId)
Parameters
outletIdintThe ID of the outlet to power on.
PowerOffAll()
Powers off all outlets on the KMTronic relay device by sending a command to either open or close all relays, depending on the configured mode.
public override void PowerOffAll()
PowerOffRelay(int)
Powers off a specific outlet on the KMTronic relay device by sending a command to either open or close the relay, depending on the configured mode.
public override void PowerOffRelay(int outletId)
Parameters
outletIdintThe ID of the outlet to power off.
PowerOnAll()
Powers on all outlets on the KMTronic relay device by sending a command to either open or close all relays, depending on the configured mode.
public override void PowerOnAll()
PowerOnRelay(int)
Powers on a specific outlet on the KMTronic relay device by sending a command to either open or close the relay, depending on the configured mode.
public override void PowerOnRelay(int outletId)
Parameters
outletIdintThe ID of the outlet to power on.
Reboot()
Reboots all outlets on the KMTronic relay device by first powering them off, waiting for a specified delay, and then powering them back on. This method is used to reset all connected devices by briefly cutting off their power supply.
public override void Reboot()
RebootOutlet(int)
Reboots a specific outlet on the KMTronic relay device by first powering it off, waiting for a specified delay, and then powering it back on. This method is used to reset the connected device by briefly cutting off its power supply.
public override void RebootOutlet(int outletId)
Parameters
outletIdintThe ID of the outlet to reboot.
Send(string)
Sends a command to the KMTronic relay device and waits for a response. It first checks if the UDP client is initialized and connected, and if not, it attempts to connect to the device. If the connection is successful, it sends the specified command to the device and waits for a response.
protected virtual string Send(string datagrama)
Parameters
datagramastringThe command to send to the KMTronic relay device.
Returns
- string
The response from the KMTronic relay device.