ENP-AI4
ai4
library implements analog inputs interface for the ENP-AI4 module.
ENP-AI4 has 4 analog input channels with IDs from 1
to 4
. Channels are pre-configured on the Enapter factory for either voltage, or current, or temperature (PT1000) readings.
Two modifications exist:
- ENP-AI4-50V with all 4 channels for voltage reading (-50…+50 V).
- ENP-AI4-20MA with all 4 channels for current reading (4…20 mA).
ai4.read_volts
-- @param id number ID of input
-- @return number|nil, number Voltage in V, and error code
function ai4.read_volts(id)
end
Returns voltage on the given input as the first return value. Could be in -50…+50 V range. Error code is returned as a second return value (use ai4.err_to_str
to convert it to string representation).
Example
data, result = ai4.read_volts(2)
if not data then
enapter.log("Unable to read channel 2: "..result.." "..ai4.err_to_str(result), "error", true)
end
ai4.read_milliamps
-- @param id number ID of input
-- @return number|nil, number Current in A, and error code
function ai4.read_milliamps(id)
end
Returns current on the given input as the first return value. Could be in 0.004-0.02 A (4-20 mA) range. Error code is returned as a second return value (use ai4.err_to_str
to convert it to string representation).
Example
data, result = ai4.read_milliamps(2)
if not data then
enapter.log("Unable to read channel 2: "..result.." "..ai4.err_to_str(result), "error", true)
end
ai4.err_to_str
-- @param error number
-- @return string
function ai4.err_to_str(error)
end
Returns string representation of ai4
function return code.