!# variables.fn 1.6 !# !# Dieses Script gibt die Systemvariablen als JSON String aus !# !# 3'2013-6'2014 hobbyquaker https://github.com/hobbyquaker !# object oSysVar; string sSysVarId; var sValue; integer iValueType; integer iValueSubType; string sValueList; Write('{'); !# due to the fact that service messages can be automatically acknowledged, we have to loop over all and check var servs = dom.GetObject(ID_SERVICES); string id; integer serviceMessages = 0; foreach(id, servs.EnumIDs()) { var service = dom.GetObject(id); if(service) { if(service.IsTypeOf(OT_ALARMDP) && (service.Used() == true) && (service.Enabled() == true) && (service.AlState() == asOncoming)) { serviceMessages = serviceMessages + 1; } } } WriteLine('"40":{"Name":"Alarmmeldungen","TypeName":"VARDP","DPInfo":"Anzahl%20Alarmmeldungen","Value":' # dom.GetObject(40).Value() # ',"ValueMin":0,"ValueMax":65000,"ValueUnit":"","ValueType":16,"ValueSubType":0,"ValueList":""},'); Write('"41":{"Name":"Servicemeldungen","TypeName":"VARDP","DPInfo":"Anzahl%20Servicemeldungen","Value":' # serviceMessages # ',"ValueMin":0,"ValueMax":65000,"ValueUnit":"","ValueType":16,"ValueSubType":0,"ValueList":""}'); foreach(sSysVarId, dom.GetObject(ID_SYSTEM_VARIABLES).EnumUsedIDs()) { WriteLine(','); oSysVar = dom.GetObject(sSysVarId); sValue = oSysVar.Value(); iValueType = oSysVar.ValueType(); iValueSubType = oSysVar.ValueSubType(); sValueList = ''; Write('"' # sSysVarId # '":{'); Write('"Name":"'); WriteURL(oSysVar.Name()); Write('"'); Write(',"TypeName":"' # oSysVar.TypeName() # '"'); Write(',"DPInfo":"'); WriteURL(oSysVar.DPInfo()); Write('"'); Write(',"Value":'); if (iValueType == 20) { Write('"'); WriteURL(sValue); Write('"'); } elseif ((iValueType == 16) && (iValueSubType == 29)) { sValueList = oSysVar.ValueList(); if (sValue.VarType() == 2) { Write(sValue); } else { string sItem; integer iIndex = 0; string sIndex = "null"; foreach(sItem, sValueList.Split(";")) { if ((sIndex == "null") && (sItem == sValue)) { sIndex = iIndex.ToString(); } iIndex = iIndex + 1; } Write(sIndex); } } elseif (iValueType == 2) { if (sValue) { Write("true"); } else { Write("false"); } } elseif (sValue == "") { Write("0"); } else { Write(sValue); } string sValueMin = oSysVar.ValueMin(); if (sValueMin == '') { sValueMin = 'null'; } string sValueMax = oSysVar.ValueMax(); if (sValueMax == '') { sValueMax = 'null'; } Write(',"Timestamp":"' # oSysVar.Timestamp() # '"'); Write(',"ValueMin":' # sValueMin); Write(',"ValueMax":' # sValueMax); Write(',"ValueUnit":"'); WriteURL(oSysVar.ValueUnit()); Write('"') Write(',"ValueType":' # iValueType); Write(',"ValueSubType":' # iValueSubType); if (iValueType == 2) { Write(',"ValueList":"'); WriteURL(oSysVar.ValueName0() # ';' # oSysVar.ValueName1()); } else { Write(',"ValueList":"'); WriteURL(sValueList); } Write('"}'); } Write('}');