Skip to main content
Skip table of contents

IO Mapping Application

Introduction

The IO Mapping Application is a built-in application that runs on the Barionet M44 and remains constantly available.

Its purpose is to provide a straightforward method for performing read and write operations across the IO Addresses of the Barionet through user-friendly Python and Lua modules.

API

It is possible to access the API using:

  1. Command line with the io-mapping command

  2. Python / Lua methods details below

Command Line utility: io-mapping

Read Function

Returns the value of the queried IO addresse(s).
It is possible to read one address or multiple addresses separating them with comma.

Command:

CODE
io-mapping read <addresses>

Example: read the current value of addresses 1, 201, 601

CODE
-> io-mapping read 1,201,601
<- Address 1 with value 0        # Relay 1 value is off
<- Address 201 with value 1      # Digital Input 1 is closed
<- Address 601 with value 23500  # Temperature sensor value is 23.5°C

Write Function

Writes the value of the specified IO addresse(s).
It is possible to write the same value into multiple addresses at the same time separating them with comma. The command doesn’t return anything.

Command:

CODE
io-mapping write <addresses> <value>

Example: write 1 in addresses 1,2,3,4

CODE
-> io-mapping write 1,2,3,4 1 
# Enables Relays 1-2-3-4 

Write operations are only allowed on addresses that allow “read/write” operations. See the IO Addresses table for more information.

Receive Notifications

It is possible to receive notifications for IO Addresses 1 to 400.

Notifications offer a way for the system to inform the application interacting with io-mapping about state changes of those IO being enabled for monitoring.

The io-mapping command allows you to receive notifications only for the requested addresses.

Command:

CODE
io-mapping notify <addresses>

Example: Enable notifications for addresses 201,202,203,204 (all 4 digital inputs)

CODE
io-mapping notify 201,202,203,204
# Now toggling those inputs will print:
Address 201 with value 1
Address 201 with value 0
Address 202 with value 1
Address 202 with value 0
Address 203 with value 1
Address 203 with value 0
Address 204 with value 1
Address 204 with value 0

Get Parameters

This command retrieves the parameters associated with each IO address. Those parameters are:

  • IO address type (relay, digital input, analog, …)

  • the index of the IO within the type

  • the maximum value allowed for the addresses queried (this is the bit-size of the address)

Command:

CODE
io-mapping params <addresses>

Example:

CODE
-> io-mapping params 1206,201 
<- type: fw_version, index: 1, max value: 65535
<- type: input_digital, index: 1, max value: 1

Python API

All the functions from the API described above are also available in Python.

Below is a Python script containing examples for all the operations that can be performed on the IO Addresses.

PY
import signal
from iomapping import IoMapping, RegisterType

EXIT_APP = False

def signal_handler(signum, frame):
    global EXIT_APP               
    EXIT_APP = True

signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)

# Create an instance of IoMapping
service = IoMapping()

################### READ OPERATIONS ###################
# read value of address 1
value=service.read_value(1)
print(f"Value for address 1: {value}")

# read value of multiple addresses simultaneously
values=service.read_values([1,2,3,4])
print(f"address 1: {values[0]}")
print(f"address 2: {values[1]}")
print(f"address 3: {values[2]}")
print(f"address 4: {values[3]}")

################### WRITE OPERATIONS ###################
# write value 1 on address 2
service.write_value(2, 1)

################### ENABLE NOTIFICATIONS ###################
# create function to receive callback
def callback(address, value):
    print(f"address: {address}, value: {value}")

# enable notifications for one address
service.enable_notifications(201, callback)

# enable notifications for a range of addresses
service.enable_notifications_range(list(range(1,5)), callback)

################### GET PARAMETERS ###################
# get parameters of address 1
params = service.get_params(1)
print(f"type: {params[0]}, index: {params[1]}, max value: {params[2]}")

# get all addresses of a certain type
addresses=service.get_addresses(RegisterType.RELAY)

################### RUN THE APP ###################
# check if service is alive
alive=service.is_alive()

while not EXIT_APP:
    service.run()

################### DISABLE NOTIFICATIONS ###################
# disable notifications for one address
service.disable_notifications(201)

# disable notifications for a range of addresses
service.disable_notifications_range(list(range(1,5)))

print("Finished!")

Lua API

All the functions from the API described above are also available in Lua.

Below is a Lua script containing examples for all the operations that can be performed on the IO Addresses.

LUA
require("iomapping")

-- Create an instance of IoMapping
service = IoMapping.new()

---------------- READ OPERATIONS ----------------
-- read value of address 1
value=service:read_value(1)
print("Value for address 1:", value)

-- read value of multiple addresses simultaneously
values=service:read_values({1,2,3,4})
print("address 1:", values[1])
print("address 2:", values[2])
print("address 3:", values[3])
print("address 4:", values[4])

---------------- WRITE OPERATIONS ----------------
-- write value 1 on address 2
service:write_value(2, 1)

---------------- ENABLE NOTIFICATIONS ----------------
-- create function to receive callback
function callback(address, value)
    print("address: ", address, "value: ", value)
end

-- enable notifications for one address
service:enable_notifications(201, callback)

-- enable notifications for a range of addresses
service:enable_notifications_range({1,2,3,4,5}, callback)

---------------- GET PARAMETERS ----------------
-- get parameters of address 1
params = service:get_params(1)
print("type: ", params[1], "index: ", params[2], "max value: ", params[3])

-- get all addresses of a certain type
type = RegisterType.new()
addresses=service:get_addresses(type.RELAY)

---------------- RUN THE APP ----------------
-- check if service is alive
alive=service:is_alive()

-- main loop to process notifications
service:run()

---------------- DISABLE NOTIFICATIONS ----------------
-- disable notifications for address 201
service:disable_notifications(201)

-- disable notifications for a range of addresses
service:disable_notifications_range({1,2,3,4,5})
print("Finished!")
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.