This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Create Modbus client via script
#7
(28.09.2017, 20:22)Erwin van der Zwart Wrote: Hi,

Yes i could, but i don't see the point (:

You can change grp.address = '1/1/' .. counter to grp.address = '1/2/' .. counter and run it again, the script checks already if a object is already mapped and skips it then, so it will resume on the unmapped objects.

If you have 900 objects just run it 4 times and change the grp.address range between each run.

also add script.disable(_SCRIPTNAME) at the end of the above script to avoid it from running multiple times when using it from a resident script

BR,

Erwin
I've tried to modify and seems it works

Code:
-- Select all entrys from DB inside table 'modbus_mapping'
-- "id", "internal_id", "device", "name", "active", "bus_write", "bus_address", "bus_datatype", "internal", "type", "value_delta","value_base","value_multiplier","value_bitmask","value_nan","value_conv","value_custom","units","address","address_scale","read_count","read_offset","read_swap","datatype","writable","write_only","write_multiple"
query = 'SELECT * FROM modbus_mapping'
counter = 0
for _, mapping in ipairs(db:getall(query)) do
 if mapping.bus_address == "" or  mapping.bus_address == nil then
   mid_group = math.floor(counter/256)
   grp_address = '32/'..mid_group..'/' .. (counter - 256*mid_group)
   log(grp_address)
   if counter < 2047 then
     dec_grp_address = knxlib.encodega(grp_address)
     address = grp.create({
     datatype = mapping.datatype,
     address = grp_address,
     name = mapping.name,
     comment = 'Auto mapped by script',
     units = mapping.units,
     tags = {},
     })
     counter = counter + 1
     db:update('modbus_mapping', { bus_address = dec_grp_address, bus_write = 1, value_delta = 0.1, value_custom = 'Auto mapped by script' }, { id = mapping.id })
   end
 end
end
log('done')
script.disable(_SCRIPTNAME)
but few times this script did not fill full modbus table. it stops on 32/0/225, but all GA was created (the last was 32/3/***)
this script worked about 1 minute

(29.09.2017, 07:37)toujour Wrote: Hi to Everybody,

I like your scripts !!  Wink

I have a problem with only one object in modbus mapping profile, please see the image in the attachment.

I want change the COIL 192 to COIL 191 ( I forgot it in the profile     Angry  )

Can I use a script to change only this point ? I have more then 500 point in this modbus device.

Thanks in Advance !

Alberto
I think there is another simple way
You can create additional profile for your modbus device only with coil 191.
Reply


Messages In This Thread
Create Modbus client via script - by FatMax - 17.02.2017, 11:31
RE: Create Modbus client via script - by AEK - 28.09.2017, 16:04
RE: Create Modbus client via script - by AEK - 29.09.2017, 07:56
RE: Create Modbus client via script - by AEK - 02.08.2018, 10:55

Forum Jump: