User manual

Scripting
6
Python, Lua or NodeJS scripts are saved in directory “/var/ipcore/”. It is recommended to
create a separate subdirectory for each script.
cd /var/ipcore
mkdir myscript
cd myscript
vim myscript.py
chmod +x myscript.py
The following scripts are examples of this:
4.1. LUA
The following script searches for a gpio.AI module in all buses available and continuously
records measurements issued by the standard output.
#! /usr/bin/lem /etc/mbtcp.conf
--[[
1. Look for a gpio.AI module on all busses
2. Configure gpio.AI
3. Get data
]]
-- return card type
function get_card_type(id)
_, _, ct, _, _ = string.match(id, "^(.*):(.*):(.*):(.*):(.*)$")
ct = "0x" .. ct
ct = tonumber(ct)
if ct == 0x0200 then
return "AO"
elseif ct == 0x0100 then
return "AI"
elseif (ct >= 0x0010) and (ct <= 0x009F) then
return "DIO"
elseif (ct >= 0x00A0) and (ct <= 0x00FF) then
return "Relais"
end
return nil
end
-- return bus and Modbus ID of the first card matching type
function find_card_type(type)
bus_list = tml.get_busses()
for _, bus in ipairs(bus_list) do
for i = 1, 16, 1 do
ret, id = tml.report_id(bus, i)
if ret == 0 then
if get_card_type(id) == type then
return bus, i
end
end
end
end
return nil
end
local bus, mb_id = find_card_type("AI")
tml.write_regs(bus, mb_id, 0x0100, {65535, 2})
print("bus: " .. bus .. " id: " .. mb_id)
print("\nIN0 ... IN7 in mV")
while true do
-- read IN0 to IN7
ret, v = tml.read_input_regs(bus, mb_id, 0, 8)