# Class KmTronicRelay

Namespace
  adas_core.module.Relays.Devices

Assembly
  adas-core.module.Relays.dll

Class for controlling a KMTronic relay device.

    public class KmTronicRelay : RelayDevice

Inheritance
  object
  RelayDevice
  KmTronicRelay

Inherited Members
  RelayDevice.Relay
  RelayDevice.RelaySettings
  RelayDevice.RelayStatusChanged
  RelayDevice.SetStatusRelay(int, RelayEnum.Status)
  RelayDevice.PowerOnOffRelay(int, int)
  RelayDevice.Refresh()
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### KmTronicRelay(Relay, RelaySettings)

Class for controlling a KMTronic relay device.

    public KmTronicRelay(Relay relay, RelaySettings relaySettings)

#### Parameters

`relay` Relay

  The Relay object representing the relay device.

`relaySettings` RelaySettings

  The 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

bool

## 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

`outletId` int

  The 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

`outletId` int

  The ID of the outlet to retrieve the status for.

#### Returns

RelayEnum.Status

  The status of the specified outlet.

### 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

Task<bool>

  A task representing the asynchronous operation.

#### Exceptions

NotImplementedException

### 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

`outletId` int

  The 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

`outletId` int

  The 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

`outletId` int

  The 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

`outletId` int

  The 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

`datagrama` string

  The command to send to the KMTronic relay device.

#### Returns

string

  The response from the KMTronic relay device.