Logic Machine Forum
Group Address export for ETS - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2)
+--- Thread: Group Address export for ETS (/showthread.php?tid=5035)



Group Address export for ETS - Ian@GWTi - 17.10.2023

Hi,

I would like to export all group address from the logicmachine and import them into ETS.  Can this be done?

Reason being you can add lots of modbus data points and automatically link group addresses to them quickly in the logicmachine.


RE: Group Address export for ETS - admin - 17.10.2023

This old script by Erwin might work: https://forum.logicmachine.net/showthread.php?tid=1126&pid=6713#pid6713


RE: Group Address export for ETS - Ian@GWTi - 17.10.2023

(17.10.2023, 13:38)admin Wrote: This old script by Erwin might work: https://forum.logicmachine.net/showthread.php?tid=1126&pid=6713#pid6713

Thanks,

I actually used the script by Daniel,  Used ftp to download the file which worked well.  Only issue it doesn't have data type assigned,  Could this be added?


RE: Group Address export for ETS - admin - 18.10.2023

This script generates CSV with datatypes that can be imported into ETS 6.1.0. csv variable contains the CSV file data as a string.
Code:
function csvescape(val)
  val = tostring(val)
  val = val:gsub('"', '""'):gsub('^[-=+@\t\r]', "'%0")
  return '"' .. val .. '"'
end

function getdpst(dpt)
  dpt = tonumber(dpt)

  if not dpt then
    return ''
  elseif dpt < 1000 then
    return 'DPT-' .. dpt
  else
    local mdpt = dpt % 1000
    dpt = math.floor(dpt / 1000)

    return 'DPST-' .. dpt .. '-' .. mdpt
  end
end

objs = grp.all()

buf = { '"Group name";"Address";"Central";"Unfiltered";"Description";"DatapointType"' }

for _, obj in ipairs(objs) do
  if obj.id < 0x10000 then
    row = {
      csvescape(obj.name or ''),
      csvescape(obj.address),
      '""',
      '""',
      csvescape(obj.comment or ''),
      csvescape(getdpst(obj.datatype)),
    }

    buf[ #buf + 1 ] = table.concat(row, ';')
  end
end

csv = table.concat(buf, '\n')