Skip to main content

Analog InputHardware UCMVirtual UCM

The analogin library provides an interface for controlling analog inputs.

The analogin library is available for:

  • ENP-AI4-50V, using 4 hardware ports for voltage reading,
  • ENP-AI4-20MA, using 4 hardware ports for current reading,
  • ENP-AI6 M2, using 6 hardware ports for voltage, 2 ports for current, and 2 ports for temperature reading.

analogin.new

-- @param connection_uri string Connection URI
-- @return object|nil, string|nil
function analogin.new(connection_uri)
end

Creates a new analog input client The connection URI should specify the desired analog input device.

Use port schema to access hardware ports.

On failure, it returns nil and an error message string.

client Object

client:get_volts

Portability

This feature is not available for ENP-AI4-20MA. The function always returns an error.

-- @return number, string|nil
function client:get_volts()
end

Returns the voltage (in Volts) from the analog input.

On success, the function returns the number and nil. On failure, it returns nil and an error message string.

Example

local client, _ = analogin.new("port://ai-1")
local volts, err = client:get_volts()
if err ~= nil then
enapter.log("Unable to get voltage: " .. err, "error")
else
enapter.log("Voltage: " .. tostring(volts))
end

client:get_amps

Portability

This feature is not available for ENP-AI4-50V. The function always returns an error.

Configure First

Analog input must be configured for temperature reading.

-- @return number, string|nil
function client:get_amps()
end

Returns the amperage (in Amperes) from the analog input.

On success, the function returns the number and nil. On failure, it returns nil and an error message string.

Example

local client, _ = analogin.new("port://ai-1")
local amps, err = client.get_amps()
if err ~= nil then
enapter.log("Unable to get amperage: " .. err, "error")
else
enapter.log("Amperage: " .. tostring(amps))
end

client:get_temperature

Portability

This feature is not available for ENP-AI4-50V and ENP-AI4-20MA. The function always returns an error.

Configure First

Analog input must be configured for temperature reading.

-- @return number, string|nil
function client:get_temperature()
end

Returns the temperature (in degrees Celsius) from the analog input.

On success, the function returns the number and nil. On failure, it returns nil and an error message string.

Example

local client, _ = analogin.new("port://ai-1")
local temperature, err = client.get_temperature()
if err ~= nil then
enapter.log("Unable to get temperature: " .. err, "error")
else
enapter.log("Temperature: " .. tostring(temperature))
end

All Rights Reserved © 2025 Enapter AG.