Digital Loggers

MODBUS over Ethernet

 

MODBUS is supported in all DLI power controllers and DIN relays with WiFi.  It is not currently available in PLCs.

 

 

Unit ID:1

 

The relays are mapped to coils (1..8)
 

Standard MODBUS commands can be used to manipulate them, ie:

 

READ_COILS = 0x01

WRITE_SINGLE_COIL=0x05

WRITE_MULTIPLE_COILS = 0x0F

 

Use scripting and the REST API to configure custom registers to do whatever you please.

 

 Here's a sample script snippet: (from default.modbus_demo)

 

function flip_all_modbus_discrete_inputs()
for i=1,#modbus.discrete_inputs do
modbus.discrete_inputs[i].value=not modbus.discrete_inputs[i].value
end
end
 


function allow_custom_meter_to_be_set_from_modbus()
-- You're expected to create a custom meter and specify its ID here
local custom_value=meter.values["custom_meter_id"]
if custom_value then
-- You're expected to create the registers manually and assign
-- sequential addresses to them and specify them here
local rlow,rhigh=modbus.holding_registers[1],modbus.holding_registers[2]
assert(rlow and rhigh)
custom_value.value=util.float32be.decode(util.uint16be.encode(rhigh.value)..util.uint16be.encode(rhigh.value))
for i,t,data in event.stream(event.change_listener(rhigh)) do
if data.key=="value" then
custom_value.value=util.float32be.decode(util.uint16be.encode(rhigh.value)..util.uint16be.encode(rhigh.value))
end
end
else
log.info("Please edit the script to specify a custom meter meter")
end
end
 


function expose_temperature_to_modbus()
local temperature=meter.values["sensors.0.temperature"] or meter.values["environment.temperature"]
if temperature then
-- You're expected to create the registers manually, assign
-- sequential addresses to them and specify them here (they may be
-- input or holding registers).
local rlow,rhigh=modbus.input_registers[1],modbus.input_registers[2]
assert(rlow and rhigh)
local encoded_value=util.float32be.encode(temperature.value)
rlow.value=util.uint16be.decode(encoded_value:sub(3,4))
rhigh.value=util.uint16be.decode(encoded_value:sub(1,2))
for i,t,data in event.stream(event.change_listener(temperature)) do
if data.key=="value" then
encoded_value=util.float32be.encode(temperature.value)
rlow.value=util.uint16be.decode(encoded_value:sub(3,4))
rhigh.value=util.uint16be.decode(encoded_value:sub(1,2))
end
end
else
log.info("Please edit the script to choose an existing meter")
end
end