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.

Group Address export for ETS
#4
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')
Reply


Messages In This Thread
Group Address export for ETS - by Ian@GWTi - 17.10.2023, 13:14
RE: Group Address export for ETS - by admin - 17.10.2023, 13:38
RE: Group Address export for ETS - by admin - 18.10.2023, 12:00

Forum Jump: