Logic Machine Forum
Object and Modbus Mapping Delete via Script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Object and Modbus Mapping Delete via Script (/showthread.php?tid=3191)



Object and Modbus Mapping Delete via Script - BrentW - 23.02.2021

Hi all,

I need some help with database manipulation. I'm familiar with the correct methodology for adding objects via script.
What I am interested to know is the best practice for deleting objects via script.
Specifically, I need to delete an object and also remove the affiliated link in the modbus mapping.

EDIT: Also how to delete modbus devices via script.
I note the method does not work;

require('json')
function json.data()
return { id = 1 }
end
dofile('/lib/genohm-scada/web/modbus_devices/delete.lua')

Thanks in Advance,
BW


RE: Object and Modbus Mapping Delete via Script - admin - 24.02.2021

Try this:
Code:
addr = '1/1/1'

-- delete object
grp.delete(addr)

-- clear modbus mapping
id = buslib.encodega(addr)
db:query('UPDATE modbus_mapping SET bus_address="" WHERE bus_address=?', id)

-- restart modbus
os.execute('sh /lib/genohm-scada/plugins/modbus/stop.sh; sleep 1; sh /lib/genohm-scada/plugins/modbus/start.sh')



RE: Object and Modbus Mapping Delete via Script - BrentW - 24.02.2021

Thanks! Works as expected.
Also, The following code worked to delete the entire modbus device. Care should be taken to remove the associated mapping in modbus_mapping as this will cause conflicts when adding new devices.
db:query('DELETE FROM modbus_devices', id)