Skip to main content

ENP-RL6

rl6 library implements relay management for the ENP-RL6 module.

ENP-RL6 has 6 controllable relays with IDs from 1 to 6.

rl6.get

-- @param id number ID of relay
-- @return boolean|nil, number Relay status and error code
function rl6.get(id)
end

Returns the current state of single relay:

  • true is closed contact,
  • false is opened contact,

Returns nil when reading relay status failed, see the second return value, error code (use rl6.err_to_str to convert it to string representation).

Example

status, result = rl6.get(1)
if status == nil then
enapter.log("Reading relay 1 status failed: "..result.." "..rl6.err_to_str(result), "error", true)
elseif status then
enapter.log("Relay 1 is closed")
else
enapter.log("Relay 1 is opened")
end

rl6.open

-- @param id number ID of relay
-- @return number
function rl6.open(id)
end

Opens single relay contact.

Returns 0 on success, otherwise returns error code (use rl6.err_to_str to convert it to string representation).

rl6.close

-- @param id number ID of relay
-- @return number
function rl6.close(id)
end

Closes single relay contact.

Returns 0 on success, otherwise returns error code (use rl6.err_to_str to convert it to string representation).

rl6.impulse

-- @param id number ID of relay
-- @param duration number Impulse duration in milliseconds
-- @return number
function rl6.impulse(id, duration)
end

Performs impulse on the single relay. The state of the relay will be changed to the opposite one for the delay milliseconds, and then will be switched back.

Non-blocking call

This function call is non-blocking. Any other operation with the same relay ID during the impulse period will abort the impulse operation.

Returns 0 on success, otherwise returns error code (use rl6.err_to_str to convert it to string representation).

Example

rl6.open(2)

-- Send "close" impulse on channel 2 for 100ms.
result = rl6.impulse(2, 100)
if result ~= 0 then
enapter.log("Impulse on relay 2 failed: "..result.." "..rl6.err_to_str(result), "error", true)
end

rl6.open_all

-- @return number
function rl6.open_all()
end

Opens all 6 relay contacts.

Returns 0 on success, otherwise returns error code (use rl6.err_to_str to convert it to string representation).

rl6.close_all

-- @return number
function rl6.close_all()
end

Closes all 6 relay contacts.

Returns 0 on success, otherwise returns error code (use rl6.err_to_str to convert it to string representation).

rl6.set_all

-- @param close1 boolean Close relay 1, otherwise open
-- @param close2 boolean Close relay 2, otherwise open
-- @param close3 boolean Close relay 3, otherwise open
-- @param close4 boolean Close relay 4, otherwise open
-- @param close5 boolean Close relay 5, otherwise open
-- @param close6 boolean Close relay 6, otherwise open
-- @return number
function rl6.set_all(close1, close2, close3, close4, close5, close6)
end

Simultaneously change states of all relays. true will close the corresponding relay, false will open it.

Returns 0 on success, otherwise returns error code (use rl6.err_to_str to convert it to string representation).

Example

-- Close relays 1 and 4, open the rest.
result = rl6.set_all(true, false, false, true, false, false)
if result ~= 0 then
enapter.log("Changing relay statuses failed: "..result.." "..rl6.err_to_str(result), "error", true)
end

rl6.err_to_str

-- @param error number
-- @return string
function rl6.err_to_str(error)
end

Returns string representation of rl6 function return code.

Error on relay operation usually means hardware problem, contact Enapter support at support@enapter.com to address the issue.

Hardware diversity is welcome. Integrate any device into a unified energy network.
© 2024 Enapter
Developer toolkit
DocumentationReference