我正在尝试连接所有值并将它们附加到同一个变量,然后写入字符串的内容。我不断收到错误消息:“尝试连接全局 'arglist'(一个 nil 值)”
eo_device = {}
eo_device[1] = {node = "ME", t_object = "AV1", h_object = "AV2" }
eo_device[2] = {node = "ME", t_object = "AV3", h_object = "AV4" }
eo_device[3] = {node = "ME", t_object = "AV5", h_object = "AV6" }
eo_device[4] = {node = "ME", t_object = "AV7", h_object = "AV8" }
eo_device[5] = {node = "ME", t_object = "AV9", h_object = "AV10" }
eo_device[6] = {node = "ME", t_object = "AV11", h_object = "AV12" }
eo_device[7] = {node = "ME", t_object = "AV13", h_object = "AV14" }
eo_device[8] = {node = "ME", t_object = "AV15", h_object = "AV16" }
eo_device[9] = {node = "ME", t_object = "AV17", h_object = "AV18" }
eo_device[10] = {node = "ME", t_object = "AV19", h_object = "AV20" }
eo_device[11] = {node = "ME", t_object = "AV21", h_object = "AV22" }
eo_device[12] = {node = "ME", t_object = "AV23", h_object = "AV24" }
eo_device[13] = {node = "ME", t_object = "AV25", h_object = "AV26" }
eo_device[14] = {node = "ME", t_object = "AV27", h_object = "AV28" }
eo_device[15] = {node = "ME", t_object = "AV29", h_object = "AV30" }
-- Generate string with all arguments to be written to CSV
for deviceindex = 1,#eo_device do
device_name = scl.nodes[eo_device[deviceindex].node][eo_device[deviceindex].t_object .. "_Object_Name"].value -- point to Object Names
description = scl.nodes[eo_device[deviceindex].node][eo_device[deviceindex].t_object .. "_Description"].value -- point to Description of all objects
temperature = scl.nodes[eo_device[deviceindex].node][eo_device[deviceindex].t_object .. "_Present_Value"].value -- value of temperature object
humidity = scl.nodes[eo_device[deviceindex].node][eo_device[deviceindex].h_object .. "_Present_Value"].value -- value of humidity object
buflist = device_name .. "," .. description .. "," .. temperature .. "," .. humidity
arglist = arglist .. "," .. buflist
end -- end for
--then once outside of the loop:
arglist = arglist .. "," .. buflist
buffer = os.date() .. arglist .. "\r\n"
file, info = io.open("trend.csv", "a+") -- write to CSV
if file then
file:write(buffer)
file:close()
end -- end if