Logic Machine Forum
Creating a KNx point for Modbus Device Communication Error Situation - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Creating a KNx point for Modbus Device Communication Error Situation (/showthread.php?tid=408)



Creating a KNx point for Modbus Device Communication Error Situation - savaskorkmaz - 03.10.2016

Hello ,
When we have a communication problem in Logic Machine, In modbus section of LM, modbus device turns red color and we can understand there is a communication problem. I would like to transfer this information as a Bacnet point but I need first , I need to transfer this communication failure in to KNX data point.

How could i do that ?

Regards,


RE: Creating a KNx point for Modbus Device Communication Error Situation - Erwin van der Zwart - 03.10.2016

Hi Savaskorkmaz,

I don't know if there is a function for this in the system, but i solved it once with a little resident script.

Put your actions on the position where the logging is now (replace them with your action).

Code:
-- Check all modbus meters for connection
query = 'SELECT * FROM modbus_devices'
meter_state = db:getall(query)
previous_state = storage.get('meterstate')
if previous_state == nil then
 for _, device in ipairs(meter_state) do
   if device.active == 0 then
     log(device.name .. " = down")
   else
     log(device.name .. " = active")
   end
 end
 storage.set('meterstate', meter_state)
else
 for _, device in ipairs(meter_state) do
   if device.active ~= previous_state[_].active then
     log(device.name .. ' is changed to ' .. device.active)
   end    
 end
 storage.set('meterstate', meter_state)
end

BR,

Erwin van der Zwart


RE: Creating a KNx point for Modbus Device Communication Error Situation - admin - 04.10.2016

For now Erwin's script is the only solution, but we have this feature in our to-do list Smile


RE: Creating a KNx point for Modbus Device Communication Error Situation - Erwin van der Zwart - 04.10.2016

Hi,

Here is a version with writing to KNX objects:

Code:
-- Check all modbus meters for connection

-- Function to send changes to KNX
function writetoknx(name,active)
    if name == 'Meter 1' then  -- name must match modbus device name
   grp.write('1/1/1', toboolean(active))
 elseif name == 'Meter 2' then
   grp.write('1/1/2', toboolean(active))
 elseif name == 'Meter 3' then
   grp.write('1/1/3', toboolean(active))
 elseif name == 'Meter 4' then
   grp.write('1/1/4', toboolean(active))
 elseif name == 'Meter 5' then
   grp.write('1/1/5', toboolean(active))
 end
end

-- Get meter status
query = 'SELECT * FROM modbus_devices'
meter_state = db:getall(query)
previous_state = storage.get('meterstate')
if previous_state == nil then
 for _, device in ipairs(meter_state) do
     writetoknx(device.name,device.active)
 end
 storage.set('meterstate', meter_state)
else
 for _, device in ipairs(meter_state) do
   if device.active ~= previous_state[_].active then
        writetoknx(device.name,device.active)
   end    
 end
 storage.set('meterstate', meter_state)
end
 
BR,
Erwin