Skip to main content
Version: Next

DIO

DIO Functions​

This category contains functions that enable pulse devices to use DIO (digital input/output).

API NameBrief Description
api.AnalogReadPin(pin)Reads analog value on defined pin.
api.DIOwaitForEvent(pin, event, sync, timeout)Waits for specified event on defined pin.
api.DIOreadPin(pin)Reads DIO pin state.
api.DIOwritePin(pin, state)Writes DIO pin state.

api.AnalogReadPin(pin)​


api.AnalogReadPin(1)

Reads analog value on defined pin.

Warning: Disabled by default, requires firmware and hardware changes.

Arguments​

  • pin (integer): Defined analog pin.

Return​

  • voltage (integer): Measured voltage value.

Example​

-- Read analog value on pin 1
mV = api.AnalogReadPin(1)
print("Raw value: " .. tostring(mV) .. " mV")

api.DIOwaitForEvent(pin, event, sync, timeout)​


api.DIOwaitForEvent(1, 1)

Waits for specified event on defined pin.

Info: If event occurs, device wakes up and calls onWake() function.

Arguments​

  • pin (integer): Pin number, 1 to 4.
  • event (integer): Event to wait for:
    • 0 - unregister.
    • 1 - rising.
    • 2 - falling.
    • 3 - both.

Optional

  • sync (integer, optional):

    • 1 synchronous event is requested.
    • 0 asynchronous (default).
  • timeout (integer, optional): Time in milliseconds to wait, only used if sync is 1.

Return​

  • status (integer):

    • 1-4 - success, the value is the pin number that was (registered or) triggered.

      • in async mode: returned immediately after registration.

      • in sync mode: returned when the event occurs.

    • 0 - success; the event was unregistered/disabled for the pin (event = 0).

    • -1 - invalid pin (must be 1-4).

    • -2 - invalid event (must be 0-3).

    • -3 - timeout (only possible when sync = 1 and timeout > 0).

Example​

-- Wait for rising edge on pin 1
api.DIOwaitForEvent(1, 1)

--------------------------------

function onStartup()
print("Starting up Lua VM...")
print("Float Gauge script ver. " .. version)

api.nbAT("APN=" .. APN)
api.nbAT("PLMNID="..PLMNID)

api.exec("setSwWdogNoComReloadValue", noComWdg)

print(
"Set input " ..
tostring(directInput) .. " and " .. tostring(invertedInput) .. " to rising/falling edge event source"
)
api.DIOwaitForEvent(directInput, 3)
api.DIOwaitForEvent(invertedInput, 3)

api.DIOreadPin(pin)​


api.DIOreadPin(1)

Reads DIO pin state.

Arguments​

  • pin (integer): Pin number, 1 to 4.

Return​

  • state (integer):
    • 1 pin is set.
    • 0 pin is not set.

Example​

-- Read state of pin 1
state = api.DIOreadPin(1)

api.DIOwritePin(pin, state)​


api.DIOwritePin(1, 1)

Writes DIO pin state.

Arguments​

  • pin (integer): Pin number, 1 to 4.

Optional

  • state (integer, optional): Pin state:
    • -2 - analog.
    • -1 - high impedance.
    • 0 - low.
    • 1 - high.
    • -2 - default.

Return​

  • status (integer):
    • 0 for success.
    • -1 for failure.

Example​

-- Set logical 1 to pins 2 and 3, and logical 0 to pins 1 and 4
api.DIOwritePin(1, 0)
api.DIOwritePin(2, 1)
api.DIOwritePin(3, 1)
api.DIOwritePin(4, 0)

-- Read state of pins 1 to 4
print("pin 1 set to:", api.DIOreadPin(1))
print("pin 2 set to:", api.DIOreadPin(2))
print("pin 3 set to:", api.DIOreadPin(3))
print("pin 4 set to:", api.DIOreadPin(4))